Emulated Roku for Harmony


I saw this error in the detailed logs

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

SyntaxError: invalid syntax

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
      platform: event
      event_type: roku_command
      #NOTE: FutureFiltering to separate python script automations by USN could be enabled by filtering via USN value here...
      #  roku_usn: {ROKU USN}
      - 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!
          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:{key}
#			For Example to test '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


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.




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

 - alias: 'PC play started from harmony hub'
     - platform: event
       event_type: roku_command
         roku_usn: syKCCvQcdZGZ7tdw27qyZX
         type: keypress
         key: Play
     service: scene.turn_on
     entity_id: scene.livingroom_off
 - alias: 'PC stop started from harmony hub'
     - platform: event
       event_type: roku_command
         roku_usn: syKCCvQcdZGZ7tdw27qyZX
         type: keypress
         key: Back
     service: scene.turn_on
     entity_id: scene.livingroom_dim
 - alias: 'Play harmony'
     - platform: event
       event_type: roku_command
         roku_usn: syKCCvQcdZGZ7tdw27qyZX
         type: keypress
         key: Play
     service: remote.send_command
     entity_id: remote.Harmony_Hub
       device: "50272082"
       command: "Play"
 - alias: 'Back harmony'
     - platform: event
       event_type: roku_command
         roku_usn: syKCCvQcdZGZ7tdw27qyZX
         type: keypress
         key: Back
     service: remote.send_command
     entity_id: remote.Harmony_Hub
       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.


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 !


Just wanted to send a big thank you for the work.
This works perfect so far and fixed the annoying issue of being able to pause chromecast from the remote.

Using Hassio


I am getting following error, windows 10. Any help appreciated!

2018-02-02 07:39:45 ERROR (MainThread) [homeassistant.core] 
Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "c:\program files\python36\lib\asyncio\tasks.py", line 180, in _step
result = coro.send(None)
  File "C:\Users\Tom\AppData\Roaming\.homeassistant\custom_components\emulated_roku.py", line 127, in start_emulated_roku
discovery_server, _ = yield from discovery_endpoint
  File "c:\program files\python36\lib\asyncio\base_events.py", line 939, in create_datagram_endpoint
sock, protocol, r_addr, waiter)
  File "c:\program files\python36\lib\asyncio\base_events.py", line 323, in _make_datagram_transport
raise NotImplementedError

My config.yaml:

  upnp_bind_multicast: True
    - 8060

I also changed to upnp_bind_multicast: False and similar error.


It looks like Home Assistant uses ProactorEventLoop on Windows which does not support UDP sockets. (same issue as in the LIFX component)
Updated the README noting that Windows is not supported, sorry.

You can run emulated_roku as a standalone python cli app with the default python event loop, though you’ll need to do some coding to forward key presses to Home Assistant.

Home Assistant - Homebridge-Alexa (for Alexa)/Emulated Hue (for Harmony Hub) - Doubling up - please help!

Thanks for the update.



Any progress here with regards to getting it accepted as an integrated component?


No, the component required Python 3.5.4 on windows because of some UDP connection parameters, and HASS’s python version didn’t have it.
Though now that it doesn’t work at all on Windows like the LIFX component I guess we can ignore that.
Didn’t have time to work on the docs either, but that shouldn’t take long…


I just tried to install emulated roku on 0.64.2 and received the following error,

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/lib/python3.5/asyncio/tasks.py”, line 241, in _step
result = coro.throw(exc)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/setup.py”, line 57, in async_setup_component
return (yield from task)
File “/usr/lib/python3.5/asyncio/futures.py”, line 380, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.5/asyncio/tasks.py”, line 304, in _wakeup
File “/usr/lib/python3.5/asyncio/futures.py”, line 293, in result
raise self._exception
File “/usr/lib/python3.5/asyncio/tasks.py”, line 239, in _step
result = coro.send(None)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/setup.py”, line 104, in _async_setup_component
component = loader.get_component(domain)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/loader.py”, line 142, in get_component
module = importlib.import_module(path)
File “/usr/lib/python3.5/importlib/init.py”, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 986, in _gcd_import
File “”, line 969, in _find_and_load
File “”, line 958, in _find_and_load_unlocked
File “”, line 673, in _load_unlocked
File “”, line 669, in exec_module
File “”, line 775, in get_code
File “”, line 735, in source_to_code
File “”, line 222, in _call_with_frames_removed
File “/home/homeassistant/.homeassistant/custom_components/emulated_roku.py”, line 1

SyntaxError: invalid syntax

If anyone could help me, that would be amazing, this is high on the WAF score!!


Post your config and someone could probably work out what’s wrong.


Here is what I have in my config:

- 8060

I have a manual install with a virtual environment. I tried to access at port 8060, but it didn’t connect. All I did was place the emulated_roku.py in my custom_component file

Edit: I have discovery enabled and I included roku in my media platform section. Is there any order of operations to getting the component to work? Does harmony need to discover it first before hass? very confused with this one. I am on Stretch btw


It looks like python can’t even load the file. Are you sure the contents are correct?


By contents, do you mean the emulated_roku.py? I downloaded it directly from the github, but I could try downloading the whole package and extracting the py file?


Was just coming on to suggest trying that, I’ve seen people caught before with Github, right clicking on the file name and thinking they’ve downloaded the file but in reality have downloaded an html file of the webpage it links to.