mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-01 13:29:26 +00:00
36_Shelly.pm: Neue Version 2.02 mit einigen Fixes
git-svn-id: https://svn.fhem.de/fhem/trunk@19510 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
8c05b19f99
commit
b9f2412694
@ -38,7 +38,7 @@ use vars qw{%attr %defs};
|
||||
sub Log($$);
|
||||
|
||||
#-- globals on start
|
||||
my $version = "2.01";
|
||||
my $version = "2.02";
|
||||
|
||||
#-- these we may get on request
|
||||
my %gets = (
|
||||
@ -56,7 +56,8 @@ my %setssw = (
|
||||
"on-for-timer" => "X",
|
||||
"off-for-timer" => "E",
|
||||
"config" => "K",
|
||||
"password" => "W"
|
||||
"password" => "W",
|
||||
"xtrachannels" => "C"
|
||||
);
|
||||
|
||||
my %setsrol = (
|
||||
@ -156,17 +157,9 @@ sub Shelly_Define($$) {
|
||||
if( $a[2] !~ m|\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?(\:\d+)?| );
|
||||
|
||||
my $dev = $a[2];
|
||||
#-- split into parts
|
||||
my @tcp = split(':',$dev);
|
||||
#-- when the specified ip address contains a port already, use it as supplied
|
||||
if ( $tcp[1] ){
|
||||
$hash->{TCPIP} = $dev;
|
||||
}else{
|
||||
$hash->{TCPIP} = $tcp[0].":80";
|
||||
};
|
||||
|
||||
$hash->{TCPIP} = $dev;
|
||||
$hash->{DURATION} = 0;
|
||||
$hash->{MOVING} = "stopped";
|
||||
$hash->{MOVING} = "stopped";
|
||||
delete $hash->{BLOCKED};
|
||||
$hash->{INTERVAL} = 60;
|
||||
|
||||
@ -179,7 +172,7 @@ sub Shelly_Define($$) {
|
||||
my $err = Shelly_status($hash);
|
||||
if( !defined($err) ){
|
||||
readingsBulkUpdate($hash,"state","initialized");
|
||||
readingsBulkUpdate($hash,"network","connected");
|
||||
readingsBulkUpdate($hash,"network","<html>connected to <a href=\"http://".$hash->{TCPIP}."\">".$hash->{TCPIP}."</a></html>");
|
||||
}else{
|
||||
readingsBulkUpdate($hash,"state",$err);
|
||||
readingsBulkUpdate($hash,"network","not connected");
|
||||
@ -513,6 +506,20 @@ sub Shelly_Set ($@) {
|
||||
$cmd = (ReadingsVal($name,"relay".$subs,"off") eq "on") ? "off" : "on";
|
||||
}
|
||||
Shelly_onoff($hash,$channel,"?turn=".$cmd);
|
||||
}elsif( $cmd eq "xtrachannels" ){
|
||||
if( $shelly_models{$model}[0]>1){
|
||||
for( my $i=0;$i<$shelly_models{$model}[0];$i++){
|
||||
fhem("defmod ".$name."_$i readingsProxy $name:relay_$i");
|
||||
fhem("attr ".$name."_$i room ".AttrVal($name,"room","Unsorted"));
|
||||
fhem("attr ".$name."_$i group ".AttrVal($name,"group","Shelly"));
|
||||
fhem("attr ".$name."_$i setList on off");
|
||||
fhem("attr ".$name."_$i setFn {\$CMD.\" $i \"}");
|
||||
fhem("attr ".$name."_$i userReadings button {ReadingsVal(\"$name \",\"button_$i\",\"\")}");
|
||||
Log3 $name, 1,"[Shelly_Set] readingsProxy device ".$name."_$i created";
|
||||
}
|
||||
}else{
|
||||
Log3 $name, 1,"[Shelly_Set] no separate channel device created, only one channel present";
|
||||
}
|
||||
}
|
||||
|
||||
#-- we have a Shelly 2 roller type device
|
||||
@ -757,7 +764,7 @@ sub Shelly_pwd($){
|
||||
my $state = $hash->{READINGS}{state}{VAL};
|
||||
my $net = $hash->{READINGS}{network}{VAL};
|
||||
return
|
||||
if( $net ne "connected" );
|
||||
if( $net !~ /connected/ );
|
||||
|
||||
my $model = AttrVal($name,"model","");
|
||||
my $creds = Shelly_pwd($hash);
|
||||
@ -853,7 +860,7 @@ sub Shelly_pwd($){
|
||||
my ($subs,$ison,$overpower,$rpower,$rstate,$power,$energy,$rstopreason,$rcurrpos,$position,$rlastdir,$pct,$pctnormal);
|
||||
|
||||
readingsBeginUpdate($hash);
|
||||
readingsBulkUpdateIfChanged($hash,"network","connected",1);
|
||||
readingsBulkUpdateIfChanged($hash,"network","<html>connected to <a href=\"http://".$hash->{TCPIP}."\">".$hash->{TCPIP}."</a></html>",1);
|
||||
|
||||
#-- we have a Shelly 1/1pw, Shelly 4, Shelly 2/2.5 or ShellyPlug switch type device
|
||||
if( ($model =~ /shelly1.*/) || ($model eq "shellyplug") || ($model eq "shelly4") || (($model =~ /shelly2.*/) && ($mode eq "relay")) ){
|
||||
@ -1035,7 +1042,7 @@ sub Shelly_pwd($){
|
||||
my $state = $hash->{READINGS}{state}{VAL};
|
||||
my $net = $hash->{READINGS}{network}{VAL};
|
||||
return
|
||||
if( $net ne "connected" );
|
||||
if( $net !~ /connected/ );
|
||||
|
||||
my $model = AttrVal($name,"model","");
|
||||
my $creds = Shelly_pwd($hash);
|
||||
@ -1126,7 +1133,7 @@ sub Shelly_pwd($){
|
||||
my $state = $hash->{READINGS}{state}{VAL};
|
||||
my $net = $hash->{READINGS}{network}{VAL};
|
||||
return
|
||||
if( $net ne "connected" );
|
||||
if( $net !~ /connected/ );
|
||||
|
||||
my $model = AttrVal($name,"model","");
|
||||
my $creds = Shelly_pwd($hash);
|
||||
@ -1137,7 +1144,7 @@ sub Shelly_pwd($){
|
||||
|
||||
if ( $hash && !$err && !$data ){
|
||||
$url = "http://$creds".$hash->{TCPIP}."/roller/0".$cmd;
|
||||
Log3 $name, 1,"[Shelly_updown] Issue a non-blocking call to $url";
|
||||
Log3 $name, 5,"[Shelly_updown] Issue a non-blocking call to $url";
|
||||
HttpUtils_NonblockingGet({
|
||||
url => $url,
|
||||
callback=>sub($$$){ Shelly_updown($hash,$cmd,$_[1],$_[2]) }
|
||||
@ -1210,7 +1217,7 @@ sub Shelly_updown2($){
|
||||
my $state = $hash->{READINGS}{state}{VAL};
|
||||
my $net = $hash->{READINGS}{network}{VAL};
|
||||
return
|
||||
if( $net ne "connected" );
|
||||
if( $net !~ /connected/ );
|
||||
|
||||
my $model = AttrVal($name,"model","");
|
||||
my $creds = Shelly_pwd($hash);
|
||||
@ -1302,7 +1309,7 @@ sub Shelly_updown2($){
|
||||
my $state = $hash->{READINGS}{state}{VAL};
|
||||
my $net = $hash->{READINGS}{network}{VAL};
|
||||
return
|
||||
if( $net ne "connected" );
|
||||
if( $net !~ /connected/ );
|
||||
|
||||
my $model = AttrVal($name,"model","");
|
||||
|
||||
@ -1310,7 +1317,7 @@ sub Shelly_updown2($){
|
||||
|
||||
if ( $hash && !$err && !$data ){
|
||||
$url = "http://$creds".$hash->{TCPIP}."/meter/".$channel;
|
||||
Log3 $name, 1,"[Shelly_meter] Issue a non-blocking call to $url";
|
||||
Log3 $name, 5,"[Shelly_meter] Issue a non-blocking call to $url";
|
||||
HttpUtils_NonblockingGet({
|
||||
url => $url,
|
||||
callback=>sub($$$){ Shelly_meter($hash,$channel,$_[1],$_[2]) }
|
||||
@ -1351,7 +1358,7 @@ sub Shelly_updown2($){
|
||||
<h3>Shelly</h3>
|
||||
<ul>
|
||||
<p> FHEM module to communicate with a Shelly switch/roller actuator/RGBW controller</p>
|
||||
<a name="Shellydefine"></a>
|
||||
<a name="Shellydefine" id="Shellydefine"></a>
|
||||
<h4>Define</h4>
|
||||
<p>
|
||||
<code>define <name> Shelly <IP address></code>
|
||||
@ -1366,109 +1373,112 @@ sub Shelly_updown2($){
|
||||
<li> For <i>Output switched ON url</i>: http://<FHEM IP address>:<Port>/fhem?XHR=1&cmd=set%20<Devicename>%20<b>out_on</b>%20[<channel>]</li>
|
||||
<li> For <i>Output switched OFF url</i>: http://<FHEM IP address>:<Port>/fhem?XHR=1&cmd=set%20<Devicename>%20<b>out_off</b>%20[<channel>]</li>
|
||||
</ul>
|
||||
Attention: Of course, a csrfToken must be included as well - or a proper allowed device declared.</li>
|
||||
Attention: Of course, a csrfToken must be included as well - or a proper <i>allowed</i> device declared.</li>
|
||||
</ul>
|
||||
<a name="Shellyset"></a>
|
||||
<a name="Shellyset" id="Shellyset></a>
|
||||
<h4>Set</h4>
|
||||
For all Shelly devices
|
||||
<ul>
|
||||
<li><a name="shelly_sconfig"></a>
|
||||
<code>set <name> config <registername> [<channel>] <value></code>
|
||||
<li><code>set <name> config <registername> [<channel>] <value></code>
|
||||
<br />set the value of a configuration register</li>
|
||||
<li><a name="shelly_password">password <password></a><br>This is the only way to set the password for the Shelly web interface</li>
|
||||
<li>password <password><br>This is the only way to set the password for the Shelly web interface</li>
|
||||
</ul>
|
||||
For Shelly switching devices (model=shelly1|shelly1pm|shelly4|shellyplug or (model=shelly2/2.5 and mode=relay))
|
||||
<ul>
|
||||
<li><a name="shelly_onoff"></a>
|
||||
<li>
|
||||
<code>set <name> on|off|toggle [<channel>] </code>
|
||||
<br />switches channel <channel> on or off. Channel numbers are 0 and 1 for model=shelly2/2.5, 0..3 for model=shelly4. If the channel parameter is omitted, the module will switch the channel defined in the defchannel attribute.</li>
|
||||
<li><a name="shelly_onofftimer"></a>
|
||||
<li>
|
||||
<code>set <name> on-for-timer|off-for-timer <time> [<channel>] </code>
|
||||
<br />switches <channel> on or off for <time> seconds. Channel numbers are 0 and 1 for model=shelly2/2.5, and 0..3 model=shelly4. If the channel parameter is omitted, the module will switch the channel defined in the defchannel attribute.</li>
|
||||
<li>
|
||||
<code>set <name> xtrachannels </code>
|
||||
<br />create <i>readingsProxy</i> devices for switching device with more than one channel</li>
|
||||
|
||||
</ul>
|
||||
<br/>For Shelly roller blind devices (model=shelly2/2.5 and mode=roller)
|
||||
<ul>
|
||||
<li><a name="shelly_updown"></a>
|
||||
<li>
|
||||
<code>set <name> open|closed|stop </code>
|
||||
<br />drives the roller blind open, closed or to a stop.</li>
|
||||
<li><a name="shelly_pct"></a>
|
||||
<li>
|
||||
<code>set <name> pct <integer percent value> </code>
|
||||
<br />drives the roller blind to a partially closed position (100=open, 0=closed)</li>
|
||||
<li><a name="shelly_zero"></a>
|
||||
<li>
|
||||
<code>set <name> zero </code>
|
||||
<br />calibration of roller device (only for model=shelly2/2.5)</li>
|
||||
</ul>
|
||||
<br/>For Shelly dimmer devices (model=shellyrgbw and mode=white)
|
||||
<ul>
|
||||
<li><a name="shelly_onoff"></a>
|
||||
<li>
|
||||
<code>set <name> on|off [<channel>] </code>
|
||||
<br />switches channel <channel> on or off. Channel numbers are 0..3 for model=shellyrgbw. If the channel parameter is omitted, the module will switch the channel defined in the defchannel attribute.</li>
|
||||
<li><a name="shelly_onofftimer"></a>
|
||||
<li>
|
||||
<code>set <name> on-for-timer|off-for-timer <time> [<channel>] </code>
|
||||
<br />switches <channel> on or off for <time> seconds. Channel numbers 0..3 for model=shellyrgbw. If the channel parameter is omitted, the module will switch the channel defined in the defchannel attribute.</li>
|
||||
<li><a name="shelly_brightness"></a>
|
||||
<li>
|
||||
<code>set <name> pct <0..100> [<channel>] </code>
|
||||
<br />percent value to set brightness value. Channel numbers 0..3 for model=shellyrgbw. If the channel parameter is omitted, the module will dim the channel defined in the defchannel attribute.</li>
|
||||
</ul>
|
||||
<br/>For Shelly RGBW devices (model=shellyrgbw and mode=color)
|
||||
<ul>
|
||||
<li><a name="shelly_onoff"></a>
|
||||
<li>
|
||||
<code>set <name> on|off</code>
|
||||
<br />switches device <channel> on or off</li>
|
||||
<li><a name="shelly_onofftimer"></a>
|
||||
<li>
|
||||
<code>set <name> on-for-timer|off-for-timer <time></code>
|
||||
<br />switches device on or off for <time> seconds. </li>
|
||||
<li><a name="shelly_hsv"></a>
|
||||
<li>
|
||||
<code>set <name> hsv <hue value 0..360><saturation value 0..1><brightness value 0..1> </code>
|
||||
<br />6-digit hex string to set the color.</li>
|
||||
<li><a name="shelly_rgb"></a>
|
||||
<li>
|
||||
<code>set <name> rgb <rrggbb> </code>
|
||||
<br />6-digit hex string to set the color.</li>
|
||||
<li><a name="shelly_rgbw"></a>
|
||||
<li>
|
||||
<code>set <name> rgbw <rrggbbww> </code>
|
||||
<br />8-digit hex string to set the color and white value</li>
|
||||
<li><a name="shelly_white"></a>
|
||||
<li>
|
||||
<code>set <name> white <integer></code>
|
||||
<br /> number 0..255 to set the white value </li>
|
||||
</ul>
|
||||
<a name="Shellyget"></a>
|
||||
<a name="Shellyget" id="Shellyget"></a>
|
||||
<h4>Get</h4>
|
||||
<ul>
|
||||
<li><a name="shelly_config"></a>
|
||||
<li>
|
||||
<code>get <name> config <registername> [<channel>]</code>
|
||||
<br />get the value of a configuration register and writes it in reading config</li>
|
||||
<li><a name="shelly_registers"></a>
|
||||
<li>
|
||||
<code>get <name> registers</code>
|
||||
<br />displays the names of the configuration registers for this device</li>
|
||||
<li><a name="shelly_status"></a>
|
||||
<li>
|
||||
<code>get <name> status</code>
|
||||
<br />returns the current devices status.</li>
|
||||
<li><a name="shelly_version"></a>
|
||||
<li>
|
||||
<code>get <name> version</code>
|
||||
<br />display the version of the module</li>
|
||||
</ul>
|
||||
<a name="Shellyattr"></a>
|
||||
<a name="Shellyattr" id="Shellyattr"></a>
|
||||
<h4>Attributes</h4>
|
||||
<ul>
|
||||
<li><a name="shelly_shellyuser"><code>attr <name> shellyuser <shellyuser></code><br>username for addressing the Shelly web interface</li>
|
||||
<li><a name="shelly_model"><code>attr <name> model shelly1|shelly1pm|shelly2|shelly2.5|shelly4|shellyplug|shellyrgbw </code></a>
|
||||
<li><code>attr <name> shellyuser <shellyuser></code><br>username for addressing the Shelly web interface</li>
|
||||
<li><<code>attr <name> model shelly1|shelly1pm|shelly2|shelly2.5|shelly4|shellyplug|shellyrgbw </code>
|
||||
<br />type of the Shelly device</li>
|
||||
<li><a name="shelly_mode"><code>attr <name> mode relay|roller (only for model=shelly2/2.5) mode white|color (only for model=shellyrgbw)</code></a>
|
||||
<li><code>attr <name> mode relay|roller (only for model=shelly2/2.5) mode white|color (only for model=shellyrgbw)</code>
|
||||
<br />type of the Shelly device</li>
|
||||
<li><a name="shelly_interval">
|
||||
<li>
|
||||
<code><interval></code>
|
||||
<br />Update interval for reading in seconds. The default is 60 seconds, a value of 0 disables the automatic update. </li>
|
||||
</ul>
|
||||
<br/>For Shelly switching devices (mode=relay for model=shelly2/2.5, standard for all other switching models)
|
||||
<ul>
|
||||
<li><a name="shelly_defchannel"><code>attr <name> defchannel <integer> </code></a>
|
||||
<li><code>attr <name> defchannel <integer> </code>
|
||||
<br />only for model=shelly2|shelly2.5|shelly4 or multi-channel switches: Which channel will be switched, if a command is received without channel number</li>
|
||||
</ul>
|
||||
<br/>For Shelly roller blind devices (mode=roller for model=shelly2/2.5)
|
||||
<ul>
|
||||
<li><a name="shelly_maxtime"><code>attr <name> maxtime <float> </code></a>
|
||||
<li><code>attr <name> maxtime <float> </code>
|
||||
<br />time needed for a complete drive upward or downward</li>
|
||||
<li><a name="shelly_pct100"><code>attr <name> pct100 open|closed (default:open) </code></a>
|
||||
<li><code>attr <name> pct100 open|closed (default:open) </code>
|
||||
<br />is pct=100 open or closed ? </li>
|
||||
</ul>
|
||||
<br/>Standard attributes
|
||||
@ -1483,6 +1493,7 @@ sub Shelly_updown2($){
|
||||
=end html
|
||||
=begin html_DE
|
||||
|
||||
<a name="Shelly"></a>
|
||||
<h3>Shelly</h3>
|
||||
<ul>
|
||||
Absichtlich keine deutsche Dokumentation vorhanden, die englische Version gibt es hier: <a href="commandref.html#Shelly">Shelly</a>
|
||||
|
Loading…
Reference in New Issue
Block a user