diff --git a/fhem/CHANGED b/fhem/CHANGED index 169a4e362..ebe8aa838 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,8 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - updated: 74_AMAD: New Minor Release 2.2 real state for deviceState Reading, + Support for Amazon Music Player and Spotify Player, Keep + Alive funktion for Android 6 - bugfix: 77_UWZ: Commandref Warn Type 7 and 6 exchanged, new method for no eperimental warnings - feature: plex: play command now handles single media items, music albums diff --git a/fhem/FHEM/74_AMAD.pm b/fhem/FHEM/74_AMAD.pm index 8d8e21b9a..3b98c34c6 100644 --- a/fhem/FHEM/74_AMAD.pm +++ b/fhem/FHEM/74_AMAD.pm @@ -37,8 +37,8 @@ use TcpServerUtils; use Encode qw(encode); -my $modulversion = "2.0.3"; -my $flowsetversion = "2.0.5"; +my $modulversion = "2.2.0"; +my $flowsetversion = "2.2.0"; @@ -97,6 +97,7 @@ sub AMAD_Define($$) { $hash->{VERSIONFLOWSET} = $flowsetversion; $hash->{helper}{infoErrorCounter} = 0 if( $hash->{HOST} ); $hash->{helper}{setCmdErrorCounter} = 0 if( $hash->{HOST} ); + $hash->{helper}{deviceStateErrorCounter} = 0 if( $hash->{HOST} ); @@ -122,10 +123,10 @@ sub AMAD_Define($$) { $attr{$name}{room} = "AMAD" if( !defined( $attr{$name}{room} ) ); readingsSingleUpdate ( $hash, "state", "initialized", 1 ) if( $hash->{HOST} ); - #readingsSingleUpdate ( $hash, "deviceState", "online", 1 ) if( $hash->{HOST} ); + readingsSingleUpdate ( $hash, "deviceState", "unknown", 1 ) if( $hash->{HOST} ); RemoveInternalTimer($hash); - InternalTimer( gettimeofday()+15, "AMAD_GetUpdate", $hash, 0 ) if( ($hash->{HOST}) && ($hash->{APSSID}) ); + InternalTimer( gettimeofday()+30, "AMAD_GetUpdate", $hash, 0 ) if( ($hash->{HOST}) && ($hash->{APSSID}) ); $modules{AMAD}{defptr}{$hash->{HOST}} = $hash; @@ -138,7 +139,7 @@ sub AMAD_Undef($$) { my ( $hash, $arg ) = @_; if( $hash->{BRIDGE} ) { - delete $modules{AMAD}{defptr}{BRIDGE}; + delete $modules{AMAD}{defptr}{BRIDGE} if(defined($modules{AMAD}{defptr}{BRIDGE})); TcpServer_Close( $hash ); } else { @@ -187,9 +188,10 @@ sub AMAD_Attr(@) { } } - elsif( $attrName eq "setScreenBrightness" ) { - Log3 $name, 1, "AMAD ($name) - !!!The Attribut \"setScreenBrightness\" is obsolete and will be remove in the future!!! Please delete the attribut description in your AMAD Device"; - Log3 $name, 1, "AMAD ($name) - !!!Das Attribut \"setScreenBrightness\" wird nicht mehr benötigt und in zukünftigen Versionen entfernt!!! Bitte lösche die Attributszuweisung aus Deinem AMAD Device"; + elsif( $attrName eq "checkActiveTask" ) { + + AMAD_statusRequest( $hash ); + Log3 $name, 3, "AMAD ($name) - $cmd $attrName $attrVal and run statusRequest"; } elsif( $attrName eq "port" ) { @@ -246,9 +248,10 @@ my ( $hash ) = @_; RemoveInternalTimer( $hash ); - if( $init_done && ReadingsVal( $name, "deviceState", "online" ) eq "online" && AttrVal( $name, "disable", 0 ) ne "1" && ReadingsVal( $bname, "fhemServerIP", "not set" ) ne "not set" && $hash->{APSSID} ) { + if( $init_done && ( ReadingsVal( $name, "deviceState", "unknown" ) eq "unknown" or ReadingsVal( $name, "deviceState", "online" ) eq "online" ) && AttrVal( $name, "disable", 0 ) ne "1" && ReadingsVal( $bname, "fhemServerIP", "not set" ) ne "not set" && $hash->{APSSID} ) { AMAD_statusRequest( $hash ); + AMAD_checkDeviceState( $hash ); } else { @@ -477,6 +480,8 @@ sub AMAD_ResponseProcessing($$) { readingsBulkUpdate( $hash, "state", "active" ) if( ReadingsVal( $name, "state", 0 ) eq "initialized" ); readingsEndUpdate( $hash, 1 ); + $hash->{helper}{deviceStateErrorCounter} = 0 if( $hash->{helper}{deviceStateErrorCounter} > 0 and ReadingsVal( $name, "deviceState", "offline") eq "online" ); + return undef; } @@ -496,8 +501,10 @@ sub AMAD_Set($$@) { $list .= "screenMsg "; $list .= "ttsMsg "; $list .= "volume:slider,0,1,15 "; - $list .= "deviceState:online,offline "; - $list .= "mediaPlayer:play,stop,next,back " if( ReadingsVal( $bname, "fhemServerIP", "none" ) ne "none"); + $list .= "googleMusic:play,stop,next,back " if( ReadingsVal( $bname, "fhemServerIP", "none" ) ne "none"); + $list .= "amazonMusic:play,stop,next,back " if( ReadingsVal( $bname, "fhemServerIP", "none" ) ne "none"); + $list .= "spotifyMusic:play,stop,next,back " if( ReadingsVal( $bname, "fhemServerIP", "none" ) ne "none"); + $list .= "tuneinRadio:play,stop,next,back " if( ReadingsVal( $bname, "fhemServerIP", "none" ) ne "none"); $list .= "screenBrightness:slider,0,1,255 "; $list .= "screen:on,off,lock,unlock "; $list .= "screenOrientation:auto,landscape,portrait " if( AttrVal( $name, "setScreenOrientation", "0" ) eq "1" ); @@ -516,14 +523,17 @@ sub AMAD_Set($$@) { $list .= "volumeNotification:slider,0,1,7 "; $list .= "vibrate:noArg "; $list .= "sendIntent "; + $list .= "openCall "; $list .= "currentFlowsetUpdate:noArg "; $list .= "installFlowSource "; if( lc $cmd eq 'screenmsg' || lc $cmd eq 'ttsmsg' || lc $cmd eq 'volume' - || lc $cmd eq 'mediaplayer' - || lc $cmd eq 'devicestate' + || lc $cmd eq 'googlemusic' + || lc $cmd eq 'amazonmusic' + || lc $cmd eq 'spotifymusic' + || lc $cmd eq 'tuneinradio' || lc $cmd eq 'screenbrightness' || lc $cmd eq 'screenorientation' || lc $cmd eq 'screenfullscreen' @@ -544,6 +554,7 @@ sub AMAD_Set($$@) { || lc $cmd eq 'sendintent' || lc $cmd eq 'currentflowsetupdate' || lc $cmd eq 'installflowsource' + || lc $cmd eq 'opencall' || lc $cmd eq 'vibrate') { Log3 $name, 5, "AMAD ($name) - set $name $cmd ".join(" ", @val); @@ -551,7 +562,7 @@ sub AMAD_Set($$@) { return "set command only works if state not equal initialized" if( ReadingsVal( $hash->{NAME}, "state", 0 ) 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 ) && ( ReadingsVal( $name, "deviceState", "online" ) eq "offline" ) && ( lc $cmd eq 'devicestate' ); + return "Cannot set command, FHEM Device is unknown" if( ReadingsVal( $name, "deviceState", "online" ) eq "unknown" ); return "Cannot set command, FHEM Device is offline" if( ReadingsVal( $name, "deviceState", "online" ) eq "offline" ); return AMAD_SelectSetCmd( $hash, $cmd, @val ) if( @val ) || ( lc $cmd eq 'statusrequest' ) || ( lc $cmd eq 'activatevoiceinput' ) || ( lc $cmd eq 'vibrate' ) || ( lc $cmd eq 'currentflowsetupdate' ); @@ -630,24 +641,15 @@ sub AMAD_SelectSetCmd($$@) { return AMAD_HTTP_POST( $hash, $url ); } - elsif( lc $cmd eq 'mediaplayer' ) { + elsif( lc $cmd eq 'googlemusic' or lc $cmd eq 'amazonmusic' or lc $cmd eq 'spotifymusic' or lc $cmd eq 'tuneinradio' ) { my $btn = join( " ", @data ); - my $url = "http://" . $host . ":" . $port . "/fhem-amad/setCommands/mediaPlayer?button=$btn"; + my $url = "http://" . $host . ":" . $port . "/fhem-amad/multimediaControl?mplayer=".$cmd."&button=".$btn; return AMAD_HTTP_POST( $hash,$url ); } - elsif( lc $cmd eq 'devicestate' ) { - - my $v = join( " ", @data ); - - readingsSingleUpdate( $hash, $cmd, $v, 1 ); - - return undef; - } - elsif( lc $cmd eq 'screenbrightness' ) { my $bri = join( " ", @data ); @@ -741,7 +743,7 @@ sub AMAD_SelectSetCmd($$@) { elsif( lc $cmd eq 'statusrequest' ) { - AMAD_GetUpdate( $hash ); + AMAD_statusRequest( $hash ); return undef; } @@ -838,6 +840,17 @@ sub AMAD_SelectSetCmd($$@) { return AMAD_HTTP_POST( $hash,$url ); } + elsif( lc $cmd eq 'opencall' ) { + + my $string = join( " ", @data ); + my ($callnumber, $time) = split( "[ \t][ \t]*", $string ); + $time = "none" if( !$time ); + + my $url = "http://" . $host . ":" . $port . "/fhem-amad/setCommands/openCall?callnumber=".$callnumber."&hanguptime=".$time; + + return AMAD_HTTP_POST( $hash,$url ); + } + elsif( lc $cmd eq 'currentflowsetupdate' ) { my $url = "http://" . $host . ":" . $port . "/fhem-amad/currentFlowsetUpdate"; @@ -1001,6 +1014,27 @@ sub AMAD_HTTP_POSTerrorHandling($$$) { return undef; } +sub AMAD_checkDeviceState($) { + + my ( $hash ) = @_; + my $name = $hash->{NAME}; + + Log3 $name, 4, "AMAD ($name) - AMAD_checkDeviceState: run Check"; + + RemoveInternalTimer( $hash ); + + if( ReadingsAge( $name, "deviceState", 90 ) > 90 ) { + + AMAD_statusRequest( $hash ) if( $hash->{helper}{deviceStateErrorCounter} == 0 ); + readingsSingleUpdate( $hash, "deviceState", "offline", 1 ) if( ReadingsAge( $name, "deviceState", 180) > 180 and $hash->{helper}{deviceStateErrorCounter} > 0 ); + $hash->{helper}{deviceStateErrorCounter} = ( $hash->{helper}{deviceStateErrorCounter} + 1 ); + } + + InternalTimer( gettimeofday()+90, "AMAD_checkDeviceState", $hash, 0 ); + + Log3 $name, 4, "AMAD ($name) - AMAD_checkDeviceState: set new Timer"; +} + sub AMAD_CommBridge_Open($) { my ( $hash ) = @_; @@ -1057,7 +1091,7 @@ sub AMAD_CommBridge_Read($) { my @data = split( '\R\R', $buf ); my $header = AMAD_Header2Hash( $data[0] ); - my $device = $header->{FHEMDEVICE}; + my $device = $header->{FHEMDEVICE} if(defined($header->{FHEMDEVICE})); my $dhash = $defs{$device}; my $response; my $c; @@ -1147,7 +1181,7 @@ sub AMAD_CommBridge_Read($) { elsif ( $fhemcmd =~ /readingsval\b/ ) { my $fhemCmd = $data[1]; - my @datavalue = split( ' ', $data[1] ); + my @datavalue = split( ' ', $fhemCmd ); $response = ReadingsVal( $datavalue[0], $datavalue[1], $datavalue[2] ); $c = $hash->{CD}; @@ -1165,7 +1199,7 @@ sub AMAD_CommBridge_Read($) { Log3 $bname, 4, "AMAD ($bname) - AMAD_CommBridge: receive fhem-function command"; - if( $fhemcmd =~ /^{.*}$/ ) { + if( $fhemCmd =~ /^{.*}$/ ) { $response = $fhemCmd if( ReadingsVal( $bname, "expertMode", 0 ) eq "1" ); @@ -1265,7 +1299,7 @@ sub AMAD_decrypt($) { How to use AMAD?
Now you need to define a device in FHEM. @@ -1277,10 +1311,10 @@ sub AMAD_decrypt($) {

Example:
- With this command two new AMAD devices in a room called AMAD are created. The parameter <IP-ADDRESS< defines the IP address of your Android device, parameter WLANAP-SSID defines the SSID(s) of the WLAN(s) from which the FHEM server can be reached. More than one SSID can be defined which need to be joined by two consequent "@". The second device created is the AMADCommBridge which serves as a communication device from each Android device to FHEM.
+ With this command two new AMAD devices in a room called AMAD are created. The parameter <IP-ADDRESS< defines the IP address of your Android device, parameter WLANAP-SSID defines the SSID(s) of the WLAN(s) from which the FHEM server can be reached. Multiple SSID can be defined. They need to be separated by a comma (,). If a SSID contains spaces replace these spaces by a double at-sign (@@). For Android devices connected by LAN use "usb-ethernet" as SSID. The second device created is the AMADCommBridge which serves as a communication device from each Android device to FHEM.
!!!Coming Soon!!! The communication port of each AMAD device may be set by the definition of the "port" attribute. One needs background knowledge of Automagic and HTTP requests as this port will be set in the HTTP request trigger of both flows, therefore the port also needs to be set there.
The communication port of the AMADCommBridge device can easily be changed within the attribut "port".
@@ -1292,7 +1326,6 @@ sub AMAD_decrypt($) { Please us the following command for configuration of the FHEM server IP address in the AMADCommBridge: set AMADCommBridge fhemServerIP <FHEM-IP>.
Additionally the expertMode may be configured. By this setting a direct communication with FHEM will be established without the restriction of needing to make use of a notify to execute set commands.
- NOW please activate the flows in Automagic!!!

You are finished now! After 15 seconds latest the readings of your AMAD Android device should be updated. Consequently each 15 seconds a status request will be sent. If the state of your AMAD Android device does not change to "active" over a longer period of time one should take a look into the log file for error messages.


@@ -1307,10 +1340,11 @@ sub AMAD_decrypt($) {
  • connectedBTdevices - list of all devices connected via bluetooth
  • connectedBTdevicesMAC - list of MAC addresses of all devices connected via bluetooth
  • currentMusicAlbum - currently playing album of mediaplayer
  • +
  • currentMusicApp - currently playing player app
  • currentMusicArtist - currently playing artist of mediaplayer
  • currentMusicTrack - currently playing song title of mediaplayer
  • daydream - on/off, daydream currently active
  • -
  • deviceState - state of Android devices. !!!It does not show the real state!!! deviceState must be set manually by the command "set DEVICE deviceState" e.g. by your PRESENCE function.
    In case deviceState is set to "offline" no set commands can be issued.
  • +
  • deviceState - state of Android devices. unknown, online, offline.
  • dockingState - undocked/docked, Android device in docking station
  • flow_SetCommands - active/inactive, state of SetCommands flow
  • flow_informations - active/inactive, state of Informations flow
  • @@ -1345,17 +1379,18 @@ sub AMAD_decrypt($) { Set