From e9835d7548bce9dd133e91fabb57c06532f49f24 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Fri, 4 Sep 2015 11:01:01 +0200 Subject: [PATCH] =?UTF-8?q?Umfassende=20erweiterung=20der=20Fehlerbehandlu?= =?UTF-8?q?ng,=20versuch=20der=20Selbstheilung=20der=20Flows=20bei=20inakt?= =?UTF-8?q?ive=20schalten.=20Erweiterte=20Fehlerausgabe=20bei=20Problemen?= =?UTF-8?q?=20mit=20der=20Verbindung=20zu=20den=20Ger=C3=A4ten.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 74_AMAD.pm | 529 +++++++++++------- ....5.3.xml => 74_AMADautomagicFlows0.5.9.xml | 499 ++++++++++------- README.md | 35 +- 3 files changed, 640 insertions(+), 423 deletions(-) rename Automagic_FHEM-AMAD_FlowsSet_v0.5.3.xml => 74_AMADautomagicFlows0.5.9.xml (57%) diff --git a/74_AMAD.pm b/74_AMAD.pm index c0a38ef..14e3ae5 100644 --- a/74_AMAD.pm +++ b/74_AMAD.pm @@ -33,7 +33,7 @@ use Time::HiRes qw(gettimeofday); use HttpUtils; -my $version = "0.5.8"; +my $version = "0.5.9"; @@ -56,15 +56,22 @@ sub AMAD_Initialize($) { "port ". "disable:1 "; $hash->{AttrList} .= $readingFnAttributes; + + + foreach my $d(sort keys %defs) { + next if($defs{$d}{TYPE} ne "AMAD"); + $defs{$d}->{VERSION} = $version; + } } sub AMAD_Define($$) { - my ( $hash, $def ) = @_; +my ( $hash, $def ) = @_; my @a = split( "[ \t][ \t]*", $def ); return "too few parameters: define AMAD " if ( @a != 3 ); + my $name = $a[0]; my $host = $a[2]; my $port = 8090; @@ -74,47 +81,51 @@ sub AMAD_Define($$) { $hash->{PORT} = $port; $hash->{INTERVAL} = $interval; $hash->{VERSION} = $version; + $hash->{helper}{infoErrorCounter} = 0; + $hash->{helper}{setCmdErrorCounter} = 0; Log3 $name, 3, "AMAD ($name) - defined with host $hash->{HOST} on port $hash->{HOST} and interval $hash->{INTERVAL} (sec)"; - AMAD_GetUpdateLocal($hash); + AMAD_GetUpdateLocal( $hash ); - InternalTimer(gettimeofday()+$hash->{INTERVAL}, "AMAD_GetUpdateTimer", $hash, 0); + InternalTimer( gettimeofday()+$hash->{INTERVAL}, "AMAD_GetUpdateTimer", $hash, 0 ); $hash->{STATE} = "initialized"; - readingsSingleUpdate ($hash,"deviceState","online",0); + readingsSingleUpdate ( $hash, "deviceState", "online", 0 ); return undef; } sub AMAD_Undef($$) { - my ($hash, $arg) = @_; - RemoveInternalTimer($hash); +my ( $hash, $arg ) = @_; + + RemoveInternalTimer( $hash ); return undef; } sub AMAD_Attr(@) { - my ( $cmd, $name, $attrName, $attrVal) = @_; + +my ( $cmd, $name, $attrName, $attrVal ) = @_; my $hash = $defs{$name}; - if ($attrName eq "disable") { - if($cmd eq "set") { - if($attrVal eq "0") { - RemoveInternalTimer($hash); - InternalTimer(gettimeofday()+2, "AMAD_GetUpdateTimer", $hash, 0) if ($hash->{STATE} eq "disabled"); + if( $attrName eq "disable" ) { + if( $cmd eq "set" ) { + if( $attrVal eq "0" ) { + RemoveInternalTimer( $hash ); + InternalTimer( gettimeofday()+2, "AMAD_GetUpdateTimer", $hash, 0 ) if( $hash->{STATE} eq "disabled" ); $hash->{STATE}='active'; Log3 $name, 3, "AMAD ($name) - enabled"; } else { $hash->{STATE} = 'disabled'; - RemoveInternalTimer($hash); + RemoveInternalTimer( $hash ); Log3 $name, 3, "AMAD ($name) - disabled"; } } - elsif ($cmd eq "del") { - RemoveInternalTimer($hash); - InternalTimer(gettimeofday()+2, "AMAD_GetUpdateTimer", $hash, 0) if ($hash->{STATE} eq "disabled"); + elsif( $cmd eq "del" ) { + RemoveInternalTimer( $hash ); + InternalTimer( gettimeofday()+2, "AMAD_GetUpdateTimer", $hash, 0 ) if( $hash->{STATE} eq "disabled" ); $hash->{STATE}='active'; Log3 $name, 3, "AMAD ($name) - enabled"; @@ -123,14 +134,14 @@ sub AMAD_Attr(@) { $attr{$name}{$attrName} = $attrVal; Log3 $name, 3, "AMAD ($name) - $attrName : $attrVal"; } - elsif ($cmd eq "del") { + elsif( $cmd eq "del" ) { } } } - if ($attrName eq "interval") { - if ($cmd eq "set") { - if ($attrVal < 60) { + if( $attrName eq "interval" ) { + if( $cmd eq "set" ) { + if( $attrVal < 60 ) { Log3 $name, 3, "AMAD ($name) - interval too small, please use something > 60 (sec), default is 180 (sec)"; return "interval too small, please use something > 60 (sec), default is 180 (sec)"; } else { @@ -138,35 +149,35 @@ sub AMAD_Attr(@) { Log3 $name, 3, "AMAD ($name) - set interval to $attrVal"; } } - elsif ($cmd eq "del") { + elsif( $cmd eq "del" ) { $hash->{INTERVAL} = 180; Log3 $name, 3, "AMAD ($name) - set interval to default"; } else { - if($cmd eq "set") { + if( $cmd eq "set" ) { $attr{$name}{$attrName} = $attrVal; Log3 $name, 3, "AMAD ($name) - $attrName : $attrVal"; } - elsif ($cmd eq "del") { + elsif( $cmd eq "del" ) { } } } - if ($attrName eq "port") { - if ($cmd eq "set") { + if( $attrName eq "port" ) { + if( $cmd eq "set" ) { $hash->{PORT} = $attrVal; Log3 $name, 3, "AMAD ($name) - set port to $attrVal"; } - elsif ($cmd eq "del") { + elsif( $cmd eq "del" ) { $hash->{PORT} = 8090; Log3 $name, 3, "AMAD ($name) - set port to default"; } else { - if($cmd eq "set") { + if( $cmd eq "set" ) { $attr{$name}{$attrName} = $attrVal; Log3 $name, 3, "AMAD ($name) - $attrName : $attrVal"; } - elsif ($cmd eq "del") { + elsif( $cmd eq "del" ) { } } } @@ -174,34 +185,33 @@ sub AMAD_Attr(@) { return undef; } -sub AMAD_GetUpdateLocal($) -{ - my ($hash) = @_; +sub AMAD_GetUpdateLocal($) { + +my ( $hash ) = @_; my $name = $hash->{NAME}; - - AMAD_RetrieveAutomagicInfo($hash); - + AMAD_RetrieveAutomagicInfo( $hash ) if( ReadingsVal( $name, "deviceState", "online" ) eq "online" && $hash->{STATE} ne "initialized" && AttrVal( $name, "disable", 0 ) ne "1" ); ### deviceState muß von Hand online/offline gesetzt werden z.B. über RESIDENZ Modul + return 1; } -sub AMAD_GetUpdateTimer($) -{ - my ($hash) = @_; +sub AMAD_GetUpdateTimer($) { + + my ( $hash ) = @_; my $name = $hash->{NAME}; - AMAD_RetrieveAutomagicInfo($hash) if (ReadingsVal($name,"deviceState","online") eq "online" && $hash->{STATE} ne "disabled"); # deviceState muß von Hand online/offline gesetzt werden z.B. über RESIDENZ Modul + AMAD_RetrieveAutomagicInfo( $hash ) if( ReadingsVal( $name, "deviceState", "online" ) eq "online" && AttrVal( $name, "disable", 0 ) ne "1" ); ### deviceState muß von Hand online/offline gesetzt werden z.B. über RESIDENZ Modul - InternalTimer(gettimeofday()+$hash->{INTERVAL}, "AMAD_GetUpdateTimer", $hash, 1); + InternalTimer( gettimeofday()+$hash->{INTERVAL}, "AMAD_GetUpdateTimer", $hash, 1 ); Log3 $name, 4, "AMAD ($name) - Call AMAD_GetUpdateTimer"; return 1; } -sub AMAD_Set($$@) -{ - my ($hash, $name, $cmd, @val) = @_; - my $apps = AttrVal("$name","setOpenApp","none"); +sub AMAD_Set($$@) { + + my ( $hash, $name, $cmd, @val ) = @_; + my $apps = AttrVal( $name, "setOpenApp", "none" ); my $list = ""; @@ -209,48 +219,53 @@ sub AMAD_Set($$@) $list .= "ttsMsg "; $list .= "volume:slider,0,1,15 "; $list .= "deviceState:online,offline "; - $list .= "mediaPlayer:play,stop,next,back " if (AttrVal("$name","fhemServerIP","none") ne "none"); - $list .= "screenBrightness:slider,0,1,255 " if (AttrVal("$name","setScreenBrightness","0") eq "1"); + $list .= "mediaPlayer:play,stop,next,back " if( AttrVal( $name, "fhemServerIP", "none" ) ne "none" ); + $list .= "screenBrightness:slider,0,1,255 " if( AttrVal( $name, "setScreenBrightness", "1" ) eq "1" ); $list .= "screen:on,off "; - $list .= "screenOrientation:auto,landscape,portrait " if (AttrVal("$name","setScreenOrientation","0") eq "1"); - $list .= "screenFullscreen:on,off " if (AttrVal("$name","setFullscreen","0") eq "1"); + $list .= "screenOrientation:auto,landscape,portrait " if( AttrVal( $name, "setScreenOrientation", "1" ) eq "1" ); + $list .= "screenFullscreen:on,off " if( AttrVal( $name, "setFullscreen", "1" ) eq "1" ); $list .= "openURL "; - $list .= "openApp:$apps " if (AttrVal("$name","setOpenApp","none") ne "none"); + $list .= "openApp:$apps " if( AttrVal( $name, "setOpenApp", "none" ) ne "none" ); $list .= "nextAlarmTime:time "; $list .= "statusRequest:noArg "; - $list .= "system:reboot " if (AttrVal("$name","root","none") ne "none"); + $list .= "system:reboot " if( AttrVal( $name, "root", "1" ) eq "1" ); - if (lc $cmd eq 'screenmsg' - || lc $cmd eq 'ttsmsg' - || lc $cmd eq 'volume' - || lc $cmd eq 'mediaplayer' - || lc $cmd eq 'devicestate' - || lc $cmd eq 'screenbrightness' - || lc $cmd eq 'screenorientation' - || lc $cmd eq 'screenfullscreen' - || lc $cmd eq 'screen' - || lc $cmd eq 'openurl' - || lc $cmd eq 'openapp' - || lc $cmd eq 'nextalarmtime' - || lc $cmd eq 'system' - || lc $cmd eq 'statusrequest') { + if (lc $cmd eq 'screenmsg' + || lc $cmd eq 'ttsmsg' + || lc $cmd eq 'volume' + || lc $cmd eq 'mediaplayer' + || lc $cmd eq 'devicestate' + || lc $cmd eq 'screenbrightness' + || lc $cmd eq 'screenorientation' + || lc $cmd eq 'screenfullscreen' + || lc $cmd eq 'screen' + || lc $cmd eq 'openurl' + || lc $cmd eq 'openapp' + || lc $cmd eq 'nextalarmtime' + || lc $cmd eq 'system' + || lc $cmd eq 'statusrequest') { - Log3 $name, 5, "AMAD ($name) - set $name $cmd ".join(" ", @val); - return AMAD_SelectSetCmd ($hash, $cmd, @val) if (@val) - || (lc $cmd eq 'statusrequest'); + Log3 $name, 5, "AMAD ($name) - set $name $cmd ".join(" ", @val); + + return "set command only works if STATE not equal initialized, please wait for next interval run" if( $hash->{STATE} eq "initialized"); + + return "Cannot set command, FHEM Device is disabled" if( AttrVal( $name, "disable", "0" ) eq "1" ); + + return AMAD_SelectSetCmd( $hash, $cmd, @val ) if( @val ) + || ( lc $cmd eq 'statusrequest' ); } return "Unknown argument $cmd, bearword as argument or wrong parameter(s), choose one of $list"; } -sub AMAD_RetrieveAutomagicInfo($) -{ +sub AMAD_RetrieveAutomagicInfo($) { + my ($hash) = @_; my $name = $hash->{NAME}; my $host = $hash->{HOST}; my $port = $hash->{PORT}; - my $fhemip = AttrVal("$name","fhemServerIP","none"); + my $fhemip = AttrVal( $name, "fhemServerIP", "none" ); my $url = "http://" . $host . ":" . $port . "/fhem-amad/deviceInfo/"; # Path muß so im Automagic als http request Trigger drin stehen @@ -269,8 +284,8 @@ sub AMAD_RetrieveAutomagicInfo($) Log3 $name, 4, "AMAD ($name) - AMAD_RetrieveAutomagicInfo: calling Host: $host"; } -sub AMAD_RetrieveAutomagicInfoFinished($$$) -{ +sub AMAD_RetrieveAutomagicInfoFinished($$$) { + my ( $param, $err, $data ) = @_; my $hash = $param->{hash}; my $doTrigger = $param->{doTrigger}; @@ -282,62 +297,109 @@ sub AMAD_RetrieveAutomagicInfoFinished($$$) ### Begin Error Handling - if (defined($err)) { - if ($err ne "") { - $hash->{STATE} = $err if ($hash->{STATE} ne "initialized"); + if( $hash->{helper}{infoErrorCounter} > 2 ) { + readingsBeginUpdate( $hash ); + readingsBulkUpdate( $hash, "lastStatusRequestState", "statusRequest_error" ); + + if( ReadingsVal( $name, "flow_Informations", "active" ) eq "inactive" && ReadingsVal( $name, "flow_SetCommands", "active" ) eq "inactive" ) { + readingsBulkUpdate( $hash, "lastStatusRequestError", "AMAD flows on your device inactive, please check your device" ); + + Log3 $name, 5, "AMAD ($name) - CHECK THE LAST ERROR READINGS FOR MORE INFO, DEVICE IS SET OFFLINE"; + + readingsBulkUpdate( $hash, "deviceState", "offline" ); + $hash->{STATE} = "AMAD Flows inactive, device set offline"; + } + elsif( $hash->{helper}{infoErrorCounter} > 4 && $hash->{helper}{setCmdErrorCounter} > 2 ) { + readingsBulkUpdate( $hash, "lastStatusRequestError", "to many errors, check your network or device configuration" ); + + Log3 $name, 4, "AMAD ($name) - To many Errors please check your Network or Device Configuration, DEVICE IS SET OFFLINE"; + + readingsBulkUpdate( $hash, "deviceState", "offline" ); + $hash->{STATE} = "To many Errors, device set offline"; + } + elsif( ReadingsVal( $name, "flow_Informations", "active" ) eq "inactive" ) { + readingsBulkUpdate( $hash, "lastStatusRequestError", "informations flow on your device is inactive, will try to reactivate" ); + + Log3 $name, 4, "AMAD ($name) - Informations Flow on your Device is inactive, will try to reactivate"; + } + elsif($hash->{helper}{infoErrorCounter} > 4 && ReadingsVal( $name, "flow_Informations", "active" ) eq "active" ){ + readingsBulkUpdate( $hash, "lastStatusRequestError", "check automagicApp on your device" ); + + Log3 $name, 4, "AMAD ($name) - Please check the AutomagicAPP on your Device"; + } else { + readingsBulkUpdate( $hash, "lastStatusRequestError", "unknown error, please contact the developer" ); + + Log3 $name, 4, "AMAD ($name) - UNKNOWN ERROR, PLEASE CONTACT THE DEVELOPER, DEVICE DISABLED"; + + $hash->{STATE} = "Unknown Error, device disabled"; + + $attr{$name}{disable} = 1; + } + readingsEndUpdate( $hash, 1 ); + } + + if( defined( $err ) ) { + if( $err ne "" ) { + $hash->{STATE} = $err if( $hash->{STATE} ne "initialized" ); + $hash->{helper}{infoErrorCounter} = ( $hash->{helper}{infoErrorCounter} + 1 ); - readingsBeginUpdate ($hash); - readingsBulkUpdate ($hash,"lastStatusRequestState","statusRequest_error"); + readingsBeginUpdate( $hash ); + readingsBulkUpdate( $hash, "lastStatusRequestState", "statusRequest_error" ); - if ($err =~ /timed out/) { - readingsBulkUpdate ($hash,"lastStatusRequestError","connect to your device is timed out. check network"); + if( $err =~ /timed out/ ) { + readingsBulkUpdate( $hash, "lastStatusRequestError", "connect to your device is timed out. check network "); } - elsif ($err =~ /Keine Route zum Zielrechner/) { - readingsBulkUpdate ($hash,"lastStatusRequestError","no route to target. bad network configuration or network is down"); + elsif( ( $err =~ /Keine Route zum Zielrechner/ ) && $hash->{helper}{infoErrorCounter} > 1 ) { + readingsBulkUpdate( $hash,"lastStatusRequestError", "no route to target. bad network configuration or network is down "); } else { - readingsBulkUpdate ($hash,"lastStatusRequestError","$err"); + readingsBulkUpdate($hash, "lastStatusRequestError", "$err" ); } - readingsEndUpdate ($hash,1); + readingsEndUpdate( $hash, 1 ); - Log3 $name, 5, "AMAD ($name) - AMAD_RetrieveAutomagicInfoFinished: error while requesting AutomagicInfo: $err"; + Log3 $name, 4, "AMAD ($name) - AMAD_RetrieveAutomagicInfoFinished: error while requesting AutomagicInfo: $err"; return; } } - if($data eq "" and exists($param->{code})) { - $hash->{STATE} = $param->{code} if ($hash->{STATE} ne "initialized"); + if( $data eq "" and exists( $param->{code} ) ) { + $hash->{STATE} = $param->{code} if( $hash->{STATE} ne "initialized" ); + $hash->{helper}{infoErrorCounter} = ( $hash->{helper}{infoErrorCounter} + 1 ); - readingsBeginUpdate ($hash); - readingsBulkUpdate ($hash,"lastStatusRequestState","statusRequest_error"); + readingsBeginUpdate( $hash ); + readingsBulkUpdate( $hash, "lastStatusRequestState", "statusRequest_error" ); - if ($param->{code} ne 200) { - readingsBulkUpdate ($hash,"lastStatusRequestError","http Error ".$param->{code}); + if( $param->{code} ne 200 ) { + readingsBulkUpdate( $hash," lastStatusRequestError", "http Error ".$param->{code} ); } - readingsBulkUpdate ($hash,"lastStatusRequestError","empty response, check automagic on your device"); - readingsEndUpdate ($hash,1); + readingsBulkUpdate( $hash, "lastStatusRequestError", "empty response, check automagicApp on your device" ); + readingsEndUpdate( $hash, 1 ); - Log3 $name, 5, "AMAD ($name) - AMAD_RetrieveAutomagicInfoFinished: received http code ".$param->{code}." without any data after requesting AMAD AutomagicInfo"; + Log3 $name, 4, "AMAD ($name) - AMAD_RetrieveAutomagicInfoFinished: received http code ".$param->{code}." without any data after requesting AMAD AutomagicInfo"; return; } - if($data =~ /\Error/i and exists($param->{code})) { - $hash->{STATE} = $param->{code} if ($hash->{STATE} ne "initialized"); + if( ( $data =~ /Error/i ) and exists( $param->{code} ) ) { + $hash->{STATE} = $param->{code} if( $hash->{STATE} ne "initialized" ); + $hash->{helper}{infoErrorCounter} = ( $hash->{helper}{infoErrorCounter} + 1 ); - readingsBeginUpdate($hash); - readingsBulkUpdate ($hash,"lastStatusRequestState","statusRequest_error"); + readingsBeginUpdate( $hash ); + readingsBulkUpdate( $hash, "lastStatusRequestState", "statusRequest_error" ); - if ($param->{code} eq 404) { - readingsBulkUpdate ($hash,"lastStatusRequestError","automagic information flow is inactive on your device!"); + if( $param->{code} eq 404 && ReadingsVal( $name, "flow_Informations", "inactive" ) eq "inactive" ) { + readingsBulkUpdate( $hash, "lastStatusRequestError", "check the informations flow on your device" ); + } + elsif( $param->{code} eq 404 && ReadingsVal( $name, "flow_Informations", "active" ) eq "active" ) { + readingsBulkUpdate( $hash, "lastStatusRequestError", "check the automagicApp on your device" ); } else { - readingsBulkUpdate ($hash,"lastStatusRequestError","http error ".$param->{code}); + readingsBulkUpdate( $hash, "lastStatusRequestError", "http error ".$param->{code} ); } - readingsEndUpdate ($hash,1); + readingsEndUpdate( $hash, 1 ); - Log3 $name, 5, "AMAD ($name) - AMAD_RetrieveAutomagicInfoFinished: received http code ".$param->{code}." receive Error after requesting AMAD AutomagicInfo"; + Log3 $name, 4, "AMAD ($name) - AMAD_RetrieveAutomagicInfoFinished: received http code ".$param->{code}." receive Error after requesting AMAD AutomagicInfo"; return; } @@ -347,48 +409,43 @@ sub AMAD_RetrieveAutomagicInfoFinished($$$) ### Begin Response Processing - $hash->{STATE} = "active" if ($hash->{STATE} eq "initialized" || $hash->{STATE} ne "active"); + $hash->{STATE} = "active" if( $hash->{STATE} eq "initialized" || $hash->{STATE} ne "active" ); + $hash->{helper}{infoErrorCounter} = 0; - my @valuestring = split('@@@@', $data); + my @valuestring = split( '@@@@', $data ); my %buffer; - foreach (@valuestring) { - my @values = split('@@', $_); + foreach( @valuestring ) { + my @values = split( '@@' , $_ ); $buffer{$values[0]} = $values[1]; } - readingsBeginUpdate($hash); + readingsBeginUpdate( $hash ); my $t; my $v; - while (($t, $v) = each %buffer) { + while( ( $t, $v ) = each %buffer ) { $v =~ s/null//g; - readingsBulkUpdate($hash, $t, $v) if (defined($v)); + readingsBulkUpdate( $hash, $t, $v ) if( defined( $v ) ); } - readingsBulkUpdate ($hash,"lastStatusRequestState","statusRequest_done"); + readingsBulkUpdate( $hash, "lastStatusRequestState", "statusRequest_done" ); - readingsEndUpdate($hash, 1); + readingsEndUpdate( $hash, 1 ); ### End Response Processing - $hash->{STATE} = "active" if ($hash->{STATE} eq "initialized"); + $hash->{STATE} = "active" if( $hash->{STATE} eq "initialized" ); return undef; } -sub AMAD_HTTP_POST($$) -{ - my ($hash, $url) = @_; +sub AMAD_HTTP_POST($$) { + + my ( $hash, $url ) = @_; my $name = $hash->{NAME}; my $state = $hash->{STATE}; - if ($hash->{STATE} eq "initialized") - { - Log3 $name, 3, "AMAD ($name) - AMAD_HTTP_POST: set command only works if STATE active, please wait for next interval run"; - return "set command only works if STATE not equal initialized, please wait for next interval run"; - } - $hash->{STATE} = "Send HTTP POST"; HttpUtils_NonblockingGet( @@ -408,30 +465,71 @@ sub AMAD_HTTP_POST($$) return undef; } -sub AMAD_HTTP_POSTerrorHandling($$$) -{ +sub AMAD_HTTP_POSTerrorHandling($$$) { + my ( $param, $err, $data ) = @_; my $hash = $param->{hash}; my $name = $hash->{NAME}; ### Begin Error Handling - if (defined($err)) { - if ($err ne "") { - $hash->{STATE} = $err if ($hash->{STATE} ne "initialized"); + if($hash->{helper}{setCmdErrorCounter} > 2 ) { + readingsBeginUpdate( $hash ); + readingsBulkUpdate( $hash, "lastSetCommandState", "statusRequest_error" ); + + if( ReadingsVal( $name, "flow_Informations", "active" ) eq "inactive" && ReadingsVal( $name, "flow_SetCommands", "active" ) eq "inactive" ) { + readingsBulkUpdate( $hash, "lastSetCommandError", "AMAD flows on your device inactive, please check your device" ); + Log3 $name, 5, "AMAD ($name) - CHECK THE LAST ERROR READINGS FOR MORE INFO, DEVICE IS SET OFFLINE"; + + readingsBulkUpdate( $hash, "deviceState", "offline" ); + $hash->{STATE} = "AMAD Flows inactive, device set offline"; + } + elsif( $hash->{helper}{infoErrorCounter} > 4 && $hash->{helper}{setCmdErrorCounter} > 2 ) { + readingsBulkUpdate($hash, "lastSetCommandError", "to many errors, check your network or device configuration" ); + + Log3 $name, 4, "AMAD ($name) - To many Errors please check your Network or Device Configuration, DEVICE IS SET OFFLINE"; + + readingsBulkUpdate( $hash, "deviceState", "offline" ); + $hash->{STATE} = "To many Errors, device set offline"; + } + elsif( ReadingsVal( $name, "flow_SetCommands", "active" ) eq "inactive" ) { + readingsBulkUpdate( $hash, "lastSetCommandError", "setCommands flow on your device is inactive, will try to reactivate" ); + + Log3 $name, 4, "AMAD ($name) - Flow SetCommands on your Device is inactive, will try to reactivate"; + } + elsif( $hash->{helper}{setCmdErrorCounter} > 4 && ReadingsVal( $name, "flow_SetCommands", "active" ) eq "active" ){ + readingsBulkUpdate( $hash, "lastSetCommandError", "check automagicApp on your device" ); + + Log3 $name, 4, "AMAD ($name) - Please check the AutomagicAPP on your Device"; + } else { + readingsBulkUpdate( $hash, "lastSetCommandError", "unknown error, please contact the developer" ); + + Log3 $name, 4, "AMAD ($name) - UNKNOWN ERROR, PLEASE CONTACT THE DEVELOPER, DEVICE DISABLED"; + + $hash->{STATE} = "Unknown Error, device disabled"; + + $attr{$name}{disable} = 1; + } + readingsEndUpdate( $hash, 1 ); + } + + if( defined( $err ) ) { + if( $err ne "" ) { + $hash->{STATE} = $err if( $hash->{STATE} ne "initialized" ); + $hash->{helper}{setCmdErrorCounter} = ($hash->{helper}{setCmdErrorCounter} + 1); - readingsBeginUpdate ($hash); - readingsBulkUpdate ($hash,"lastSetCommandState","cmd_error"); + readingsBeginUpdate( $hash ); + readingsBulkUpdate( $hash, "lastSetCommandState", "cmd_error" ); - if ($err =~ /timed out/) { - readingsBulkUpdate ($hash,"lastSetCommandError","connect to your device is timed out. check network"); + if( $err =~ /timed out/ ) { + readingsBulkUpdate( $hash, "lastSetCommandError", "connect to your device is timed out. check network" ); } - elsif ($err =~ /Keine Route zum Zielrechner/) { - readingsBulkUpdate ($hash,"lastSetCommandError","no route to target. bad network configuration or network is down"); + elsif( $err =~ /Keine Route zum Zielrechner/ ) { + readingsBulkUpdate( $hash, "lastSetCommandError", "no route to target. bad network configuration or network is down" ); } else { - readingsBulkUpdate ($hash,"lastSetCommandError","$err"); + readingsBulkUpdate( $hash, "lastSetCommandError", "$err" ); } - readingsEndUpdate ($hash,1); + readingsEndUpdate( $hash, 1 ); Log3 $name, 5, "AMAD ($name) - AMAD_HTTP_POST: error while POST Command: $err"; @@ -439,54 +537,56 @@ sub AMAD_HTTP_POSTerrorHandling($$$) } } - if($data eq "" and exists($param->{code})) { - $hash->{STATE} = $param->{code} if ($hash->{STATE} ne "initialized"); + if( $data eq "" and exists( $param->{code} ) ) { + $hash->{STATE} = $param->{code} if( $hash->{STATE} ne "initialized" ); + $hash->{helper}{setCmdErrorCounter} = ( $hash->{helper}{setCmdErrorCounter} + 1 ); - readingsBeginUpdate ($hash); + readingsBeginUpdate( $hash ); - if ($param->{code} ne 200) { - readingsBulkUpdate ($hash,"lastSetCommandState","cmd_error"); - readingsBulkUpdate ($hash,"lastSetCommandError","http Error ".$param->{code}); + if( $param->{code} ne 200 ) { + readingsBulkUpdate($hash, "lastSetCommandState", "cmd_error" ); + readingsBulkUpdate($hash, "lastSetCommandError", "http Error ".$param->{code} ); } - readingsBulkUpdate ($hash,"lastSetCommandState","cmd_done"); - readingsEndUpdate ($hash,1); + readingsBulkUpdate( $hash, "lastSetCommandState" ,"cmd_done" ); + readingsEndUpdate( $hash, 1 ); Log3 $name, 5, "AMAD ($name) - AMAD_HTTP_POST: received http code ".$param->{code}; Log3 $name, 4, "AMAD ($name) - Starte Update GetUpdateLocal"; - AMAD_GetUpdateLocal($hash); + AMAD_GetUpdateLocal( $hash ); return; } - if($data =~ /Error/i and exists($param->{code})) { - $hash->{STATE} = $param->{code} if ($hash->{STATE} ne "initialized"); + if( ( $data =~ /Error/i ) and exists( $param->{code} ) ) { + $hash->{STATE} = $param->{code} if( $hash->{STATE} ne "initialized" ); + $hash->{helper}{setCmdErrorCounter} = ( $hash->{helper}{setCmdErrorCounter} + 1 ); - readingsBeginUpdate($hash); - readingsBulkUpdate ($hash,"lastSetCommandState","cmd_error"); + readingsBeginUpdate( $hash ); + readingsBulkUpdate( $hash, "lastSetCommandState", "cmd_error" ); - if ($param->{code} eq 404) { - readingsBulkUpdate ($hash,"lastSetCommandError","automagic setcommand flow is inactive on your device!"); + if( $param->{code} eq 404 ) { + readingsBulkUpdate( $hash, "lastSetCommandError", "setCommands flow is inactive on your device!" ); } else { - readingsBulkUpdate ($hash,"lastSetCommandError","http error ".$param->{code}); + readingsBulkUpdate( $hash, "lastSetCommandError", "http error ".$param->{code} ); } } - readingsEndUpdate ($hash,1); + readingsEndUpdate( $hash, 1 ); ### End Error Handling return undef; } -sub AMAD_SelectSetCmd($$@) -{ - my ($hash, $cmd, @data) = @_; +sub AMAD_SelectSetCmd($$@) { + + my ( $hash, $cmd, @data ) = @_; my $name = $hash->{NAME}; my $host = $hash->{HOST}; my $port = $hash->{PORT}; - if (lc $cmd eq 'screenmsg') { - my $msg = join(" ", @data); + if( lc $cmd eq 'screenmsg' ) { + my $msg = join( " ", @data ); $msg =~ s/%/%25/g; $msg =~ s/\s/%20/g; @@ -494,116 +594,116 @@ sub AMAD_SelectSetCmd($$@) my $url = "http://" . $host . ":" . $port . "/fhem-amad/setCommands/screenMsg?message=$msg"; Log3 $name, 4, "AMAD ($name) - Sub AMAD_SetScreenMsg"; - return AMAD_HTTP_POST ($hash,$url); + return AMAD_HTTP_POST( $hash,$url ); } - elsif (lc $cmd eq 'ttsmsg') { - my $msg = join(" ", @data); + elsif( lc $cmd eq 'ttsmsg' ) { + my $msg = join( " ", @data ); $msg =~ s/%/%25/g; $msg =~ s/\s/%20/g; my $url = "http://" . $host . ":" . $port . "/fhem-amad/setCommands/ttsMsg?message=$msg"; - return AMAD_HTTP_POST ($hash,$url); + return AMAD_HTTP_POST( $hash,$url ); } - elsif (lc $cmd eq 'volume') { - my $vol = join(" ", @data); + elsif( lc $cmd eq 'volume' ) { + my $vol = join( " ", @data ); my $url = "http://" . $host . ":" . $port . "/fhem-amad/setCommands/setVolume?volume=$vol"; - readingsSingleUpdate ($hash,$cmd,$vol,1); + readingsSingleUpdate( $hash, $cmd, $vol, 1 ); - return AMAD_HTTP_POST ($hash,$url); + return AMAD_HTTP_POST( $hash, $url ); } - elsif (lc $cmd eq 'mediaplayer') { - my $btn = join(" ", @data); + elsif( lc $cmd eq 'mediaplayer' ) { + my $btn = join( " ", @data ); my $url = "http://" . $host . ":" . $port . "/fhem-amad/setCommands/mediaPlayer?button=$btn"; - return AMAD_HTTP_POST ($hash,$url); + return AMAD_HTTP_POST( $hash,$url ); } - elsif (lc $cmd eq 'devicestate') { - my $v = join(" ", @data); + elsif( lc $cmd eq 'devicestate' ) { + my $v = join( " ", @data ); - readingsSingleUpdate ($hash,$cmd,$v,1); + readingsSingleUpdate( $hash, $cmd, $v, 1 ); return undef; } - elsif (lc $cmd eq 'screenbrightness') { - my $bri = join(" ", @data); + elsif( lc $cmd eq 'screenbrightness' ) { + my $bri = join( " ", @data ); my $url = "http://" . $host . ":" . $port . "/fhem-amad/setCommands/setBrightness?brightness=$bri"; - return AMAD_HTTP_POST ($hash,$url); + return AMAD_HTTP_POST( $hash,$url ); } - elsif (lc $cmd eq 'screen') { - my $mod = join(" ", @data); + elsif( lc $cmd eq 'screen' ) { + my $mod = join( " ", @data ); my $url = "http://" . $host . ":" . $port . "/fhem-amad/setCommands/setScreenOnOff?screen=$mod"; - return AMAD_HTTP_POST ($hash,$url); + return AMAD_HTTP_POST( $hash,$url ); } - elsif (lc $cmd eq 'screenorientation') { - my $mod = join(" ", @data); + elsif( lc $cmd eq 'screenorientation' ) { + my $mod = join( " ", @data ); my $url = "http://" . $host . ":" . $port . "/fhem-amad/setCommands/setScreenOrientation?orientation=$mod"; - return AMAD_HTTP_POST ($hash,$url); + return AMAD_HTTP_POST( $hash,$url ); } - elsif (lc $cmd eq 'screenfullscreen') { - my $mod = join(" ", @data); + elsif( lc $cmd eq 'screenfullscreen' ) { + my $mod = join( " ", @data ); my $url = "http://" . $host . ":" . $port . "/fhem-amad/setCommands/setScreenFullscreen?fullscreen=$mod"; - readingsSingleUpdate ($hash,$cmd,$mod,1); + readingsSingleUpdate( $hash, $cmd, $mod, 1 ); - return AMAD_HTTP_POST ($hash,$url); + return AMAD_HTTP_POST( $hash, $url ); } - elsif (lc $cmd eq 'openurl') { - my $openurl = join(" ", @data); + elsif( lc $cmd eq 'openurl' ) { + my $openurl = join( " ", @data ); my $url = "http://" . $host . ":" . $port . "/fhem-amad/setCommands/openURL?url=$openurl"; - return AMAD_HTTP_POST ($hash,$url); + return AMAD_HTTP_POST( $hash, $url ); } elsif (lc $cmd eq 'nextalarmtime') { - my $alarmTime = join(" ", @data); - my @alarm = split(":", $alarmTime); + my $alarmTime = join( " ", @data ); + my @alarm = split( ":", $alarmTime ); my $url = "http://" . $host . ":" . $port . "/fhem-amad/setCommands/setAlarm?hour=".$alarm[0]."&minute=".$alarm[1]; - return AMAD_HTTP_POST ($hash,$url); + return AMAD_HTTP_POST( $hash, $url ); } - elsif (lc $cmd eq 'statusrequest') { - AMAD_GetUpdateLocal($hash); + elsif( lc $cmd eq 'statusrequest' ) { + AMAD_GetUpdateLocal( $hash ); return undef; } - elsif (lc $cmd eq 'openapp') { - my $app = join(" ", @data); + elsif( lc $cmd eq 'openapp' ) { + my $app = join( " ", @data ); my $url = "http://" . $host . ":" . $port . "/fhem-amad/setCommands/openApp?app=$app"; - return AMAD_HTTP_POST ($hash,$url); + return AMAD_HTTP_POST( $hash,$url ); } - elsif (lc $cmd eq 'system') { - my $systemcmd = join(" ", @data); + elsif( lc $cmd eq 'system' ) { + my $systemcmd = join( " ", @data ); my $url = "http://" . $host . ":" . $port . "/fhem-amad/setCommands/systemcommand?syscmd=$systemcmd"; - return AMAD_HTTP_POST ($hash,$url); + return AMAD_HTTP_POST( $hash,$url ); } return undef; @@ -635,6 +735,8 @@ sub AMAD_SelectSetCmd($$@) Im Auslieferiungszustand werden folgende Zustände dargestellt:
  • Zustand von Automagic auf dem Gerät
  • +
  • Bluetooth An/Aus
  • +
  • verbundene Bluetoothgeräte
  • aktuell abgespieltes Musikalbum des verwendeten Mediaplayers
  • aktuell abgespielter Musikinterpret des verwendeten Mediaplayers
  • aktuell abgespielter Musiktitel des verwendeten Mediaplayers
  • @@ -653,7 +755,7 @@ sub AMAD_SelectSetCmd($$@)

Mit etwas Einarbeitung können jegliche Informationen welche Automagic bereit stellt in FHEM angezeigt werden. Hierzu bedarf es lediglich - einer kleinen Anpassung des "Information" Flows + einer kleinen Anpassung des "Informations" Flows

Das Modul gibt Dir auch die Möglichkeit Deine Androidgeräte zu steuern. So können folgende Aktionen durchgeführt werden.
    @@ -678,11 +780,8 @@ sub AMAD_SelectSetCmd($$@)

    Wie genau verwendet man nun AMAD?
      -
    • Installiert Euch die App "Automagic Premium" aus dem App Store oder die Testversion von hier
    • -
    • ladet Euch das AMAD Modul und die Flowfiles von GitHub runter
    • -
    • installiert die zwei Flows und aktiviert erstmal nur den "Information" Flow, eventuell bei den - FlowUpdates mal schauen ob es was neueres gibt und den entsprechenden Flow auf dem Gerät löschen und den neuen Flow von GitHub installieren
    • -
    • kopiert die Moduldatei 74_AMAD.pm nach $FHEMPATH/FHEM. Geht auf die FHEM Frontendseite und gebt dort in der Kommandozeile reload 74_AMAD.pm ein
    • +
    • installiert Euch die App "Automagic Premium" aus dem App Store oder die Testversion von hier
    • +
    • installiert das Flowset 74_AMADautomagicFlows$VERSION.xml aus dem Ordner $INSTALLFHEM/FHEM/lib/ auf Eurem Androidgerät und aktiviert erstmal nur den "Informations" Flow.

    Nun müsst Ihr nur noch ein Device in FHEM anlegen. @@ -690,31 +789,34 @@ sub AMAD_SelectSetCmd($$@) Define

      - define <name> AMAD <IP-ADRESSE> <PORT> <INTERVAL> + define <name> AMAD <IP-ADRESSE>

      Beispiel:

        - define WandTabletWohnzimmer AMAD 192.168.0.23 8090 180
        + define WandTabletWohnzimmer AMAD 192.168.0.23

      - Diese Anweisung erstellt ein neues AMAD-Device. Die Parameter IP-ADRESSE und PORT legen die IP Adresse des Android Gerätes - sowie den, in den Flows des Trigger HTTP Request, angegebenen Port fest.
      INTERVAL ist der Zeitabstand in dem ein erneuter Informationsabruf stattfinden soll. Alle x Sekunden. - Bei mir hat sich 180 gut bewährt, also alle 3 Minuten
      - Bitte gebt für sofortige Erfolge als Port 8090 ein, das ist der Port der in den mitgelieferten Automagic Flows als Trigger Port eingetragen ist.
      - Dieser kann später mit Erfahrung auch geändert werden
      + Diese Anweisung erstellt ein neues AMAD-Device. Der Parameter <IP-ADRESSE< legt die IP Adresse des Android Gerätes fest.
      + Das Standard Abfrageinterval ist 180 Sekunden und kann über das Attribut intervall geändert werden. Wer den Port ändern möchte, kann dies über + das Attribut port tun. Ihr solltet aber wissen was Ihr tut, da dieser Port im HTTP Response Trigger der beiden Flows eingestellt ist. Demzufolge muß dieser dort + auch verädert werden.


    - Fertig! Nach anlegen des Devices sollten bereits die ersten Readings reinkommen. + Fertig! Nach anlegen der Geräteinstanz sollten nach spätestens 3 Minuten bereits die ersten Readings reinkommen.

    Readings
    • automagicState - Statusmeldungen von der AutomagicApp
    • +
    • bluetooth on/off - ist auf dem Gerät Bluetooth an oder aus
    • +
    • connectedBTdevices - eine Lieste der verbundenen Gerät
    • currentMusicAlbum - aktuell abgespieltes Musikalbum des verwendeten Mediaplayers
    • currentMusicArtist - aktuell abgespielter Musikinterpret des verwendeten Mediaplayers
    • currentMusicTrack - aktuell abgespielter Musiktitel des verwendeten Mediaplayers
    • deviceState - Status des Androidgerätes, muss selbst mit setreading gesetzt werden z.B. über die Anwesenheitskontrolle.
      Ist Offline gesetzt, wird der Intervall zum Informationsabruf aus gesetzt.
    • +
    • flow_SetCommands active/inactive - gibt den Status des SetCommands Flow wieder
    • +
    • flow_informations active/inactive - gibt den Status des Informations Flow wieder
    • lastSetCommandError - letzte Fehlermeldung vom set Befehl
    • lastSetCommandState - letzter Status vom set Befehl, Befehl erfolgreich/nicht erfolgreich gesendet
    • lastStatusRequestError - letzte Fehlermeldung vom statusRequest Befehl
    • @@ -754,7 +856,7 @@ sub AMAD_SelectSetCmd($$@)
    • mediaPlayer - steuert den Standard Mediaplayer. play, stop, Titel zürück, Titel vor. Attribut fhemServerIP
    • openApp - öffnet eine ausgewählte App. Attribut setOpenApp
    • screenBrightness - setzt die Bildschirmhelligkeit, von 0-255 Attribut setScreenBrightness
    • - Wenn Ihr das "set screenBrightness" verwenden wollt, muss eine kleine Anpassung im Flow SetCommand vorgenommen werden. Öffnet die Aktion (eines der Vierecke ganz ganz unten) + Wenn Ihr das "set screenBrightness" verwenden wollt, muss eine kleine Anpassung im Flow SetCommands vorgenommen werden. Öffnet die Aktion (eines der Vierecke ganz ganz unten) SetzeSystemeinstellung:System und macht einen Haken bei "Ich habe die Einstellungen überprüft, ich weiss was ich tue".
    • screenFullscreen - Schaltet den Vollbildmodus on/off. Attribut setFullscreen
    • screenOrientation - Schaltet die Bildschirmausrichtung Auto/Landscape/Portait. Attribut setScreenOrientation
    • @@ -769,7 +871,8 @@ sub AMAD_SelectSetCmd($$@) STATE
      • initialized - Ist der Status kurz nach einem define..
      • -
      • activ - Das Modul ist im aktiven Status.
      • +
      • active - die Geräteinstanz ist im aktiven Status.
      • +
      • disabled - die Geräteinstanz wurde über das Attribut disable deaktiviert



      Anwendungsbeispiele: diff --git a/Automagic_FHEM-AMAD_FlowsSet_v0.5.3.xml b/74_AMADautomagicFlows0.5.9.xml similarity index 57% rename from Automagic_FHEM-AMAD_FlowsSet_v0.5.3.xml rename to 74_AMADautomagicFlows0.5.9.xml index d970332..d2cdf83 100644 --- a/Automagic_FHEM-AMAD_FlowsSet_v0.5.3.xml +++ b/74_AMADautomagicFlows0.5.9.xml @@ -18,16 +18,16 @@ global_album = getString("album"); false - true - HTTP Request: /fhem-amad/deviceInfo/, Port 8090 + false + HTTP Request: /fhem-amad/deviceInfo/ true /fhem-amad/deviceInfo/ 8090 true - true - HTTP Request: /fhem-amad/setCommands/*, Port 8090 + false + HTTP Request: /fhem-amad/setCommands/* true /fhem-amad/setCommands/* 8090 @@ -79,6 +79,17 @@ global_album = getString("album"); false false + + true + Bluetooth eingeschaltet + + + true + Bluetooth Gerät verbunden: Beliebiges Geräte + true + + + true Display automatisch drehen eingeschaltet @@ -242,6 +253,11 @@ global_album = getString("album"); Expression: trigger == "com.android.music.metachanged" trigger == "com.android.music.metachanged" + + true + Expression: trigger == "HTTP Request: /fhem-amad/setCommands/*" + trigger == "HTTP Request: /fhem-amad/setCommands/*" + false Expression: ttsMsg" @@ -252,6 +268,16 @@ global_album = getString("album"); Expression: tuneinradio param_app == "tuneinradio" + + true + Flow Aktiv: Informations + Informations + + + true + Flow Aktiv: SetCommands + SetCommands + true Musik Aktiv @@ -381,8 +407,15 @@ global_album = getString("album"); false - HTTP Response - powerLevel@@{battery_percentage}@@@@powerPlugged@@{battery_plugged}@@@@volumeMusikBluetooth@@{volumeMusikBluetooth}@@@@volumeMusikSpeaker@@{volumeMusikSpeaker}@@@@screenBrightness@@{screenBrightness}@@@@nextAlarmTime@@{next_alarmtime}@@@@nextAlarmDay@@{next_alarmday}@@@@screen@@{screen_state}@@@@automagicState@@{notification_text}@@@@screenOrientation@@{screen_orientation}@@@@currentMusicTrack@@{global_track}@@@@currentMusicAlbum@@{global_album}@@@@currentMusicArtist@@{global_artist} + HTTP Response Information + powerLevel@@{battery_percentage}@@@@powerPlugged@@{battery_plugged}@@@@volumeMusikBluetooth@@{volumeMusikBluetooth}@@@@volumeMusikSpeaker@@{volumeMusikSpeaker}@@@@screenBrightness@@{screenBrightness}@@@@nextAlarmTime@@{next_alarmtime}@@@@nextAlarmDay@@{next_alarmday}@@@@screen@@{screen_state}@@@@automagicState@@{notification_text}@@@@screenOrientation@@{screen_orientation}@@@@currentMusicTrack@@{global_track}@@@@currentMusicAlbum@@{global_album}@@@@currentMusicArtist@@{global_artist}@@@@bluetooth@@{bluetooth_state}@@@@connectedBTdevices@@{connected_devices_names}@@@@flow_SetCommands@@{setCommandFlow_state} + true + text/plain + + + false + HTTP Response SetCommand + flow_informations@@{informationFlow_state}@@@@ true text/plain @@ -452,6 +485,16 @@ global_album = getString("album"); 120s true + + true + Script: bluetooth_state = "off" + + + + true + Script: bluetooth_state = "on" + + true Script: global_artist = "no soundplayer activ"; global_track = "no soundplayer activ"; global_album = "no soundplayer activ"; @@ -465,6 +508,16 @@ global_album = "no soundplayer activ"; + + true + Script: informationFlow_state = "aktiv" + + + + true + Script: informationFlow_state = "inaktiv" + + true Script: next_alarmday = "{next_alarm,dateformat,c}" @@ -505,6 +558,16 @@ global_fhemdevice = {header_fhemdevice} Script: screen_state = "on" + + true + Script: setCommandFlow_state = "aktiv" + + + + true + Script: setCommandFlow_state = "inaktiv" + + true Setze Alarm: um {param_hour}:{param_minute} @@ -530,6 +593,20 @@ global_fhemdevice = {header_fhemdevice} PORTRAIT false + + true + Setze Flow Status: Aktivieren Informations + true + Informations + + + + true + Setze Flow Status: Aktivieren SetCommands + true + SetCommands + + true Setze Systemeinstellung: System screen_brightness auf {param_brightness} @@ -577,207 +654,241 @@ global_fhemdevice = {header_fhemdevice} Informations - FHEM Info / Steuerung über AMAD Modul + FHEM Info / Steuerung über AMAD Modul v0.6 true STOP 120 - Script: next_alarmday = "{next_alarm,dateformat,c}" - Display eingeschaltet - Script: screen_state = "on" - Script: screen_orientation = "portrait" - Script: screen_orientation = "landscape" - Display Orientierung: Portrait - Initialisiere Variable Systemeinstellung: volumeMusikBluetooth - Initialisiere Variable Systemeinstellung: volumeMusikSpeaker - Initialisiere Variable Systemeinstellung: screenBrightness - Initialisiere Variable Nächster Alarm: next_alarm - Display automatisch drehen eingeschaltet - Script: next_alarmtime = "{next_alarm,dateformat,HH:mm}" - Expression: trigger == "com.android.music.metachanged" - Script: screen_state = "off" - Akku Ladestand: grösser als 0% - Script: global_fhemip = {header_fhemip} global_fhemdevice = {header_fhemdevice} - Expression: global_fhemip == "null" - Expression: global_fhemdevice == "null" - Musik Aktiv - - HTTP Request: /fhem-amad/deviceInfo/, Port 8090 + Benachrichtigung in Statusbar angezeigt: Automagic + Script: notification_text = "no supported from your device" + Script: screen_orientation = "auto" + Display automatisch drehen eingeschaltet + Script: screen_orientation = "portrait" + Display Orientierung: Portrait + Script: screen_orientation = "landscape" + Bluetooth eingeschaltet + Script: bluetooth_state = "on" + Bluetooth Gerät verbunden: Beliebiges Geräte + Script: bluetooth_state = "off" + Script: screen_state = "off" + Script: screen_state = "on" + Display eingeschaltet + Script: next_alarmtime = "{next_alarm,dateformat,HH:mm}" + Initialisiere Variable Nächster Alarm: next_alarm + Script: next_alarmday = "{next_alarm,dateformat,c}" + Initialisiere Variable Systemeinstellung: screenBrightness + Initialisiere Variable Systemeinstellung: volumeMusikSpeaker + Initialisiere Variable Systemeinstellung: volumeMusikBluetooth + HTTP Request: GET http://{global_fhemip}:8085/fhem?cmd=set%20{global_fhemdevice}%20statusRequest speichern in response + Expression: global_fhemip == "null" + Expression: global_fhemdevice == "null" + Script: global_fhemip = {header_fhemip} global_fhemdevice = {header_fhemdevice} + Pause: 2s (Gerät wach halten) + Musik Aktiv + Script: global_artist = "no soundplayer activ"; global_track = "no soundplayer activ"; global_album = "no soundplayer activ"; + Akku Ladestand: grösser als 0% + Flow Aktiv: SetCommands + Script: setCommandFlow_state = "aktiv" + Expression: trigger == "com.android.music.metachanged" + com.android.music.metachanged + HTTP Request: /fhem-amad/deviceInfo/ - Pause: 2s (Gerät wach halten) - Script: global_artist = "no soundplayer activ"; global_track = "no soundplayer activ"; global_album = "no soundplayer activ"; - Script: screen_orientation = "auto" - HTTP Response - Benachrichtigung in Statusbar angezeigt: Automagic - Script: notification_text = "no supported from your device" - HTTP Request: GET http://{global_fhemip}:8085/fhem?cmd=set%20{global_fhemdevice}%20statusRequest speichern in response - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + Script: setCommandFlow_state = "inaktiv" + Setze Flow Status: Aktivieren SetCommands + HTTP Response Information + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SetCommands - FHEM Info / Steuerung über AMAD Modul + FHEM Info / Steuerung über AMAD Modul v0.6 true QUEUE 120 - Expression: param_screen=="off" - Expression: param_screen=="on" - Audio Player steuern: Medienknopf Stopp (Google Play Musik) - Expression: param_button == "play" - Audio Player steuern: Medienknopf Play (Google Play Musik) - Audio Player steuern: Medienknopf Weiter (Google Play Musik) - Expression: param_button == "next" - Audio Player steuern: Medienknopf Zurück (Google Play Musik) - Sprachausgabe: {param_message} - Expression: param_button == "stop" - Expression: param_button == "back" - Expression: param_orientation == "portrait" - Expression: param_fullscreen == "on" - Expression: param_fullscreen == "off" - Setze Vollbild Modus: Auf Default zurücksetzen - App Starten: tuneinradio - Expression: setVolume" - Expression: ttsMsg" - Expression: setBrightness" - Expression: setAlarm" - Expression: screenMsg" - Expression: openURL" - Expression: mediaPlayer" - Expression: setScreenFullscreen" - Expression: setScreenOrientation" - Lautstärken setzen - Setze Systemeinstellung: System screen_brightness auf {param_brightness} - Setze Alarm: um {param_hour}:{param_minute} - URL in Browser öffnen: {param_url} (mit Chrome) - Benachrichtigung auf Bildschirm: {param_message} (lange) - Setze Vollbild Modus: Navigation nicht anzeigen - Gerät sperren - Schalte Display ein: Hell für 120s - App Starten: App3 - App Starten: App4 - App Starten: App5 - Expression: App3 - Expression: App4 - Expression: App5 - App Task läuft: App3 (neuster) - App Task läuft: App4 (neuster) - App Task läuft: App5 (neuster) - Expression: openApp" - Expression: setScreenOnOff" - Expression: System Command" - App Starten: PlayMusic - Expression: Reboot - - HTTP Request: /fhem-amad/setCommands/*, Port 8090 + Expression: param_screen=="on" + Sprachausgabe: {param_message} + Expression: ttsMsg" + Expression: setBrightness" + Expression: setAlarm" + Expression: screenMsg" + Expression: openURL" + Setze Alarm: um {param_hour}:{param_minute} + URL in Browser öffnen: {param_url} (mit Chrome) + Benachrichtigung auf Bildschirm: {param_message} (lange) + Schalte Display ein: Hell für 120s + Expression: setScreenFullscreen" + Expression: param_orientation == "auto" + Setze Display Orientierung: Portrait + Setze Display Orientierung: Landscape + Expression: param_orientation == "landscape" + Expression: param_orientation == "portrait" + Expression: param_fullscreen == "off" + Setze Vollbild Modus: Navigation nicht anzeigen + Expression: param_fullscreen == "on" + Setze Vollbild Modus: Auf Default zurücksetzen + Audio Player steuern: Medienknopf Zurück (Google Play Musik) + Expression: param_button == "back" + Display automatisch drehen ein-/ausschalten: Aus + Expression: param_button == "next" + Setze Display Orientierung: Auf Default zurücksetzen + Display automatisch drehen ein-/ausschalten: Ein + Audio Player steuern: Medienknopf Play (Google Play Musik) + Expression: param_button == "play" + Expression: mediaPlayer" + Audio Player steuern: Medienknopf Weiter (Google Play Musik) + Audio Player steuern: Medienknopf Stopp (Google Play Musik) + Expression: param_button == "stop" + Expression: param_screen=="off" + Gerät sperren + Expression: setScreenOnOff" + Expression: setVolume" + Lautstärken setzen + App Task läuft: App5 (neuster) + Expression: App5 + Expression: App4 + App Task läuft: App3 (neuster) + Expression: App3 + App Starten: App3 + App Starten: App4 + App Task läuft: App4 (neuster) + Expression: tuneinradio + App Task läuft: tuneinradio (neuster) + App Starten: tuneinradio + App Starten: App5 + App Task läuft: gplay (neuster) + Expression: gplay + App Starten: PlayMusic + Expression: openApp" + Expression: System Command" + Expression: setScreenOrientation" + Expression: Reboot + Neustart + Flow Aktiv: Informations + Expression: trigger == "HTTP Request: /fhem-amad/setCommands/*" + Script: informationFlow_state = "aktiv" + Script: informationFlow_state = "inaktiv" + + HTTP Request: /fhem-amad/deviceInfo/ + HTTP Request: /fhem-amad/setCommands/* - Neustart - Setze Display Orientierung: Portrait - Setze Display Orientierung: Landscape - Expression: param_orientation == "landscape" - Display automatisch drehen ein-/ausschalten: Aus - Setze Display Orientierung: Auf Default zurücksetzen - Display automatisch drehen ein-/ausschalten: Ein - Expression: param_orientation == "auto" - Expression: gplay - App Task läuft: gplay (neuster) - App Task läuft: tuneinradio (neuster) - Expression: tuneinradio - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + Setze Flow Status: Aktivieren Informations + Setze Systemeinstellung: System screen_brightness auf {param_brightness} + HTTP Response SetCommand + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 110a1c1..d6bf932 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ Im Auslieferiungszustand werden folgende Zustände dargestellt:
      • Zustand von Automagic auf dem Gerät
      • +
      • Bluetooth An/Aus
      • +
      • verbundene Bluetoothgeräte
      • aktuell abgespieltes Musikalbum des verwendeten Mediaplayers
      • aktuell abgespielter Musikinterpret des verwendeten Mediaplayers
      • aktuell abgespielter Musiktitel des verwendeten Mediaplayers
      • @@ -24,7 +26,7 @@

      Mit etwas Einarbeitung können jegliche Informationen welche Automagic bereit stellt in FHEM angezeigt werden. Hierzu bedarf es lediglich - einer kleinen Anpassung des "Information" Flows + einer kleinen Anpassung des "Informations" Flows

      Das Modul gibt Dir auch die Möglichkeit Deine Androidgeräte zu steuern. So können folgende Aktionen durchgeführt werden.
        @@ -49,11 +51,8 @@

        Wie genau verwendet man nun AMAD?
          -
        • Installiert Euch die App "Automagic Premium" aus dem App Store oder die Testversion von hier
        • -
        • ladet Euch das AMAD Modul und die Flowfiles von GitHub runter
        • -
        • installiert die zwei Flows und aktiviert erstmal nur den "Information" Flow, eventuell bei den - FlowUpdates mal schauen ob es was neueres gibt und den entsprechenden Flow auf dem Gerät löschen und den neuen Flow von GitHub installieren
        • -
        • kopiert die Moduldatei 74_AMAD.pm nach $FHEMPATH/FHEM. Geht auf die FHEM Frontendseite und gebt dort in der Kommandozeile reload 74_AMAD.pm ein
        • +
        • installiert Euch die App "Automagic Premium" aus dem App Store oder die Testversion von hier
        • +
        • installiert das Flowset 74_AMADautomagicFlows$VERSION.xml aus dem Ordner $INSTALLFHEM/lib/ auf Eurem Androidgerät und aktiviert erstmal nur den "Informations" Flow.

        Nun müsst Ihr nur noch ein Device in FHEM anlegen. @@ -61,31 +60,34 @@ Define

          - define <name> AMAD <IP-ADRESSE> <PORT> <INTERVAL> + define <name> AMAD <IP-ADRESSE>

          Beispiel:

            - define WandTabletWohnzimmer AMAD 192.168.0.23 8090 180
            + define WandTabletWohnzimmer AMAD 192.168.0.23

          - Diese Anweisung erstellt ein neues AMAD-Device. Die Parameter IP-ADRESSE und PORT legen die IP Adresse des Android Gerätes - sowie den, in den Flows des Trigger HTTP Request, angegebenen Port fest.
          INTERVAL ist der Zeitabstand in dem ein erneuter Informationsabruf stattfinden soll. Alle x Sekunden. - Bei mir hat sich 180 gut bewährt, also alle 3 Minuten
          - Bitte gebt für sofortige Erfolge als Port 8090 ein, das ist der Port der in den mitgelieferten Automagic Flows als Trigger Port eingetragen ist.
          - Dieser kann später mit Erfahrung auch geändert werden
          + Diese Anweisung erstellt ein neues AMAD-Device. Der Parameter <IP-ADRESSE< legt die IP Adresse des Android Gerätes fest.
          + Das Standard Abfrageinterval ist 180 Sekunden und kann über das Attribut intervall geändert werden. Wer den Port ändern möchte, kann dies über + das Attribut port tun. Ihr solltet aber wissen was Ihr tut, da dieser Port im HTTP Response Trigger der beiden Flows eingestellt ist. Demzufolge muß dieser dort + auch verädert werden.


        - Fertig! Nach anlegen des Devices sollten bereits die ersten Readings reinkommen. + Fertig! Nach anlegen der Geräteinstanz sollten nach spätestens 3 Minuten bereits die ersten Readings reinkommen.

        Readings
        • automagicState - Statusmeldungen von der AutomagicApp
        • +
        • bluetooth on/off - ist auf dem Gerät Bluetooth an oder aus
        • +
        • connectedBTdevices - eine Lieste der verbundenen Gerät
        • currentMusicAlbum - aktuell abgespieltes Musikalbum des verwendeten Mediaplayers
        • currentMusicArtist - aktuell abgespielter Musikinterpret des verwendeten Mediaplayers
        • currentMusicTrack - aktuell abgespielter Musiktitel des verwendeten Mediaplayers
        • deviceState - Status des Androidgerätes, muss selbst mit setreading gesetzt werden z.B. über die Anwesenheitskontrolle.
          Ist Offline gesetzt, wird der Intervall zum Informationsabruf aus gesetzt.
        • +
        • flow_SetCommands active/inactive - gibt den Status des SetCommands Flow wieder
        • +
        • flow_informations active/inactive - gibt den Status des Informations Flow wieder
        • lastSetCommandError - letzte Fehlermeldung vom set Befehl
        • lastSetCommandState - letzter Status vom set Befehl, Befehl erfolgreich/nicht erfolgreich gesendet
        • lastStatusRequestError - letzte Fehlermeldung vom statusRequest Befehl
        • @@ -125,7 +127,7 @@
        • mediaPlayer - steuert den Standard Mediaplayer. play, stop, Titel zürück, Titel vor. Attribut fhemServerIP
        • openApp - öffnet eine ausgewählte App. Attribut setOpenApp
        • screenBrightness - setzt die Bildschirmhelligkeit, von 0-255 Attribut setScreenBrightness
        • - Wenn Ihr das "set screenBrightness" verwenden wollt, muss eine kleine Anpassung im Flow SetCommand vorgenommen werden. Öffnet die Aktion (eines der Vierecke ganz ganz unten) + Wenn Ihr das "set screenBrightness" verwenden wollt, muss eine kleine Anpassung im Flow SetCommands vorgenommen werden. Öffnet die Aktion (eines der Vierecke ganz ganz unten) SetzeSystemeinstellung:System und macht einen Haken bei "Ich habe die Einstellungen überprüft, ich weiss was ich tue".
        • screenFullscreen - Schaltet den Vollbildmodus on/off. Attribut setFullscreen
        • screenOrientation - Schaltet die Bildschirmausrichtung Auto/Landscape/Portait. Attribut setScreenOrientation
        • @@ -140,7 +142,8 @@ STATE
          • initialized - Ist der Status kurz nach einem define..
          • -
          • activ - Das Modul ist im aktiven Status.
          • +
          • active - die Geräteinstanz ist im aktiven Status.
          • +
          • disabled - die Geräteinstanz wurde über das Attribut disable deaktiviert



          Anwendungsbeispiele: