diff --git a/fhem/FHEM/36_Shelly.pm b/fhem/FHEM/36_Shelly.pm index a62adec6f..3cf515128 100644 --- a/fhem/FHEM/36_Shelly.pm +++ b/fhem/FHEM/36_Shelly.pm @@ -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","connected to {TCPIP}."\">".$hash->{TCPIP}.""); }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","connected to {TCPIP}."\">".$hash->{TCPIP}."",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($){
FHEM module to communicate with a Shelly switch/roller actuator/RGBW controller
- +
define <name> Shelly <IP address>
@@ -1366,109 +1373,112 @@ sub Shelly_updown2($){
set <name> config <registername> [<channel>] <value>
+ set <name> config <registername> [<channel>] <value>
set <name> on|off|toggle [<channel>]
set <name> on-for-timer|off-for-timer <time> [<channel>]
set <name> xtrachannels
+ set <name> open|closed|stop
set <name> pct <integer percent value>
set <name> zero
set <name> on|off [<channel>]
set <name> on-for-timer|off-for-timer <time> [<channel>]
set <name> pct <0..100> [<channel>]
set <name> on|off
set <name> on-for-timer|off-for-timer <time>
set <name> hsv <hue value 0..360><saturation value 0..1><brightness value 0..1>
set <name> rgb <rrggbb>
set <name> rgbw <rrggbbww>
set <name> white <integer>
get <name> config <registername> [<channel>]
get <name> registers
get <name> status
get <name> version
attr <name> shellyuser <shellyuser>
attr <name> model shelly1|shelly1pm|shelly2|shelly2.5|shelly4|shellyplug|shellyrgbw
+ attr <name> shellyuser <shellyuser>
attr <name> model shelly1|shelly1pm|shelly2|shelly2.5|shelly4|shellyplug|shellyrgbw
attr <name> mode relay|roller (only for model=shelly2/2.5) mode white|color (only for model=shellyrgbw)
+ attr <name> mode relay|roller (only for model=shelly2/2.5) mode white|color (only for model=shellyrgbw)
<interval>
attr <name> defchannel
+ attr <name> defchannel
attr <name> maxtime <float>
+ attr <name> maxtime <float>
attr <name> pct100 open|closed (default:open)
+ attr <name> pct100 open|closed (default:open)