Previous project developments have heavily focused on physical hardware prototyping of a keyboard and motion-based remote controller. One of the tasks that haven't been explored in depth is the peripheral digital devices that we can control with our prototypes. We have discussed some ways to control a Roku media player as a proof-of-concept starting point and in this log, I will detail one method using an ESP32 microcontroller through Home Assistant to emulate a Roku remote.
Simple ESP32 Keyboard
While we are working on a more developed keyboard prototype, I created a low-fidelity one for the purposes of debugging. This is shown below. It is 8 tactile switches connected to an input pin on the controller. The uploaded sketch publishes a message (UP, DOWN, HOME, etc.) to an MQTT broker, which will be used as a trigger to perform an action on the Roku.
Home Assistant on a Raspberry Pi
There are many possibilities on how we can communicate from a microcontroller to the Roku. I chose to use Home Assistant because it was simple to setup, easy to learn, and has integrations with the majority of smart devices. This last point is important because it makes it easy to translate from controlling a Roku to controlling another device like an Amazon Echo or Google Nest.
The setup to install Home Assistant on a Raspberry Pi was followed from the Home Assistant website. After, the Roku and MQTT broker integrations were setup for this specific example.
The next step was to establish a connection between Home Assistant to the Roku media player. Tests scripts were written where a button on the Home Assistant dashboard could be used to send Roku commands.
Once that was done, the ESP32 microcontroller needed to send messages to Home Assistant. With the MQTT broker configured, short messages were published to HA, which could be seen from the Home Assistant dashboard.
Finally, an automation routine was written to combine the trigger from the microcontroller and to perform actions on the Roku media player. Two simple automation scripts are shown below.
The video below shows the ability to use the 8 buttons to emulate Roku remote to control a Roku media player.