Emulated Roku for Harmony

Aha - Restared HA this it seems Roku is throwing an error:

RokuError

Drill into it and I can see this:

Fri Mar 29 2019 10:19:24 GMT+0000 (Greenwich Mean Time)
Error doing job: Future exception was never retrieved
Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/urllib3/connection.py”, line 159, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File “/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py”, line 80, in create_connection
raise err
File “/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py”, line 70, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py”, line 600, in urlopen
chunked=chunked)
File “/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py”, line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File “/usr/local/lib/python3.7/http/client.py”, line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File “/usr/local/lib/python3.7/http/client.py”, line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File “/usr/local/lib/python3.7/http/client.py”, line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File “/usr/local/lib/python3.7/http/client.py”, line 1016, in _send_output
self.send(msg)
File “/usr/local/lib/python3.7/http/client.py”, line 956, in send
self.connect()
File “/usr/local/lib/python3.7/site-packages/urllib3/connection.py”, line 181, in connect
conn = self._new_conn()
File “/usr/local/lib/python3.7/site-packages/urllib3/connection.py”, line 168, in _new_conn
self, “Failed to establish a new connection: %s” % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x6cf3a3f0>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/requests/adapters.py”, line 449, in send
timeout=timeout
File “/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py”, line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File “/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py”, line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host=‘192.168.2.170’, port=8060): Max retries exceeded with url: /query/device-info (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x6cf3a3f0>: Failed to establish a new connection: [Errno 111] Connection refused’))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/lib/python3.7/concurrent/futures/thread.py”, line 57, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/local/lib/python3.7/site-packages/homeassistant/components/roku/init.py”, line 51, in roku_discovered
CONF_HOST: info[‘host’]
File “/usr/local/lib/python3.7/site-packages/homeassistant/components/roku/init.py”, line 100, in _setup_roku
r_info = roku.device_info
File “/usr/local/lib/python3.7/site-packages/roku/core.py”, line 213, in device_info
resp = self._get(’/query/device-info’)
File “/usr/local/lib/python3.7/site-packages/roku/core.py”, line 172, in _get
return self._call(‘GET’, path, *args, **kwargs)
File “/usr/local/lib/python3.7/site-packages/roku/core.py”, line 189, in _call
resp = func(url, *args, **kwargs)
File “/usr/local/lib/python3.7/site-packages/requests/sessions.py”, line 546, in get
return self.request(‘GET’, url, **kwargs)
File “/usr/local/lib/python3.7/site-packages/requests/sessions.py”, line 533, in request
resp = self.send(prep, **send_kwargs)
File “/usr/local/lib/python3.7/site-packages/requests/sessions.py”, line 646, in send
r = adapter.send(request, **kwargs)
File “/usr/local/lib/python3.7/site-packages/requests/adapters.py”, line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host=‘192.168.2.170’, port=8060): Max retries exceeded with url: /query/device-info (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x6cf3a3f0>: Failed to establish a new connection: [Errno 111] Connection refused’))
Connection lost. Reconnecting…

The error is from the roku component trying to connect to the emulated_roku. I guess it finds it via autodiscovery (UPNP) then tries to connect, but the port isn’t open?
First and foremost, you should be able to access it via <hass address>:8060. If that doesn’t work, UPNP discovery for Harmony won’t work either. (which is another thing that people have problems with, but there are workarounds on the component page)

There might be some other errors in the log preventing emulated_roku to bind to port 8060.

<hass address>:8060 in a browser also gives connection refused. I just upgraded to the latest stable version of HA so my full log is quite short, and I am not seeing anything other then the Roku error itself.

The odd Hue and TPLink errors are to be expected - they represent devices in Config that are not currently plugged in!

019-03-29 11:05:16 WARNING (MainThread) [homeassistant.loader] You are using a custom component for huesensor.device_tracker which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-03-29 11:05:16 WARNING (MainThread) [homeassistant.loader] You are using a custom component for huesensor.sensor which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-03-29 11:05:16 WARNING (MainThread) [homeassistant.loader] You are using a custom component for huesensor.binary_sensor which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-03-29 11:05:19 WARNING (MainThread) [homeassistant.components.hue] Connected to Hue at 192.168.2.147 but not registered.
2019-03-29 11:05:19 ERROR (SyncWorker_8) [homeassistant.components.tplink] Unable to connect to device 192.168.2.177: Communication error
2019-03-29 11:05:19 WARNING (MainThread) [homeassistant.components.hue] Connected to Hue at 192.168.2.147 but not registered.
2019-03-29 11:05:19 ERROR (Thread-2) [pychromecast.socket_client] [AFTN-158:8010] Exception caught while sending message to controller ReceiverController: Message urn:x-cast:com.google.cast.receiver from receiver-0 to sender-0: {‘requestId’: 1, ‘status’: {‘applications’: [], ‘isActiveInput’: True, ‘volume’: {‘controlType’: ‘attenuation’, ‘level’: 1, ‘muted’: False, ‘stepInterval’: 0.05}}, ‘type’: ‘RECEIVER_STATUS’}
Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/pychromecast/socket_client.py”, line 563, in _route_message
message, data)
File “/usr/local/lib/python3.7/site-packages/pychromecast/socket_client.py”, line 889, in receive_message
self._process_get_status(data)
File “/usr/local/lib/python3.7/site-packages/pychromecast/socket_client.py”, line 1019, in _process_get_status
status = self._parse_status(data, self.cast_type)
File “/usr/local/lib/python3.7/site-packages/pychromecast/socket_client.py”, line 997, in _parse_status
app_data = data[‘applications’][0]
IndexError: list index out of range
2019-03-29 11:05:19 ERROR (MainThread) [homeassistant.components.device_tracker] Unable to load /config/known_devices.yaml: Config file not found: /config/known_devices.yaml
2019-03-29 11:05:22 ERROR (SyncWorker_8) [homeassistant.components.tplink] Unable to connect to device 192.168.2.178: Communication error
2019-03-29 11:05:25 ERROR (SyncWorker_8) [homeassistant.components.tplink] Unable to connect to device 192.168.2.179: Communication error
2019-03-29 11:05:28 ERROR (SyncWorker_8) [homeassistant.components.tplink] Unable to connect to device 192.168.2.181: Communication error
2019-03-29 11:05:50 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/urllib3/connection.py”, line 159, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File “/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py”, line 80, in create_connection
raise err
File “/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py”, line 70, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py”, line 600, in urlopen
chunked=chunked)
File “/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py”, line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File “/usr/local/lib/python3.7/http/client.py”, line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File “/usr/local/lib/python3.7/http/client.py”, line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File “/usr/local/lib/python3.7/http/client.py”, line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File “/usr/local/lib/python3.7/http/client.py”, line 1016, in _send_output
self.send(msg)
File “/usr/local/lib/python3.7/http/client.py”, line 956, in send
self.connect()
File “/usr/local/lib/python3.7/site-packages/urllib3/connection.py”, line 181, in connect
conn = self._new_conn()
File “/usr/local/lib/python3.7/site-packages/urllib3/connection.py”, line 168, in _new_conn
self, “Failed to establish a new connection: %s” % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x6f4cc9b0>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/requests/adapters.py”, line 449, in send
timeout=timeout
File “/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py”, line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File “/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py”, line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host=‘192.168.2.170’, port=8060): Max retries exceeded with url: /query/device-info (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x6f4cc9b0>: Failed to establish a new connection: [Errno 111] Connection refused’))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/lib/python3.7/concurrent/futures/thread.py”, line 57, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/local/lib/python3.7/site-packages/homeassistant/components/roku/init.py”, line 51, in roku_discovered
CONF_HOST: info[‘host’]
File “/usr/local/lib/python3.7/site-packages/homeassistant/components/roku/init.py”, line 100, in _setup_roku
r_info = roku.device_info
File “/usr/local/lib/python3.7/site-packages/roku/core.py”, line 213, in device_info
resp = self._get(’/query/device-info’)
File “/usr/local/lib/python3.7/site-packages/roku/core.py”, line 172, in _get
return self._call(‘GET’, path, *args, **kwargs)
File “/usr/local/lib/python3.7/site-packages/roku/core.py”, line 189, in _call
resp = func(url, *args, **kwargs)
File “/usr/local/lib/python3.7/site-packages/requests/sessions.py”, line 546, in get
return self.request(‘GET’, url, **kwargs)
File “/usr/local/lib/python3.7/site-packages/requests/sessions.py”, line 533, in request
resp = self.send(prep, **send_kwargs)
File “/usr/local/lib/python3.7/site-packages/requests/sessions.py”, line 646, in send
r = adapter.send(request, **kwargs)
File “/usr/local/lib/python3.7/site-packages/requests/adapters.py”, line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host=‘192.168.2.170’, port=8060): Max retries exceeded with url: /query/device-info (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x6f4cc9b0>: Failed to establish a new connection: [Errno 111] Connection refused’))

The emulated_roku correctly starts up as it looks like it’s advertising the 8060 port via UPNP (roku component finds it) and that should mean it’s available at 8060. (if any error happens when binding the HTTP port the UPNP advertising shuts down too)

Do you use the hassio OS or the hassio docker container on a generic linux host?
If you’re using hassio OS, and it’s not working, the problem is probably with your router’s network configuration.
On generic linux, you might have to use docker host networking, expose docker ports or open the ports with firewalld, etc.

I use Hassio

Not sure why the router would be an issue. I have a big internal network and am always running services up and down of different machines on different ports - all of which work - ie I have nothing set up on my internal network to prevent any kind of port connection.

Accessing the emulated roku directly by IP and port doesn’t work, and I can see in the HA log that it tries the same thing and fails there too. (Last two entries in the log I posted previously)

If anyone can suggest anything I might try, I’d be grateful.

PS Emulated Hue works just fine, if that sheds any additional light. The problem is I already have a Hue hub so cannot connect Emulated Hue to Harmony!

I originally posted this question here, but since there appears to be more activity here, I will try here also.

I want to add the emulated_roku component, but in the documentation, there is a warning stating the below information:

This component opens an unauthenticated API on the host, allowing anything on the local network to access your Home Assistant instance through the automations you create with emulated Roku as the trigger. Using a proxy with whitelisted IP addresses is recommended. (set advertise_ip to the proxy’s ip or DNS name)

What exactly does this mean and how do I configure this proxy so I keep my HA safe and secure?

Anyone know how to setup the emulated_roku component securely?

Hi,

After initialization of Emulated Roku (through integrations or configuration.yaml) I do have following error.
I’m using Hass.io on Rpi 3

Failed to start Emulated Roku Home Assistant 2 on 192.168.0.148:14

Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/homeassistant/components/emulated_roku/binding.py”, line 112, in emulated_roku_start
await self._api_server.start()
File “/usr/local/lib/python3.7/site-packages/emulated_roku/init.py”, line 424, in start
reuse_address=True)
File “uvloop/loop.pyx”, line 2946, in create_datagram_endpoint
File “uvloop/loop.pyx”, line 2931, in uvloop.loop.Loop.create_datagram_endpoint
OSError: [Errno 98] Address in use

Anybody know how to overcome it?

Hey, I got this all set up in Hassio and it’s working really well. However, I am limited to the keypress actions and can’t figure out how to use the ‘launch’ event type. I’ve assigned a button to Netflix in the phone app, but Home Assistant isn’t picking up any signal from the remote. Can anyone point me in the right direction?

For example I use traefik reverse proxy on the same machine (nginx works too) so roku.[my-dns-name].org is an alias for <home-assistant-ip>:8060. Home Assistant and emulated_roku listens on 127.0.0.1, so it’s only accessible via the reverse proxy. (or other local processes, depends on how you configured docker networking)
I configured traefik so only Harmony’s IP is white-listed, all others are blocked.

In Home Assistant, I use this config for emulated_roku:
advertise_ip: roku.[my-dns-name].org
advertise_port: 80
listen_port: 8060
host_ip: 127.0.0.1

Yeah, Harmony uses IR for launch instead of the WIFI API, so it doesn’t work.

From the docs:

Harmony cannot launch apps as it uses IR instead of the WiFi API and will not display the custom dummy app list.

I understand that I can’t actually launch an app. However, the Emulated Roku component page says that I should be able to access the ‘launch’ activity and 10 dummy apps. I’m wondering if the process is different for being able to use those commands instead of keypress commands. Maybe I am misunderstanding the documentation?

Harmony can only use the keypress event, it cannot use the ‘launch’ event or the 10 dummy apps.
That means you can’t use the ‘Netflix’ command from the phone app, as it uses IR instead of the WIFI API.

Okay, thank you for the reply. They should just remove any mention of the ‘launch’ event from the component page because that is very confusing.

I’m new to Home Assistant, and getting this component working is the whole reason I’m trying it. I’m stuck however, in that my Harmony Hub cannot discover the Emulated Roku component. I’m running Home Assistant on Raspberry Pi, and I’ve installed the Emulated Roku component with the intent of having buttons on the Harmony remote activate Lutron Caseta Scenes. Home Assistant itself can successfully trigger the Scenes from the GUI on the Overview page. When I manually browse to the Home Assistant IP on port 8060, I do get a page with what I’m assuming is the correct text string for Emulated Roku. However, when I have my Harmony try to discover it, it fails to. So it seems like I’ve got the beginning (the Emulated Roku component installed) and the end (the Caseta Scenes in Home Assistant), but I can’t tie them together yet. I’ve seen the posts on here referring to logs, but I can’t find any logs that look like what people are posting. I’d welcome any help.

question:
i am using the roku integration for controlling volume (via a dedicated harmony activity using specific key presses as harmony remote Volume + and Volume - buttons cannot be assigned), however roku is not recognized within the harmony configuration as a device that can change volume for a specific device. is this normal? or is there a fix to that?

Since I upgraded my network I can’t find the emulated Roku within the Harmony.
I run home assistant in a VM with Docker and forwarded the ports. I can access the roku page via ip-of-home-assistant:8060 and can see the details there.
My Harmony Hub and the Home Assistant Server are on a separate VLAN and they are able to communicate, I was able to connect the Harmony to Home Assistant. I enabled UPnP, but my Harmony won’t find the Roku.

My config:

emulated_roku:
servers:
- name: Roku Emu
listen_port: 8060
host_ip: ip_of_vm
advertise_ip: ip_of_home_assistant_server
advertise_port: 8060

I don’t know what I’m missing here.

The easiest solution is to run the advertise.py script on a PC on the same VLAN as Harmony as mentioned in this post:

I wanted to try this as well, however if I go to ip-of-homeassistant:8060, in the section serial number it only says “Roku Emu” and in the section “udn” it says “uuid:some-numbers-and digits”, but the number doesn’t look like a serial number (in the past it was different, not connected with dashes and without uuid: in the front. I can post some screenshots in the evening if this helps.

“Roku Emu” is fine. It used to be generated, now the USN is the “name” config.

1 Like