Autostart FireTV Server

Hi,
im not verry good in Linux Stuff, so please forgive me.

I configured the FireTV like its explained here: https://home-assistant.io/components/media_player.firetv/
But I cant get it autostart and run in background. I already tried to write an init.d script, but im kinda noob.

#!/bin/sh
### BEGIN INIT INFO
# Provides:          firetv-server
# Required-Start:
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: firetv-server
# Description:       firetv-server
### END INIT INFO

sudo firetv-server [-d [192.168.1.110]] [-p 5555]

Could you help me make this script running?

Greets

Lucas

I had followed the setup here that put the server in its own virtual environment

and then used this to create a service:

1 Like

If you want to use docker I made a new image for it.

To test:

docker run -it --rm --name python-firetv -p 5556:5556 sytone/python-firetv

To use as a service:

docker run -d --restart=always --name python-firetv -p 5556:5556 sytone/python-firetv

@smolz, thanks for your instruction.
Unfortunately it doesnt work for me. But it may have other reasons?

I used the general instruction on the hass site and it ran fine till today…

During investigation in the forum I got your post and tried it.

When I run firetv-server -d <myIP>:5555 I get now:
Traceback (most recent call last): File "/usr/local/bin/firetv-server", line 9, in <module> load_entry_point('firetv==1.0.5', 'console_scripts', 'firetv-server')() File "/usr/local/lib/python2.7/dist-packages/firetv/__main__.py", line 237, in main if args.default and not add('default', args.default): File "/usr/local/lib/python2.7/dist-packages/firetv/__main__.py", line 81, in add devices[device_id] = FireTV(str(host)) File "/usr/local/lib/python2.7/dist-packages/firetv/__init__.py", line 61, in __init__ self.connect() File "/usr/local/lib/python2.7/dist-packages/firetv/__init__.py", line 71, in connect serial=self.host) File "/usr/local/lib/python2.7/dist-packages/adb/adb_commands.py", line 87, in ConnectDevice return cls.Connect(handle, **kwargs) File "/usr/local/lib/python2.7/dist-packages/adb/adb_commands.py", line 110, in Connect device_state = cls.protocol_handler.Connect(usb, banner=banner, **kwargs) File "/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py", line 272, in Connect cmd, arg0, arg1, banner = cls.Read(usb, ['CNXN', 'AUTH']) File "/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py", line 215, in Read cmd, arg0, arg1, data_length, data_checksum = cls.Unpack(msg) File "/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py", line 200, in Unpack raise ValueError('Unable to unpack ADB command.', cls.format, message, e) ValueError: ('Unable to unpack ADB command.', '<6I', '', error('unpack requires a string argument of length 24',))

I cant determine the problem :neutral_face:

The error you are getting looks like firetv-server is failing to connect to the adb server. Do you have adb installed? You can test it manually.

adb connect IP_ADDRESS_OF_FIRE_TV

Hi,
Tanks for your help!
Hm, it was still running beforethis error :-/

But as you said I tried adb connect and it misses adb so I installed it.
Aftery successfully trying adb connect [ip]
I tried to start the server again after a restart.
Here’s the complete log

`Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Jan 25 22:40:34 2017 from android.fritz.box
pi@homeserver:~ $ sudo su - firetv -s /bin/bash
firetv@homeserver:~$ source firetv/bin/activate
(firetv) firetv@homeserver:~$ sudo firetv-server -d 192.168.1.25:5555
[sudo] password for firetv:
Traceback (most recent call last):
File “/usr/local/bin/firetv-server”, line 9, in
load_entry_point(‘firetv==1.0.5’, ‘console_scripts’, ‘firetv-server’)() File “/usr/local/lib/python2.7/dist-packages/firetv/main.py”, line 237, in main
if args.default and not add(‘default’, args.default):
File “/usr/local/lib/python2.7/dist-packages/firetv/main.py”, line 81, in add
devices[device_id] = FireTV(str(host))
File “/usr/local/lib/python2.7/dist-packages/firetv/init.py”, line 61, in init
self.connect()
File “/usr/local/lib/python2.7/dist-packages/firetv/init.py”, line 71, in connect
serial=self.host)
File “/usr/local/lib/python2.7/dist-packages/adb/adb_commands.py”, line 87, in ConnectDevice
return cls.Connect(handle, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/adb/adb_commands.py”, line 110, in Connect
device_state = cls.protocol_handler.Connect(usb, banner=banner, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py”, line 272, in Connect
cmd, arg0, arg1, banner = cls.Read(usb, [‘CNXN’, ‘AUTH’])
File “/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py”, line 215, in Read
cmd, arg0, arg1, data_length, data_checksum = cls.Unpack(msg)
File “/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py”, line 200, in Unpack
raise ValueError(‘Unable to unpack ADB command.’, cls.format, message, e)
ValueError: (‘Unable to unpack ADB command.’, ‘<6I’, ‘’, error(‘unpack requires a string argument of length 24’,))
(firetv) firetv@homeserver:~$ sudo adb connect 192.168.1.25

  • daemon not running. starting it now on port 5037 *
  • daemon started successfully *
    connected to 192.168.1.25:5555
    (firetv) firetv@homeserver:~$ sudo firetv-server -d 192.168.1.25:5555
    Traceback (most recent call last):
    File “/usr/local/bin/firetv-server”, line 9, in
    load_entry_point(‘firetv==1.0.5’, ‘console_scripts’, ‘firetv-server’)() File “/usr/local/lib/python2.7/dist-packages/firetv/main.py”, line 237, in main
    if args.default and not add(‘default’, args.default):
    File “/usr/local/lib/python2.7/dist-packages/firetv/main.py”, line 81, in add
    devices[device_id] = FireTV(str(host))
    File “/usr/local/lib/python2.7/dist-packages/firetv/init.py”, line 61, in init
    self.connect()
    File “/usr/local/lib/python2.7/dist-packages/firetv/init.py”, line 71, in connect
    serial=self.host)
    File “/usr/local/lib/python2.7/dist-packages/adb/adb_commands.py”, line 87, in ConnectDevice
    return cls.Connect(handle, **kwargs)
    File “/usr/local/lib/python2.7/dist-packages/adb/adb_commands.py”, line 110, in Connect
    device_state = cls.protocol_handler.Connect(usb, banner=banner, **kwargs)
    File “/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py”, line 272, in Connect
    cmd, arg0, arg1, banner = cls.Read(usb, [‘CNXN’, ‘AUTH’])
    File “/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py”, line 215, in Read
    cmd, arg0, arg1, data_length, data_checksum = cls.Unpack(msg)
    File “/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py”, line 200, in Unpack
    raise ValueError(‘Unable to unpack ADB command.’, cls.format, message, e)
    ValueError: (‘Unable to unpack ADB command.’, ‘<6I’, ‘’, error(‘unpack requires a string argument of length 24’,))`

Have you tried rebooting your firetv?

Also, after adb connect, can you try adb shell.

1 Like

Naaa, are you kidding me!! :confounded:
After reboot everything works super smooth again…
Thank you so much!
Cant believe I didnt try that first, sorry.

I’ve seen this happen before. I think it’s because only one active ADB connection is allowed.

Good to hear yours is working now.

Oh, okay, ill keep that in mind.
What would cause multiple ADB connections?
The hass is the only service I use for communication with the firetv except our smartphones.

In my case, it was because I switched from one PC to another without disconnecting.

Ah okay, maybe I started 2 services. One in virtual machine and one with regular pi user…
I will check taht if I get problems again :slight_smile:

@benaranguren - I wonder if you can help me; first of all, when I run adb connect IP at the command line, I get the following:

pi@raspi1:~$ adb connect 192.168.1.166:5555
-bash: adb: command not found
pi@raspi1:~$ pip install adb
Requirement already satisfied (use --upgrade to upgrade): adb in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied (use --upgrade to upgrade): libusb1 in /usr/local/lib/python2.7/dist-packages (from adb)
Requirement already satisfied (use --upgrade to upgrade): python-gflags in /usr/local/lib/python2.7/dist-packages (from adb)
Requirement already satisfied (use --upgrade to upgrade): M2Crypto in /usr/local/lib/python2.7/dist-packages (from adb)
Requirement already satisfied (use --upgrade to upgrade): typing in /usr/local/lib/python2.7/dist-packages (from M2Crypto->adb)
Cleaning up...
pi@raspi1:~$

But as you can see, it is already installed. I tried an upgrade but it shows it’s at the latest version. Do you have any ideas where I should start in troubleshooting this?

I had firetv server up and running, and was able to get to the web interface and see the devices I had put in the configuration yaml used in the firetv-server -c option.

However I never saw my devices in HA. In the process of looking through threads after getting no replies to my post here or at the github repo for firetv, I’m running out of ideas.

Sure @rpitera, let’s see what we can do.

The standalone adb is different from the Python ADB that gets installed running pip install adb. firetv-server doesn’t really use the standalone adb, just the pure Python ADB.

From what you’ve posted, it doesn’t look like your issue is in firetv-server but more on the HA side. Can you post the relevant HA configuration lines for firetv?

Well, right now I am unable to start up firetv-server. I am getting the following error:

pi@raspi1:~$ firetv-server -c firetv.yaml
Traceback (most recent call last):
  File "/usr/local/bin/firetv-server", line 11, in <module>
    load_entry_point('firetv==1.0.5', 'console_scripts', 'firetv-server')()
  File "/usr/local/lib/python2.7/dist-packages/firetv/__main__.py", line 235, in main
    _add_devices_from_config(args)
  File "/usr/local/lib/python2.7/dist-packages/firetv/__main__.py", line 224, in _add_devices_from_config
    add(device, config['devices'][device]['host'])
  File "/usr/local/lib/python2.7/dist-packages/firetv/__main__.py", line 81, in add
    devices[device_id] = FireTV(str(host))
  File "/usr/local/lib/python2.7/dist-packages/firetv/__init__.py", line 61, in __init__
    self.connect()
  File "/usr/local/lib/python2.7/dist-packages/firetv/__init__.py", line 71, in connect
    serial=self.host)
  File "/usr/local/lib/python2.7/dist-packages/adb/adb_commands.py", line 87, in ConnectDevice
    return cls.Connect(handle, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/adb/adb_commands.py", line 110, in Connect
    device_state = cls.protocol_handler.Connect(usb, banner=banner, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py", line 272, in Connect
    cmd, arg0, arg1, banner = cls.Read(usb, ['CNXN', 'AUTH'])
  File "/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py", line 215, in Read
    cmd, arg0, arg1, data_length, data_checksum = cls.Unpack(msg)
  File "/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py", line 200, in Unpack
    raise ValueError('Unable to unpack ADB command.', cls.format, message, e)
ValueError: ('Unable to unpack ADB command.', '<6I', '', error('unpack requires a string argument of length 24',))

What’s strange is that I didn’t change anything in the config and it was starting up and listing the devices before.

Try rebooting.

Which? The Pi or the FireTV devices?

Sorry this is sort of off topic. I have 2 questions:

How fast can you send commands to the fire tv with home assistant? Like could you send a direction down command 4 times very quickly or is there a lot of delay in between? I really only have use for this if it is faster than controlling it with harmony hub service calls. (which take a good entire second between commands)

Also, if anyone knows why when I try to start the fire tv server it says starting server on 0.0.0.0:5555, even though I am entering the correct IP when starting the server that would also be helpful.

@rpitera you need to reboot the Fire TV. I just added more logging to this in my fork and the Docker image will have it shortly. I need to organize a pull at some point.

@stunts1337 no idea :slight_smile: Time to test it for us! As for the 0.0.0.0 binding this is hard coded in so it listens on all interfaces on the machine you are running the python fire tv service.

I’ve rebooted everything, but the current problem is that firetv-server is failing to start.

pi@raspi1:~$ sudo systemctl status firetv.service -l
● firetv.service - Fire TV Server
   Loaded: loaded (/etc/systemd/system/firetv.service; enabled)
   Active: failed (Result: exit-code) since Tue 2017-02-21 14:57:21 EST; 24min ago
  Process: 422 ExecStart=/usr/local/bin/firetv-server -c /home/pi/firetv.yaml (code=exited, status=1/FAILURE)
 Main PID: 422 (code=exited, status=1/FAILURE)

Feb 21 14:57:21 raspi1 firetv-server[422]: add(device, config['devices'][device]['host'])
Feb 21 14:57:21 raspi1 firetv-server[422]: File "/usr/local/lib/python2.7/dist-packages/firetv/__main__.py", line 81, in add
Feb 21 14:57:21 raspi1 firetv-server[422]: devices[device_id] = FireTV(str(host))
Feb 21 14:57:21 raspi1 firetv-server[422]: File "/usr/local/lib/python2.7/dist-packages/firetv/__init__.py", line 61, in __init__
Feb 21 14:57:21 raspi1 firetv-server[422]: self.connect()
Feb 21 14:57:21 raspi1 firetv-server[422]: File "/usr/local/lib/python2.7/dist-packages/firetv/__init__.py", line 74, in connect
Feb 21 14:57:21 raspi1 firetv-server[422]: raise serr
Feb 21 14:57:21 raspi1 firetv-server[422]: socket.error: [Errno 104] Connection reset by peer
Feb 21 14:57:21 raspi1 systemd[1]: firetv.service: main process exited, code=exited, status=1/FAILURE
Feb 21 14:57:21 raspi1 systemd[1]: Unit firetv.service entered failed state.

It was working and was even showing the devices in the list in a browser. I haven’t changed anything nor have I moved or changed the config file. I’m not doing anything else with ADB on the Pi, so I don’t think anything I have installed lately would have broken a dependency. I’m stumped.