From eaa8ff2d80fc6383838c958fda517a71aa5f5695 Mon Sep 17 00:00:00 2001 From: andi291 <> Date: Sat, 14 Oct 2017 18:43:54 +0000 Subject: [PATCH] 86_Robonect.pm: # ABU 20171006 added options for Maehauftrag # ABU 20171006 added "umlautfilter" for test # ABU 20171006 added "health" for test # ABU 20171010 finished health for test, added chck for undef at each reading git-svn-id: https://svn.fhem.de/fhem/trunk@15258 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/86_Robonect.pm | 233 +++++++++++++++++++++++++++++++++------ 1 file changed, 198 insertions(+), 35 deletions(-) diff --git a/fhem/FHEM/86_Robonect.pm b/fhem/FHEM/86_Robonect.pm index 000d7d507..d11d8bf11 100644 --- a/fhem/FHEM/86_Robonect.pm +++ b/fhem/FHEM/86_Robonect.pm @@ -34,8 +34,10 @@ # ABU 20170501 tuned documentation # ABU 20170516 removed useless print # ABU 20170525 bugfixed winterschlaf again -# ABU 20170613 added Maehauftrag - +# ABU 20171006 added options for Maehauftrag +# ABU 20171006 added "umlautfilter" for test +# ABU 20171006 added "health" for test +# ABU 20171010 finished health for test, added chck for undef at each reading package main; @@ -59,7 +61,8 @@ my $PW = "passwort"; #available get cmds my %gets = ( - "status" => "noArg" + "status" => "noArg", + "health" => "noArg" ); #available set cmds @@ -68,7 +71,7 @@ my %sets = ( $HOME => "noArg", $AUTO => "noArg", $MANUAL => "noArg", - $JOB => "noArg", + $JOB => "", $START => "noArg", $STOP => "noArg", $HYBERNATE => "on,off", @@ -77,7 +80,7 @@ my %sets = ( ); my %commands = ( - GET_STATUS => "cmd=status", + #GET_STATUS => "cmd=status", SET_MODE => {$HOME=>"cmd=mode&mode=home", $MANUAL=>"cmd=mode&mode=man", $JOB=>"cmd=mode&mode=job", $AUTO=>"cmd=mode&mode=auto", $EOD=>"cmd=mode&mode=eod", $STOP=>"cmd=stop", $START=>"cmd=start"} ); @@ -100,6 +103,37 @@ my %elements = ( "hours" => {ALIAS=>"betriebsstunden"} }, + "health" => + { + ALIAS => "erweitert", + "alarm" => + { + ALIAS => "alarm", + "voltage3v3extmin" => {ALIAS=>"unterspannung_extern_3V3", "false"=> "bereit", "true"=>"alarm"}, + "voltage3v3extmax" => {ALIAS=>"ueberspannung_extern_3V3", "false"=> "bereit", "true"=>"alarm"}, + "voltage3v3intmin" => {ALIAS=>"unterspannung_intern_3V3", "false"=> "bereit", "true"=>"alarm"}, + "voltage3v3intmax" => {ALIAS=>"ueberspannung_intern_3V3", "false"=> "bereit", "true"=>"alarm"}, + "voltagebattmin" => {ALIAS=>"unterspannung_batterie", "false"=> "bereit", "true"=>"alarm"}, + "voltagebattmax" => {ALIAS=>"ueberspannung_batterie", "false"=> "bereit", "true"=>"alarm"}, + "temperatureMin" => {ALIAS=>"zu_kalt", "false"=> "bereit", "true"=>"alarm"}, + "temperatureMax" => {ALIAS=>"zu_warm", "false"=> "bereit", "true"=>"alarm"}, + "humidityMax" => {ALIAS=>"zu_feucht", "false"=> "bereit", "true"=>"alarm"}, + }, + "voltages" => + { + ALIAS => "spannung", + "ext3v3" => {ALIAS=>"extern"}, + "int3v3" => {ALIAS=>"intern"}, + "batt" => {ALIAS=>"batterie"}, + }, + "climate" => + { + ALIAS => "umwelt", + "temperature" => {ALIAS=>"temperatur"}, + "humidity" => {ALIAS=>"feuchte"}, + } + }, + "timer" => { ALIAS => "timer", @@ -130,6 +164,9 @@ my %elements = ( # } ); +#this table is used to replace special chars +my %umlaute = ("ä" => "ä", "ü" => "ü", "ö" => "ö","Ä" => "Ä", "Ü" => "Ü", "Ö" => "Ö", "ß" => "ß"); + #Init this device #This declares the interface to fhem ############################# @@ -149,7 +186,8 @@ sub Robonect_Initialize($) { "credentials " . #user/password combination for authentication in mower, stored in a credentials file "basicAuth " . #user/password combination for authentication in mower "pollInterval " . #interval to poll in seconds - "timeout " . #interval to poll in seconds + "timeout " . #http-timeout + "useHealth " . #if true, poll for health "$readingFnAttributes "; #standard attributes } @@ -303,7 +341,8 @@ sub Robonect_Get($@) #append userdata, if given $url = $url . "user=" . $userName . "&pass=" . $passWord . "&" if (defined ($userName) and defined ($passWord)); #append command - $url = $url . $commands{GET_STATUS}; + #$url = $url . $commands{GET_STATUS}; + $url = $url . "cmd=" . $cmd; my $httpData; $httpData->{url} = $url; @@ -312,7 +351,8 @@ sub Robonect_Get($@) $httpData->{hideurl} = 0; $httpData->{callback} = \&Robonect_callback; $httpData->{hash} = $hash; - $httpData->{cmd} = $commands{GET_STATUS}; + #$httpData->{cmd} = $commands{GET_STATUS}; + $httpData->{cmd} = "cmd=" . $cmd; $httpData->{timeout} = AttrVal ($name, "timeout", 4); HttpUtils_NonblockingGet($httpData); @@ -345,7 +385,7 @@ sub Robonect_Set($@) my $cmd = $a[1]; #lower cmd $cmd = lc($cmd); - + #create response, if cmd is wrong or gui asks my $cmdTemp = Robonect_getCmdList ($hash, $cmd, %sets); return $cmdTemp if (defined ($cmdTemp)); @@ -377,13 +417,13 @@ sub Robonect_Set($@) } } #if command is user - if ($cmd eq lc($USER)) + elsif ($cmd eq lc($USER)) { setKeyValue("ROBONECT_USER_$name", $a[2]); Log3 ($name, 5, "set - wrote username"); } #if command is password - if ($cmd eq lc($PW)) + elsif ($cmd eq lc($PW)) { setKeyValue("ROBONECT_PW_$name", $a[2]); Log3 ($name, 5, "set - wrote password"); @@ -398,7 +438,26 @@ sub Robonect_Set($@) $url = $url . "user=" . $userName . "&pass=" . $passWord . "&" if (defined ($userName) and defined ($passWord)); #append command $url = $url . $decodedCmd; + + #execute for alle "extra" arguments + for (my $i = 2; $i < @a; $i++) + { + my $cmdAttr = $a[$i]; + my ($key, $val) = split (/=/, $cmdAttr); + if (defined ($key) and defined ($val) and (length ($key) > 0) and (length ($val) > 0)) + { + $url = $url . "&" . $key . "=" . $val; + Log3 ($name, 5, "set - found option. Key:$key Value:$val") + } + else + { + Log3 ($name, 1, "set - found incomplete option. Key:$key Value:$val") + } + } + + Log3 ($name, 5, "set - complete call-string: $url"); + my $httpData; $httpData->{url} = $url; $httpData->{loglevel} = AttrVal ($name, "verbose", 2); @@ -411,8 +470,9 @@ sub Robonect_Set($@) HttpUtils_NonblockingGet($httpData); return $httpData->{err}; - - Robonect_GetUpdate($hash); + + #BUllshit - never gets called + #Robonect_GetUpdate($hash); } Log3 ($name, 5, "exit set"); @@ -531,6 +591,14 @@ sub Robonect_GetUpdate($) $callAttr[0] = $name; $callAttr[1] = "status"; Robonect_Get ($hash, @callAttr); + + #try to poll health, if desired + my $useHealth = AttrVal($name,"useHealth",undef); + if (defined ($useHealth) and ($useHealth =~ m/[1]|([oO][nN])/)) + { + $callAttr[1] = "health"; + Robonect_Get ($hash, @callAttr); + } } my $interval = AttrVal($name,"pollInterval",90); @@ -569,6 +637,13 @@ sub Robonect_callback ($) my $answer = undef; eval '$answer = decode_json (encode_utf8($data))'; + #try to replaye german special chars + if (defined ($answer) and (length ($answer) > 0)) + { + my $umlautkeys = join ("|", keys(%umlaute)); + $answer =~ s/($umlautkeys)/$umlaute{$1}/g; + } + #backup error from eval my $evalErr = $@; @@ -605,29 +680,32 @@ sub Robonect_callback ($) #readingsBulkUpdate($hash, $key, $value); ($key, $value) = Robonect_decodeContent ($hash, $answer, "status", "status", undef); - readingsBulkUpdate($hash, $key, $value); - readingsBulkUpdate($hash, "state", $value); + if (defined ($value) and !($value =~ m/undef/)) + { + readingsBulkUpdate($hash, $key, $value); + readingsBulkUpdate($hash, "state", $value); + } ($key, $value) = Robonect_decodeContent ($hash, $answer, "status", "mode", undef); - readingsBulkUpdate($hash, $key, $value); + readingsBulkUpdate($hash, $key, $value) if (defined ($value) and !($value =~ m/undef/)); ($key, $value) = Robonect_decodeContent ($hash, $answer, "status", "battery", undef); - readingsBulkUpdate($hash, $key, $value); + readingsBulkUpdate($hash, $key, $value) if (defined ($value) and !($value =~ m/undef/)); $value = 0; ($key, $value) = Robonect_decodeContent ($hash, $answer, "status", "duration", undef); readingsBulkUpdate($hash, $key, sprintf ("%d", $value/3600)) if (defined($value) and ($value =~ m/(?:\d*\.)?\d+/)); ($key, $value) = Robonect_decodeContent ($hash, $answer, "status", "hours", undef); - readingsBulkUpdate($hash, $key, $value); + readingsBulkUpdate($hash, $key, $value) if (defined ($value) and !($value =~ m/undef/)); ($key, $value) = Robonect_decodeContent ($hash, $answer, "timer", "status", undef); - readingsBulkUpdate($hash, $key, $value); + readingsBulkUpdate($hash, $key, $value) if (defined ($value) and !($value =~ m/undef/)); ($key, $value) = Robonect_decodeContent ($hash, $answer, "timer", "next", "date"); - readingsBulkUpdate($hash, $key, $value); + readingsBulkUpdate($hash, $key, $value) if (defined ($value) and !($value =~ m/undef/)); ($key, $value) = Robonect_decodeContent ($hash, $answer, "timer", "next", "time"); - readingsBulkUpdate($hash, $key, $value); + readingsBulkUpdate($hash, $key, $value) if (defined ($value) and !($value =~ m/undef/)); $value = -95; ($key, $value) = Robonect_decodeContent ($hash, $answer, "wlan", "signal", undef); - readingsBulkUpdate($hash, $key, $value); + readingsBulkUpdate($hash, $key, $value) if (defined ($value) and !($value =~ m/undef/)); if (defined($value) and ($value =~ m/(?:\d*\.)?\d+/)) { @@ -635,6 +713,35 @@ sub Robonect_callback ($) readingsBulkUpdate($hash, $key . "-prozent", $value); } + #try to decode health, if desired + my $useHealth = AttrVal($name,"useHealth",undef); + if (defined ($useHealth) and ($useHealth =~ m/[1]|([oO][nN])/)) + { + ($key, $value) = Robonect_decodeContent ($hash, $answer, "health", "alarm", "voltagebattmin"); + readingsBulkUpdate($hash, $key, $value) if (defined ($value) and !($value =~ m/undef/)); + + ($key, $value) = Robonect_decodeContent ($hash, $answer, "health", "alarm", "voltagebattmax"); + readingsBulkUpdate($hash, $key, $value) if (defined ($value) and !($value =~ m/undef/)); + + ($key, $value) = Robonect_decodeContent ($hash, $answer, "health", "alarm", "temperatureMin"); + readingsBulkUpdate($hash, $key, $value) if (defined ($value) and !($value =~ m/undef/)); + + ($key, $value) = Robonect_decodeContent ($hash, $answer, "health", "alarm", "temperatureMax"); + readingsBulkUpdate($hash, $key, $value) if (defined ($value) and !($value =~ m/undef/)); + + ($key, $value) = Robonect_decodeContent ($hash, $answer, "health", "alarm", "humidityMax"); + readingsBulkUpdate($hash, $key, $value) if (defined ($value) and !($value =~ m/undef/)); + + ($key, $value) = Robonect_decodeContent ($hash, $answer, "health", "voltages", "batt"); + readingsBulkUpdate($hash, $key, $value) if (defined ($value) and !($value =~ m/undef/)); + + ($key, $value) = Robonect_decodeContent ($hash, $answer, "health", "umwelt", "temperature"); + readingsBulkUpdate($hash, $key, $value) if (defined ($value) and !($value =~ m/undef/)); + + ($key, $value) = Robonect_decodeContent ($hash, $answer, "health", "umwelt", "humidity"); + readingsBulkUpdate($hash, $key, $value) if (defined ($value) and !($value =~ m/undef/)); + } + readingsEndUpdate($hash, 1); } @@ -849,7 +956,8 @@ sub Robonect_getCmdList ($$$) #append option, if valid $retVal = $retVal . ":" . $myOpt if (defined ($myOpt) and (length ($myOpt) > 0)); $myOpt = "" if (!defined($myOpt)); - Log3 ($name, 5, "parse cmd-table - Set:$mySet, Option:$myOpt, RetVal:$retVal"); + #Logging makes me crazy... + #Log3 ($name, 5, "parse cmd-table - Set:$mySet, Option:$myOpt, RetVal:$retVal"); } if (!defined ($retVal)) @@ -913,6 +1021,16 @@ sub Robonect_getCmdList ($$$)
  • stop
    Stops mowing immediately. The mower does not drive home. It stands there, until battery is empty. Use with care!
  • +
  • maehauftrag
    + This command starts a single mowing-task. It can be applied as much parameters as you want. For example you can influence start-/stop-time and duration.
    + The parameters have to be named according the robonect-API (no doublechecking!).
    +
    + Example:
    + Lauch at 15:00, Duration 120 minutes, do not use a remote-start-point, do not change mode after finishing task +
    +			  set myMower maehauftrag start=15:00 duration=120 remotestart=0 after=4
    +			
    +
  • winterschlaf <on, off>
    If set to on, no polling is executet. Please use this during winter.
  • @@ -927,10 +1045,18 @@ sub Robonect_getCmdList ($$$) -

    Get

    - =end html =device @@ -1002,7 +1135,7 @@ sub Robonect_getCmdList ($$$)

    Robonect

    Get

    -