How I remotely control my Fire TV with the Mosquitto MQTT, AppDaemon, and Android TV addons

I wanted to use a TV remote and optionally a Web app to remotely control, from other rooms, my home devices that are connected to my home-assstant hub. I prefer using physical remotes over phone apps because I like the tactile feeling and haptic feedback they provide.

There are multiple ways to do this, including using the Hass Rest API or the Hass WebSocket API or a roll your own integration. There are other ways too, but not all listed here

With some home-assistant experience and study, I decided to use MQTT because I read its an easy, fast, reliable lightweight way to transport data over the net. Plus I’ve never used MQTT and thought it would be learning fun. :slight_smile:

I also decided to use AppDaemon as my remote control proxy, because its a powerful and flexible way to control the home-assistant hub using regular Python with its included api plugins.

My first basic use case to solve with this project:

Press power key on remote
==>Capture key press data on PI4, located in same room
====>Ship key press data to home-assistant hub via MQTT message
======>Use key press data to start home-assistant service and turn on Fire TV (or other devices)

For this project I bought a MINIX usb wireless remote:


Also bought a PI4b to capture remote key presses:


I own an Insignia Fire TV


Basic Steps Performed:

  • Install headless version of raspbian on my PI4b. Plugged in remote’s usb dongle

  • Installed AppDaemon, Mosquito MQTT addons via home-assistant supervisor

  • Modified home-assistant config.yaml file to enable Android TV integration

  • Created a Python script to capture remote key presses via usb with Python evdev package

  • Created node.js script to recieve captured key press data from Python script and forward it to the Mosquito MQTT Broker via the node.js MQTT-Client module to publish a MQTT message

  • Created an AppDaemon app to listen for the MQTT messages sent to Mosquitto broker and in turn use the home-assistant api plugin to start a home-assistant service to turn on the FireTV.

After I got the first use case working, it was easy to use the remote to control my sonos sound, control my fireplace and blinds.

I’ve also created a simple html page that sends simulated key press data to my node.js script (server) and can control all the same stuff as the remote.

This post is very light on detail, but happy to share all on request. You can review/use any of my code as desired: (note: code uses hardcoded url’s that would need to be changed for your lan)

NOTE: Since writing this, I discovered that Mosquito MQTT doesn’t support MQTT over websockets, so I’m unable to connect a browser to the Mosquito Broker. :frowning:

So subsequently Ive dumped MQTT in favor of using straight websockets, after I discovered a slick trick to emulate MQTT messages by using the hassio SCRIPTS Integration to generate custom events with data.

So I’m still using the same conccept described here, but using websockets instead of MQTT