diff --git a/fhem/FHEM/36_Shelly.pm b/fhem/FHEM/36_Shelly.pm index c8e46a02f..9688c3b00 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 = "1.6"; +my $version = "1.7"; #-- these we may get on request my %gets = ( @@ -64,14 +64,14 @@ my %setsrol = ( "stop:noArg" => "S", "config" => "K", "password" => "W", - "pct:slider,0,1,100" => "P" + "pct:slider,0,1,100" => "P", + "zero:noArg" => "Z" ); my %shelly_models = ( #(relays,rollers,meters) "shelly1" => [1,0,0,], "shelly2" => [2,1,1], - "shelly2beta" => [2,1,1], "shellyplug" => [1,0,1], "shelly4" => [4,0,4] ); @@ -198,6 +198,8 @@ sub Shelly_Attr(@) { #--------------------------------------- if ( ($cmd eq "set") && ($attrName =~ /model/) ) { + Log 1,"[Shelly_Attr] =====> Attribute model=shelly2beta deprecated, please replace by model=shelly2" + if( $model eq "shelly2beta" ); my $regex = "((".join(")|(",(keys %shelly_models))."))"; if( $attrVal !~ /$regex/){ Log3 $name,1,"[Shelly_Attr] wrong value of model attribute, see documentation for possible values"; @@ -229,7 +231,7 @@ sub Shelly_Attr(@) { #--------------------------------------- }elsif ( ($cmd eq "set") && ($attrName =~ /mode/) ) { if( $model !~ /shelly2.*/ ){ - Log3 $name,1,"[Shelly_Attr] setting the mode attribute only works for model=shelly2[xxx]"; + Log3 $name,1,"[Shelly_Attr] setting the mode attribute only works for model=shelly2"; return } if( $attrVal !~ /((relay)|(roller))/){ @@ -249,7 +251,7 @@ sub Shelly_Attr(@) { #--------------------------------------- }elsif ( ($cmd eq "set") && ($attrName eq "maxtime") ) { if( ($model !~ /shelly2.*/) || ($mode ne "roller" ) ){ - Log3 $name,1,"[Shelly_Attr] setting the maxtime attribute only works for model=shelly2[xxx] and mode=roller"; + Log3 $name,1,"[Shelly_Attr] setting the maxtime attribute only works for model=shelly2 and mode=roller"; return } Shelly_configure($hash,"settings?maxtime=".$attrVal); @@ -257,7 +259,7 @@ sub Shelly_Attr(@) { #--------------------------------------- }elsif ( ($cmd eq "set") && ($attrName eq "pct100") ) { if( ($model !~ /shelly2.*/) || ($mode ne "roller" ) ){ - Log3 $name,1,"[Shelly_Attr] setting the pct100 attribute only works for model=shelly2[xxx] and mode=roller"; + Log3 $name,1,"[Shelly_Attr] setting the pct100 attribute only works for model=shelly2 and mode=roller"; return } @@ -416,9 +418,6 @@ sub Shelly_Set ($@) { #-- WEB asking for command list if( $cmd eq "?" ) { $newkeys = join(" ", sort keys %setsrol); - if( $model eq "shelly2beta" ){ - $newkeys .= " zero:noArg"; - } return "[Shelly_Set] Unknown argument " . $cmd . ", choose one of ".$newkeys; } @@ -454,46 +453,14 @@ sub Shelly_Set ($@) { my $pos = ReadingsVal($name,"position",""); my $pct = ReadingsVal($name,"pct",undef); - #-- shelly2 cannot memorize position, commands are only "go" - if( $model eq "shelly2" ){ - if( !$max ){ - $msg = "Error: pct value can be set for model=shelly2 only if maxtime attribute is set properly"; - Log3 $name,1,"[Shelly_Set] ".$msg; - return $msg - } - if( $pos eq "open" ){ - $time = int( ($pctnormal ? $max*(100-$targetpct) : $max*$targetpct)/10)/10; - $cmd = "?go=close&duration=".$time; - $hash->{MOVING} = "moving_down"; - }elsif( $pos eq "closed" ){ - $time = int( ($pctnormal ? $max*$targetpct : $max*(100-$targetpct))/10)/10; - $cmd = "?go=open&duration=".int($time/10)/10; - $hash->{MOVING} = "moving_up"; - }else{ - if( !defined($pct) || ($pct !~ /\d\d?\d?/) ){ - $msg = "Error: current pct value unknown. Open or close roller blind before"; - Log3 $name,1,"[Shelly_Set] ".$msg; - return $msg; - } - if( $targetpct > $pct ){ - $time = int( ($max*($targetpct-$pct))/10 )/10; - $cmd = $pctnormal ? "?go=open&duration=".$time : "?go=close&duration=".$time; - $hash->{MOVING} = $pctnormal ? "moving_up" : "moving_down"; - }else{ - $time = int(($max*($pct-$targetpct))/10)/10; - $cmd = $pctnormal ? "?go=close&duration=".$time : "?go=open&duration=".$time; - $hash->{MOVING} = $pctnormal ? "moving_down" : "moving_up"; - } - } - }else{ - if( !$max ){ - Log3 $name,1,"[Shelly_Set] please set the maxtime attribute for proper operation"; - $max = 20; - } - $time = int(abs($targetpct-$pct)/100*$max); - $cmd = "?go=to_pos&roller_pos=".$targetpct; - $hash->{MOVING} = $pctnormal ? (($targetpct > $pct) ? "moving_up" : "moving_down") : (($targetpct > $pct) ? "moving_down" : "moving_up"); + if( !$max ){ + Log3 $name,1,"[Shelly_Set] please set the maxtime attribute for proper operation"; + $max = 20; } + $time = int(abs($targetpct-$pct)/100*$max); + $cmd = "?go=to_pos&roller_pos=".$targetpct; + $hash->{MOVING} = $pctnormal ? (($targetpct > $pct) ? "moving_up" : "moving_down") : (($targetpct > $pct) ? "moving_down" : "moving_up"); + $hash->{DURATION} = $time; $hash->{TARGETPCT} = $targetpct; Shelly_updown($hash,$cmd); @@ -604,6 +571,8 @@ sub Shelly_pwd($){ #-- isolate register name my $reg = substr($cmd,index($cmd,"?")+1); my $val = $jhash->{$reg}; + $val = "" + if(!defined($val)); readingsSingleUpdate($hash,"config",$reg."=".$val,1); return undef; @@ -716,7 +685,7 @@ sub Shelly_pwd($){ #-- we have data from the device, take that one if( defined($rcurrpos) && ($rcurrpos =~ /\d\d?\d?/) ){ - Log3 $name,1,"[Shelly_status] device $name with model=shelly2 returns a blind position, consider chosing a different model=shelly2[xxx]" + Log3 $name,1,"[Shelly_status] device $name with model=shelly2 returns a blind position, consider chosing a different model=shelly2" if( $model eq "shelly2" ); $pct = $pctnormal ? $rcurrpos : 100-$rcurrpos; $position = ($rcurrpos==100) ? "open" : ($rcurrpos==0 ? "closed" : $pct); @@ -1041,16 +1010,16 @@ sub Shelly_updown2($){
set the value of a configuration register
  • password <password>
    This is the only way to set the password for the Shelly web interface
  • - For Shelly switching devices (mode=relay for model=shelly2[xxx], standard for all other models) + For Shelly switching devices (mode=relay for model=shelly2, standard for all other models) -
    For Shelly roller blind devices (mode=roller for model=shelly2[xxx]) +
    For Shelly roller blind devices (mode=roller for model=shelly2)

    Get

    @@ -1082,20 +1051,20 @@ sub Shelly_updown2($){

    Attributes

    -
    For Shelly switching devices (mode=relay for model=shelly2[xxx], standard for all other models) +
    For Shelly switching devices (mode=relay for model=shelly2, standard for all other models)
    -
    For Shelly roller blind devices (mode=roller for model=shelly2[xxx]) +
    For Shelly roller blind devices (mode=roller for model=shelly2)