Emulated Roku for Harmony

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

#SOLVED

Here is the code for the 4 automations needed with forwarded roku buttons from harmony

 - alias: 'PC play started from harmony hub'
   trigger:
     - platform: event
       event_type: roku_command
       event_data:
         roku_usn: syKCCvQcdZGZ7tdw27qyZX
         type: keypress
         key: Play
   action:
     service: scene.turn_on
     entity_id: scene.livingroom_off
 - alias: 'PC stop started from harmony hub'
   trigger:
     - platform: event
       event_type: roku_command
       event_data:
         roku_usn: syKCCvQcdZGZ7tdw27qyZX
         type: keypress
         key: Back
   action:
     service: scene.turn_on
     entity_id: scene.livingroom_dim
 - alias: 'Play harmony'
   trigger:
     - platform: event
       event_type: roku_command
       event_data:
         roku_usn: syKCCvQcdZGZ7tdw27qyZX
         type: keypress
         key: Play
   action:
     service: remote.send_command
     entity_id: remote.Harmony_Hub
     data:
       device: "50272082"
       command: "Play"
 - alias: 'Back harmony'
   trigger:
     - platform: event
       event_type: roku_command
       event_data:
         roku_usn: syKCCvQcdZGZ7tdw27qyZX
         type: keypress
         key: Back
   action:
     service: remote.send_command
     entity_id: remote.Harmony_Hub
     data:
       device: "50272082"
       command: "Back"

Hello, can you please tell me how did you get the Harmony app to finally discover the emulated roku?
I’am stuck on this part and it’s really frustarting.
Thanks

You go to add new device and then scan for WiFi devices

Thank you for your kind response.

For everyone knowledge, it was a real pain to get the emulated roku to be discovered by my synology nas.

I solved it disconecting every wifi devices in my home, hue, ipad, phone, tv etc… and rebooting my home assistant on docker. After many reboots it finaly works.

Thanks for the work this emulated roku is DOPE !