Emulated Roku for Harmony

I get this is 58.1 hass.io

2017-11-26 17:41:47 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "uvloop/loop.pyx", line 2448, in uvloop.loop.Loop.create_datagram_endpoint (uvloop/loop.c:44337)
  File "uvloop/handles/udp.pyx", line 117, in uvloop.loop.UDPTransport._bind (uvloop/loop.c:103378)
OSError: [Errno 98] Address in use

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.6/asyncio/tasks.py", line 179, in _step
    result = coro.send(None)
  File "/config/custom_components/emulated_roku.py", line 100, in start_emulated_roku
    discovery_server, _ = yield from discovery_endpoint
  File "uvloop/loop.pyx", line 2459, in create_datagram_endpoint (uvloop/loop.c:44639)
OSError: could not bind to local_addr ('0.0.0.0', 1900)

Are you putting this directly down to your component?

So this is the weirdness I was talking about… On windows where I was testing portability, python has reuse_address=True parameter for asyncio datagram sockets, but I couldn’t do the same on linux because the python version was lagging behind. Now that hassio has an updated python I think the if branch can be removed. (resinio uses multicasting so the port must be reused)

Well, wifi is pretty weak in my room (I have a tp-link switch which keeps filling the HASS logs with communication errors) and I don’t think the Harmony Hub handles such errors gracefully, thus freezing the whole thing. I’ve tested scenarios where I’ve killed HASS while I was using Harmony and it handled that fine, so I don’t think any errors in the emulated roku implementation could bring the Harmony Hub down.

Edit: I’ll try to push an updated version tonight.

1 Like

Sounds good, look forward to it, thank you.

Made some changes, should work properly now :slight_smile:
Also added some new options:

  • upnp_bind_multicast
  • updated advertise_* properties to be consistent with emulated_hue (and allow multiple ports to be aliased)
2 Likes

Looking good, no errors and set up device in Harmony without issue.

Will try setting up some commands tomorrow.

Many thanks for the update :+1:

All working perfectly, thanks again.

I literally just used the example from the readme and tweaked the serial for what was shown in Harmony at set up. Then just change names to whatever you want, pick a key, assign any service you have set up in HA and that’s it.

It just feels a little weird at first because you use automations as the middle man.

Where did the code you posted come from?

That was just the device info HA showed when I clicked it :slight_smile:

How do I update, just copy paste the new code or do I need to do something else?
Thanks for you effort updating the component :+1:

Download the component again and overwrite the existing one in the custom_components folder is all I did.

Not come across this, where are you clicking?

Any plans on pushing this upstream?

Click the emulate_roku under dev-states.

1 Like

Should only show in dev-state when you have a autodiscovery or the roku component enabled. (basically hass discovers itself…)

I’ll open a PR when I get around making a dev env.

Also, Android remotes don’t auto discover the emulated roku server which I don’t quite understand. Perhaps something is wrong with the model number, etc in the response template. (I’d like to be as compatible with the original API as possible)

1 Like

Should host_ip be set to the hass servers ip?

Essentially, yes.
By default it binds to 0.0.0.0 and it advertises that, which won’t work from outside.

Alternatively, you can set advertise_ip if you need host_ip to bind to all or another interface (like docker)

Ahh…I don’t have the component enabled and I killed discovery five minutes after first using HA as all I got out of it was loads of ongoing errors in the log from devices I had no interest in.

Is there any advantage to enabling the component if you don’t have a real one and want to control it.

Would you happen to have a list of the key names that work as the names Harmony uses don’t work eg in your example you use Fwd which works perfectly but FastForward as Harmony itself calls it doesn’t. This is the full list of Harmony names…

PowerOn
DirectionDown
DirectionLeft
DirectionRight
DirectionUp
Select
Play
Rewind
Pause
FastForward
Back
Search
Sleep
Info
PageDown
PageUp
Exit
Netflix
Pandora
Amazon
Crackle
HBONow 
Home
Hulu
InstantReplay
MGO
Options*
Showtime
SlingTv
Vudu

The library just forwards what it receives as a parameter, doesn’t do any filtering, etc.

Though Hulu and others are not key presses so those won’t work.