Emulated Roku for Harmony

Thanks!
Multiple return values are not unpacked when creating the server because I changed it to fix a warning. Guess the warning was wrong. Should only happen when shutting down home assistant I think.

How annoying Roku uses Play for both play and pause :anguished:

1 Like

@mindigmarton Fantastic job on this component!! Wow, seriously. This brings Harmony to the next level. Truly a must have for any Harmony user. Can’t wait for it to be merged upstream! You have created the functionality for HA users to turn their Harmony remotes into full blown HA controllers. This is even better than using emulated_hue since Harmony places the arbitrary restriction on controlling Hue devices to “home control” buttons (available only on their more expensive models, of course).

Something I found useful when setting this up that I would suggest including in the documentation:

tail -f home-assistant.log -n 0 | grep roku_command

Once the Roku is set up in Harmony app, you can trace the button presses through the Home Assistant log using the above command (this also exposes the Roku USN which is helpful for initial automations). Of course this requires setting the HA log level to INFO (include logger: in your configuration.yaml). Of most value here is the key value for each keypress.

Is there some URL that can be visited once the emulated Roku is running through HA to confirm it is running correctly? Something similar to the emulated_hue troubleshooting section.

Cheers

1 Like

Yeah, I wrote this because emulated_hue limited me to 4 buttons…

Updated the README with more instructions. You can also get the serial from Harmony (it’s case sensitive) or the Roku API reachable at the ports specified.

Pushed a new version with fixes for the errors when shutting down HASS.

2 Likes

I can confirm your fix for the shutdown errors worked perfectly :slight_smile:

I’m currently not home so I can’t test anything, but I still fiddling with some HA config… How would I go about to configure an action (Harmony Elite control) to trigger an automation in HA?

Also, can I use the color buttons on the remote? I didn’t find them in the list over compatible buttons.

Btw, before some update I saw “emulated_roku” under states, but that is gone now, why?

You configure an automation to trigger on the event that the emulated roku fires when the button is pressed on your Harmony remote. This button can be any of the buttons exposed to Roku (and is in the list of buttons from the component README). To assign the button on your remote you do that from the Harmony app or software and map it to the button on the emulated roku that you configured your automation to listen to.

1 Like

Unfortunately you cannot use the “Home Control” buttons as they are reserved for smart device integrations such as Hue.
For that, you can use emulated_hue.

You probably saw the roku because you had autodiscovery on or the Roku component configured and HASS discovered the emulated_roku :slight_smile:

You can, make sure they’re unassigned in the home control section and then they become available as normal buttons, I control a standalone IR dimmer with one of mine.

1 Like

Can someone explain what the app_id is and how to use it?

It’s the same things as normal keys basically, you shouldn’t need it unless you have a remote that can launch apps.
That said, Harmony can’t launch apps on Roku over WiFi. I think it uses IR for that.

The Home Control buttons are not available for me in the Activity Control Buttons menu with the Hub’s Companion remote. Can only use them when I add Hue…

This is how it looks for me.

I’ve got the 950 like @ZyberSE so I guess it may just be a limitation of the Companion.

Well I still get an error that the component could not be setup. What am I doing wrong

emulated_roku:
  host_ip: http://192.168.1.173
  upnp_bind_multicast: True
  listen_ports:
    - 8060

Unable to find component emulated_roku

Host ip should be just the IP without the http:// part.
Have you copied the emulated_roku.py file to the custom_components folder?

1 Like

Thx that did the trick… I now dont get any errors on the log, but when i visit http://192.168.1.173:8060 i get nothing and the roku is not discoverable in the hamony app. I cant seem to find any roku device in the entities list in HA

The roku component should only exist if you have configured media_player.roku in HASS.
Do you see “Initializing emulated roku” and “Intializing emulated roku 192.168.1.173:8060” in the logs?

Hmm…
I saw this error in the detailed logs

File “/config/custom_components/emulated_roku.py”, line 1

^
SyntaxError: invalid syntax

EDIT:
the wrong file was copied.
I now have the right file but i get the following error

Error during setup of component emulated_roku
Traceback (most recent call last):
File “/usr/lib/python3.6/site-packages/homeassistant/setup.py”, line 190, in _async_setup_component
result = yield from component.async_setup(hass, processed_config)
File “/usr/lib/python3.6/asyncio/coroutines.py”, line 210, in coro
res = func(*args, **kw)
File “/config/custom_components/emulated_roku.py”, line 57, in async_setup
from emulated_roku import RokuCommandHandler, make_roku_api
ModuleNotFoundError: No module named ‘emulated_roku’

EDIT 2: after a second restart it worked! Thx for your support

Yes, I’m using HASS.io v0.60 and I got this same error when I initially tried loading the custom component. As mentioned in this thread, simply restarting the HomeAssistant service from the Configuration tab on the left didn’t work, however, restarting HASS.io from the HASS.io tab did work . . . it perhaps does a more complete reboot of Docker container (not sure).

AWESOME, the custom component is quite brilliant, and working very well for me using Hass.IO v0.60! Now my Harmony can correctly turn on “Movie Scene” and “Movie Paused Scene” on demand!

These scenes in turn work amazingly well with the Lutron Caseta Pro custom component here!, and other Z-Wave lamps!

I sure hope these two great components become part of the HomeAssistant core soon . . . they have provided the most stable automation between Harmony, theater, and lights I’ve ever been able to achieve.

It would be great however if the documentation for the Emulated_Roku on GitLab could be updated with details about how the App Launch functionality does not work with Harmony – I lost alot of time trying to understand this and, finally discovering that it doesn’t work (and now the comments above make sense).

Others may also find it useful to know that the easiest way I found to Debug this component was to create an automation that pipes the data into a Python Script. This allows you to then log to the console, or send a notification via pushover, with data details as buttons are pressed. Python Scripts support dynamic changes, so you can just edit it live and retest without reloading HomeAssistant, which was wayyy easier than working with unique automations.

Here’s my Proxy Automation:

  #Proxy the Emulated Roku Data into our Python Script for Automation!
  - alias: Emulated Roku Event Trigger
    hide_entity: True
    trigger:
      platform: event
      event_type: roku_command
      #NOTE: FutureFiltering to separate python script automations by USN could be enabled by filtering via USN value here...
      #event_data:
      #  roku_usn: {ROKU USN}
    action:
      - service: python_script.emulated_roku
        #BBernard - 01/04/2018
        #NOTE: Pass in key data to the Python Script where Debugging is significantly easier because Python Scripts support dynamic reloading!
        data_template:
          roku_usn: "{{ trigger.event.data.roku_usn }}"
          type: "{{ trigger.event.data.type }}"
          key: "{{ trigger.event.data.key }}"

And here’s the beginning of the Python script snippet to support debugging outputs:

#Initialize the event data passed to the Script!
#TEST NOTE: Roku buttons can be tested via RESTFul POST calls to: 192.168.1.10:8060/keypress/{key}
#			For Example to test 'Back': 192.168.1.10:8060/keypress/Back
roku_usn = data.get("roku_usn", "UNDEFINED")
roku_cmd_type = data.get("type", "UNDEFINED")
roku_cmd_key = data.get("key", "UNDEFINED")

#Log the Event to the Log for Debugging (temporarily)
hass.services.call("notify", "pushover", {"message": "Roku Command Event [roku_usn={0}] [type={1}] [key={2}]".format(roku_usn, roku_cmd_type, roku_cmd_key)})
logger.error("EMULATED ROKU DEBUG - Command Event [roku_usn=%s] [type=%s] [key=%s]", roku_usn, roku_cmd_type, roku_cmd_key)

Note the use of logger.error() above, this is for temporary debugging so you don’t have to set your HASS log level to Info and restart, etc. You can comment out the line in the Script at any time and save it, and no restart of HomeAssistant is necessary.

Finally, if just debugging your automations and you don’t want to have to keep pressing the buttons on your Harmony (for me this saved me from running up and down 2 flights of stairs for every test), you can use the REST api for the Roku to trigger keypresses to test the HomeAssistant automations directly.

Testing automations via RESTFul API:
To test the automation when “Down” button is pressed you can just use PostMan to send a POST with the following url:

#TEST NOTE: Roku buttons can be tested via RESTFul POST calls to: http://{IP_ADDRESS}:8060/keypress/{key}
#			For Example to test 'Back': http://{IP_ADDRESS}/keypress/Back
POST:  http://{IP_ADDRESS}:8060/keypress/Down
1 Like

Hello and thank you very much, this tool looks really Amazing.

My main goal with it is to be able to switch between 3 light scenes and 4 automations when i’m running and leaving one activity.

  • 3 scenes with lights: full, dim and off
  • activity home-cinéma with 4 automations: start activity(dim), play(off), back(dim), stop activity(full).

Scenes and automations buttons are visible on the main screen and can all be triggered.

I am complete noob on home assistant, just installed the “0.60.1” version 2 days ago on my synology nas using docker.
I can visit the “http://myip:8060/” page, I linked the emulated roku to the Official Android app.
The big problem is harmony app is not finding the roku. From Phone, tablet or even pc, nothing works. I also tried to change my wifi security without success.

Any kind of help will be really appriciated.

Thanks