Skip to content

98_FireTV.pm

Thomas Nesges edited this page Mar 9, 2017 · 3 revisions

FireTV

FireTV is used to remote control a Amazon FireTV device. It is not able to read the currently playing music/movie or other status information, but sending commands to the device. A working copy of adb is needed.

Prerequisites

  • Activate adb debugging in your fire tv (see here)
  • Get adb for your fhem-server. Depending on your system, you have several options:
  • uses the perl module File::MimeInfo for some tasks. Installs via apt-get install libfile-mimeinfo-perl on some systems
  • uses 73_PRESENCE.pm by Markus Bloch for presence-detection (included in Fhem by default)


Define

define <name> FireTV <IP> [<ADB_PATH>] [<PRESENCE_TIMEOUT_ABSENT>] [<PRESENCE_TIMEOUT_PRESENT>] [<PRESENCE_MODE>] [<PRESENCE_ADDRESS>]

or, if 73_PRESENCE.pm is not available:

define <name> FireTV <IP> [<ADB_PATH>]

Example: define FIRETV FireTV 192.168.178.66 /usr/local/bin/adb

IP is the ip-address of your FireTV-device
ADB_PATH is the full path to your adb-binary. Default: /usr/bin/adb
PRESENCE_TIMEOUT_ABSENT timeout (in seconds) to the next presence check if the device is absent. Default: 30
PRESENCE_TIMEOUT_PRESENT timeout (in seconds) to the next presence check if the device is present. Default: <PRESENCE_TIMEOUT_ABSENT>
PRESENCE_MODE mode for the presence check, see PRESENCE. Default: lan-ping
PRESENCE_ADRESS address for the presence check, see PRESENCE. Default: <IP>


Get

  • adb <COMMAND>
    Execute an adb command on your firetv and return it's response. Try adb help.
  • isapprunning <PACKAGE>
    Returns the PID of a running app, or 0 if not running
  • packages
    Reads the list of installed packages on your firetv and stores it internally. get packages is called automatically when the device changes state from absent to present to populate the select-boxes for some other commands (e.g. appstart) in FHEMWEB
Set
  • adb <COMMAND>
    Execute an adb command on your firetv. If you need to see the devices response use the get version of this command instead.
  • appstart <PACKAGE>
    Start an app on your firetv. You may read names of installed packages via get packages (see above)
  • appstop <PACKAGE>
    Stop an app on your firetv
  • apptoggle <PACKAGE>
    Start/stop an app on your firetv. Start if not running, stop otherwise
  • button <BUTTON>
    Send a button-press to your firetv. Possible buttons (in order of appearance on a standard fire remote): up, left, ok, right, down, back, home, menu, prev, playpause, next
  • connect
    Connect adb to your firetv. This is done automatically by all defined set/get-commands
  • deletefile <PATH>
    Delete a file on your firetv. This command is restricted to files, that where uploaded vie upload/uploadandview (see below)
  • disconnect
    Disconnect adb from your firetv
  • install <APK>
    Install ("sideload") an apk-file on your firetv. APK is a local path on your fhem-server. install is implemented as a blocking call, don't use it in scripts
  • key <KEYCODE>
    Send a standard android keycode to your firetv. You can send any keycode, but firetv may not understand them all (known to work: KEYCODE_DPAD_UP, KEYCODE_DPAD_DOWN, KEYCODE_DPAD_LEFT, KEYCODE_DPAD_CENTER, KEYCODE_DPAD_RIGHT, KEYCODE_BACK, KEYCODE_HOME, KEYCODE_MENU, KEYCODE_MEDIA_PREVIOUS, KEYCODE_MEDIA_PLAY_PAUSE, KEYCODE_MEDIA_FAST_FORWARD, KEYCODE_WAKEUP, KEYCODE_POWER)
  • screen <wakeup|toggle|sleep>
    Set screen to wake up or sleep or toggle between these states
  • screenshot
    Take a screenshot and download it to a local tempfile on your fhem-server. Since it may take some seconds to produce a screenshot, this function is implemented nonblocking (iow: no direct feedback). The path to the local tempfile is saved in a reading "screenshot" and may be set by the attribute "screenshotpath". Screenshots taken while playing a movie/tv-show/etc from amazons library are in general just black. On error the reading "screenshot" is emptied
  • search <TEXT>
    Navigate to the search-menu on your firetv, enter text and navigate to the first result
  • searchonly <TEXT>
    Navigate to the search-menu on your firetv and enter text
  • statusRequest
    Schedules an immediate presence-check
  • text <TEXT>
    Send text to your firetv
  • uploadandview <PATH:CONTENTTYPE>
    Upload a file to your firetv and view it on screen. The view action is dependend on an arbitrary installed app that handles CONTENTTYPE and is not limited to images. You may omit CONTENTTYPE if you have the perl module File::MimeInfo installed on your system. Such files may be automatically deleted when the attribute upviewdeleteafter is set (see below)
  • upload <PATH>
    Upload a file to your firetv. Such files may be automatically deleted when the attribute uploaddeleteafter is set (see below)
  • view <PATH:CONTENTTYPE>
    View a file on your firetv. The view action is dependend on an arbitrary installed app that handles CONTENTTYPE and is not limited to images. If you have the perl module File::MimeInfo installed on your system, you may replace CONTENTTYPE whith the keyword load: The file will be downloaded to your fhem-server prior viewing it on screen, then (which may take some time and is generally speaking inefficient).
  • window <appsetting|fotos|music|settings>
    Activate a named window of the firetv menu.

Attributes
  • holdconnection yes|no
    "yes" to keep the adb connection open or "no" to close it after every command. Default: no
  • remotehtml <HTML>
    HTML to add to the output of FireTV_Remote() (see below)
  • screenshotpath <PATH>
    If screenshotpath is set to a filename, every new screenshot (see set screenshot) will overwrite that file. If set to a directory, a random file will be created in that directory. If not set, a random file is created in your systems tempdirectory (POSIX tmpnam). Default: not set
  • uploaddeleteafter <SECONDS>
    Files uploaded via set upload are deleted after SECONDS when set to a positve integer number. Default: not set
  • upviewdeleteafter <SECONDS>
    Files uploaded via set uploadandview are deleted after SECONDS when set to a positve integer number. Default: not set
Inherited from PRESENCE:
  • absenceThreshold
  • absenceTimeout
  • disable
  • ping_count
  • presenceThreshold
  • presenceTimeout
Other:
Values of STATE
  • active
    devicestatus is unknown, but a check is running (checked via 73_PRESENCE)
  • absent
    device is absent (checked via 73_PRESENCE)
  • defined
    device is defined
  • disabled
    presence-check is disabled, all other functions may still work
  • present
    device is present (checked via 73_PRESENCE)


FireTV_Remote()

The module provides an additional function FireTV_Remote() which returns html code for a graphic remote control usable in FHEMWEB. Just define a weblink device like:

define FIRETV_REMOTE weblink htmlCode { FireTV_Remote('FIRETV') }
define FIRETV_REMOTE weblink htmlCode { FireTV_Remote(DEVICE, ICON, COLLAPSIBLE, DEVICELINK) }

Parameters:

  • DEVICE: Devicename of your FireTV-Device
  • ICON: Icon to display in the upper left corner. Default: it_remote
  • COLLAPSIBLE: If set to a positive value (1), the remote is displayed collapsed and will expand after clicking it's icon. Default: not set
  • DEVICELINK: If not set, the Remote has a clickable title which links to the controlled device. If set to "0" it has no title. If set to any other value, that value will be used as clickable title. Default: not set

The content of the attribute remotehtml is added at the end of FireTV_Remote() output. If the content is wrapped in curly brackets it is interpreted as perl-code. The output is structured in a three-column table-layout. Here is an example of how to add some additional buttons to the remote:
{
my $device = 'FIRETV';
my $cmd = &quot;FW_cmd('$FW_ME$FW_subdir?XHR=1&amp;cmd.$device=set $device &quot;;

return &quot;&lt;tr&gt;&lt;td colspan='3'&gt;&lt;hr&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a onClick=\&quot;$cmd appstart org.xbmc.kodi')\&quot;&gt;&quot;.FW_makeImage(&quot;kodi&quot;, &quot;Kodi&quot;, &quot;rc-button&quot;).&quot;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a onClick=\&quot;$cmd appstart com.spotify.tv.android')\&quot;&gt;&quot;.FW_makeImage(&quot;spotify&quot;, &quot;Spotify&quot;, &quot;rc-button&quot;).&quot;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a onClick=\&quot;$cmd appstart tv.twitch.android.viewer')\&quot;&gt;&quot;.FW_makeImage(&quot;twitch&quot;, &quot;twitch&quot;, &quot;rc-button&quot;).&quot;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a onClick=\&quot;$cmd screen sleep')\&quot;&gt;&quot;.FW_makeImage(&quot;rc_TV\@red&quot;, &quot;sleep&quot;, &quot;rc-button&quot;).&quot;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a onClick=\&quot;$cmd screen wakeup')\&quot;&gt;&quot;.FW_makeImage(&quot;rc_TV&quot;, &quot;wakeup&quot;, &quot;rc-button&quot;).&quot;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a onClick=\&quot;$cmd window settings')\&quot;&gt;&quot;.FW_makeImage(&quot;rc_SETUP&quot;, &quot;settings&quot;, &quot;rc-button&quot;).&quot;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;&quot;;
}
Clone this wiki locally