36_Shelly.pm: Neue Version mit ein paar Fixes

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@19557 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
phenning 2019-06-05 16:56:03 +00:00
parent eec8db7af7
commit c99cb2d842

View File

@ -38,7 +38,7 @@ use vars qw{%attr %defs};
sub Log($$); sub Log($$);
#-- globals on start #-- globals on start
my $version = "2.02"; my $version = "2.03";
#-- these we may get on request #-- these we may get on request
my %gets = ( my %gets = (
@ -107,14 +107,14 @@ my %shelly_models = (
); );
my %shelly_regs = ( my %shelly_regs = (
"relay" => "reset=1\x{27f6}factory reset\ndefault_state=off|on|last|switch\x{27f6}state after power on\nbtn_type=momentary|toggle|edge\x{27f6}type of local button\nauto_on=<seconds>\x{27f6}timed on\nauto_off=<seconds>\x{27f6}timed off", "relay" => "reset=1\x{27f6}factory reset\ndefault_state=off|on|last|switch\x{27f6}state after power on\nbtn_type=momentary|toggle|edge|detached\x{27f6}type of local button\nauto_on=<seconds>\x{27f6}timed on\nauto_off=<seconds>\x{27f6}timed off",
"roller" => "reset=1\x{27f6}factory reset\ndefault_state=stop|open|close|switch\x{27f6}state after power on\nswap=true|false\x{27f6}swap open and close\ninput_mode=openclose|onebutton\x{27f6}two or one local button\n". "roller" => "reset=1\x{27f6}factory reset\ndefault_state=stop|open|close|switch\x{27f6}state after power on\nswap=true|false\x{27f6}swap open and close\ninput_mode=openclose|onebutton\x{27f6}two or one local button\n".
"btn_type=momentary|toggle\x{27f6}type of local button\nobstacle_mode=disabled|while_opening|while_closing|while_moving\x{27f6}when to watch\nobstacle_action=stop|reverse\x{27f6}what to do\n". "btn_type=momentary|toggle|detached\x{27f6}type of local button\nobstacle_mode=disabled|while_opening|while_closing|while_moving\x{27f6}when to watch\nobstacle_action=stop|reverse\x{27f6}what to do\n".
"obstacle_power=<watt>\x{27f6}power threshold for detection\nobstacle_delay=<seconds>\x{27f6}delay after motor start to watch\n". "obstacle_power=<watt>\x{27f6}power threshold for detection\nobstacle_delay=<seconds>\x{27f6}delay after motor start to watch\n".
"safety_mode=disabled|while_opening|while_closing|while_moving\x{27f6}safety mode=2nd button\nsafety_action=stop|pause|reverse\x{27f6}action when safety mode\n". "safety_mode=disabled|while_opening|while_closing|while_moving\x{27f6}safety mode=2nd button\nsafety_action=stop|pause|reverse\x{27f6}action when safety mode\n".
"safety_allowed_on_trigger=none|open|close|all\x{27f6}commands allowed in safety mode", "safety_allowed_on_trigger=none|open|close|all\x{27f6}commands allowed in safety mode",
"rgbw" => "" "color" => "reset=1\x{27f6}factory reset\neffect=0|1|2|3|4|5|6{27f6}apply an effect\ndefault_state=off|on|last{27f6}state after power on\nbtn_type=momentary|toggle|edge|detached\x{27f6}type of local button\nbtn_reverse=0|1\x{27f6}invert local button\nauto_on=<seconds>\x{27f6}timed on\nauto_off=<seconds>\x{27f6}timed off",
); "white" => "reset=1\x{27f6}factory reset\ndefault_state=off|on|last{27f6}state after power on\nbtn_type=momentary|toggle|edge|detached\x{27f6}type of local button\nbtn_reverse=0|1\x{27f6}invert local button\nauto_on=<seconds>\x{27f6}timed on\nauto_off=<seconds>\x{27f6}timed off");
######################################################################################## ########################################################################################
# #
@ -378,33 +378,43 @@ sub Shelly_Get ($@) {
#-- some help on registers #-- some help on registers
}elsif($a[1] eq "registers") { }elsif($a[1] eq "registers") {
my $txt = "relay"; my $txt;
$txt = "roller" if( ($model =~ /shelly2.*/) && ($mode eq "roller") ){
if( ($model =~ /shelly2.*/) && ($mode eq "roller") ); $txt = "roller";
return $shelly_regs{$txt}."\n\nSet/Get these registers by calling set/get $name config <registername> [<channel>] <value>"; }elsif( ($model eq "shellyrgbw") && ($mode eq "white") ){
$txt = "white";
}elsif( ($model eq "shellyrgbw") && ($mode eq "color") ){
$txt = "color";
}else{
$txt = "relay";
}
return $shelly_regs{"$txt"}."\n\nSet/Get these registers by calling set/get $name config <registername> <value> [<channel>]";
#-- configuration register #-- configuration register
}elsif($a[1] eq "config") { }elsif($a[1] eq "config") {
my $reg = $a[2]; my $reg = $a[2];
my ($chan,$val); my ($val,$chan);
if( int(@a) == 5 ){ if( int(@a) == 4 ){
$chan = $a[3]; $chan = $a[3];
$val = $a[4]; }elsif( int(@a) == 3 ){
}elsif( int(@a) == 4 ){
$chan = 0; $chan = 0;
$val = $a[3];
}else{ }else{
my $msg = "Error: wrong number of parameters"; my $msg = "Error: wrong number of parameters";
Log3 $name,1,"[Shelly_Get] ".$msg; Log3 $name,1,"[Shelly_Get] ".$msg;
return $msg; return $msg;
} }
my $pre = "settings/"; my $pre = "settings/";
if( ($model =~ /shelly2.*/) && ($mode eq "roller") ){ if( ($model =~ /shelly2.*/) && ($mode eq "roller") ){
$pre .= "roller/$chan?"; $pre .= "roller/0?";
}elsif( ($model eq "shellyrgbw") && ($mode eq "white") ){
$pre .= "white/0?";
}elsif( ($model eq "shellyrgbw") && ($mode eq "color") ){
$pre .= "color/0?";
}else{ }else{
$pre .= "relay/$chan?"; $pre .= "relay/$chan?";
$v = Shelly_configure($hash,$pre.$reg);
} }
$v = Shelly_configure($hash,$pre.$reg);
#-- else #-- else
} else { } else {
@ -693,10 +703,10 @@ sub Shelly_Set ($@) {
#-- configuration register #-- configuration register
if($cmd eq "config") { if($cmd eq "config") {
my $reg = $value; my $reg = $value;
my ($chan,$val); my ($val,$chan);
if( int(@a) == 2 ){ if( int(@a) == 2 ){
$chan = $a[0]; $chan = $a[1];
$val = $a[1]; $val = $a[0];
}elsif( int(@a) == 1 ){ }elsif( int(@a) == 1 ){
$chan = 0; $chan = 0;
$val = $a[0]; $val = $a[0];
@ -707,15 +717,15 @@ sub Shelly_Set ($@) {
} }
my $pre = "settings/"; my $pre = "settings/";
if( ($model =~ /shelly2.*/) && ($mode eq "roller") ){ if( ($model =~ /shelly2.*/) && ($mode eq "roller") ){
$pre .= "roller/$chan?"; $pre .= "roller/0?";
}elsif( ($model eq "shellyrgbw") && ($mode eq "white") ){ }elsif( ($model eq "shellyrgbw") && ($mode eq "white") ){
$pre .= "white/$chan?"; $pre .= "white/0?";
}elsif( ($model eq "shellyrgbw") && ($mode eq "color") ){ }elsif( ($model eq "shellyrgbw") && ($mode eq "color") ){
$pre .= "color/$chan?"; $pre .= "color/0?";
}else{ }else{
$pre .= "relay/$chan?"; $pre .= "relay/$chan?";
$v = Shelly_configure($hash,$pre.$reg."=".$val);
} }
$v = Shelly_configure($hash,$pre.$reg."=".$val);
} }
#-- password #-- password
@ -796,10 +806,14 @@ sub Shelly_pwd($){
#-- isolate register name #-- isolate register name
my $reg = substr($cmd,index($cmd,"?")+1); my $reg = substr($cmd,index($cmd,"?")+1);
my $chan= substr($cmd,index($cmd,"?")-1,1);
$reg = substr($reg,0,index($reg,"="))
if(index($reg,"=") > 0);
my $val = $jhash->{$reg}; my $val = $jhash->{$reg};
$val = "" $val = ""
if(!defined($val)); if(!defined($val));
readingsSingleUpdate($hash,"config",$reg."=".$val,1); $chan = " [channel $chan]";
readingsSingleUpdate($hash,"config",$reg."=".$val.$chan,1);
return undef; return undef;
} }
@ -1330,7 +1344,7 @@ sub Shelly_updown2($){
readingsSingleUpdate($hash,"state","Error",1); readingsSingleUpdate($hash,"state","Error",1);
return; return;
} }
Log3 $name, 1,"[Shelly_meter] has obtained data $data"; Log3 $name, 5,"[Shelly_meter] has obtained data $data";
my $json = JSON->new->utf8; my $json = JSON->new->utf8;
my $jhash = eval{ $json->decode( $data ) }; my $jhash = eval{ $json->decode( $data ) };
@ -1381,7 +1395,7 @@ sub Shelly_updown2($){
<h4>Set</h4> <h4>Set</h4>
For all Shelly devices For all Shelly devices
<ul> <ul>
<li><code>set &lt;name&gt; config &lt;registername&gt; [&lt;channel&gt;] &lt;value&gt;</code> <li><code>set &lt;name&gt; config &lt;registername&gt; &lt;value&gt; [&lt;channel&gt;] </code>
<br />set the value of a configuration register</li> <br />set the value of a configuration register</li>
<li>password &lt;password&gt;<br>This is the only way to set the password for the Shelly web interface</li> <li>password &lt;password&gt;<br>This is the only way to set the password for the Shelly web interface</li>
</ul> </ul>