Roku frequent API error

I’m getting the following error in my logs fairly frequently (several times a day):

2021-05-18 08:24:46 ERROR (MainThread) [homeassistant.components.roku] Error fetching roku data: Invalid response from API: Timeout occurred while connecting to device
2021-05-18 10:28:39 ERROR (MainThread) [homeassistant.components.roku] Error communicating with API: Timeout occurred while connecting to device
2021-05-18 10:28:39 ERROR (MainThread) [homeassistant.components.roku] Error communicating with API: Timeout occurred while connecting to device
2021-05-18 10:28:39 ERROR (MainThread) [homeassistant.components.roku] Invalid response from API: ('HTTP 503', {'content-type': '', 'message': '', 'status-code': 503})
2021-05-18 10:28:39 ERROR (MainThread) [homeassistant.components.roku] Invalid response from API: ('HTTP 503', {'content-type': '', 'message': '', 'status-code': 503})

We have three Rokus that are setup through the integration, and they are all different models at this point. Anyone have any idea how to track down the mis-behaving Roku or how to squelch the issue? I’m up to date on all HA updates, and run Hass OS on a RPi 4.

Thanks for any feedback/suggestions!

I’m experiencing this issue as well. I do have some night/away automations that automatically turn off my Roku TVs, and I’ve found that almost all of my timeout errors occur immediately after these automations run. I haven’t done any real debugging on this, but I wonder if something happens on the Roku side when transitioning power states, where it momentarily stops responding. Not sure if you have anything similar or can determine if yours are somehow also related to power on/off events (either manual or automations).

Mine is similar, except I have a variety of ROku boxes (ranging from a bit dated to a brand new one) - they throw this error when I close things up - either automating the app selection (Plex, Pandora, etc) or sending the unit to Home for the night. Interestingly, the automations all seem to work (the box goes to the app or Home as expected).

1 Like

Same errors here after automation to turn off Roku TV.

I finally got around to doing a bit more debugging. The error is being thrown whenever remote.turn_off is called with the device already in the off state. I’m not well-versed in Python, but I was able to get a local dev instance running and saw that there’s an is_on property that could be used to conditionally call await self.coordinator.roku.remote("poweroff"), but I’m not sure if it should be fixed there, or upstream in the rokucp library. Either way, I probably don’t know enough right now to actually submit a PR. As a work-around, I’ve switched from blindly making the turn off call to conditionally doing so - only when the device is already on. E.g. something like the following:

alias: Turn Off TV
sequence:
  - choose:
      - conditions:
          - condition: state
            entity_id: remote.bedroom_roku
            state: 'on'
        sequence:
          - service: remote.turn_off
            target:
              entity_id: remote.bedroom_roku
    default: []
mode: single

It’s definitely not as tidy, but it keeps the logs clean without having to mess w/ the logger (hiding other, possibly valuable errors from the Roku component).

Looks like there’s some fixing to be done (might be my stuff, of course). I plugged the following code into a python script to manage the roku’s:

      service_data = {'entity_id': roku_name, 'source': to_source }
      hass.services.call('media_player', 'select_source', service_data, False)
      logger.error("     Set {} to {}".format(roku_name, to_source))
      logger.error("     Service data dict: {}".format(service_data))

The first line simply sets up the data for the service call, the second line makes the service call (select_source), and the third line just writes the data to the log. The fourth line repeats back the service_data dict for verification.

The roku_name is the name of the Roku in Home Assistant and the to_source is 'Pandora'. I’ve verified they are both correctly coded (i.e., no typos in the names). Each time I execute this code, I get the error:

[homeassistant.components.roku] Error communicating with API: Timeout occurred while connecting to device
[homeassistant.components.roku] Error communicating with API: Timeout occurred while connecting to device
Invalid response from API: ('HTTP 503', {'content-type': '', 'message': '', 'status-code': 503})

This is very repeatable (and a bit odd that I get the Error communicating... twice - the timestamps in the log are exactly the same). The errors show up in the log 6 seconds after the logger... is written to the log.

To make sure the Roku is not geezed up, I reset it and the error still occurs (resetting the Roku had no impact at all).

The logger info is what I expect to see (name of the Roku and the source):

Set media_player.roku_3_training_room to Pandora
Service data dict: {'entity_id': 'media_player.roku_3_training_room', 'source': 'Pandora'}

Anyone see what I’m doing wrong?

Hi, I work on the roku integration for HA.

Is the device on/awake when calling said commands? If so what channel was it on? Do you have fast start enabled? What version of Roku OS? Roku error response aren’t the most useful as you can see ie no real message.

We do poll the roku so the error could repeat if it tried to update around same time as your calls

Hi, Chris -

Typically, the device is in its “saver” mode showing the screensaver. So, it wasn’t on a channel prior to sending the commands.

Fast start isn’t an option that I can find (I think that might only be on Roku TVs, but not sure - mine are all boxes)

Version 10.5.0

Thanks!

Ah I don’t actually have a box to compare about fast start or related… but does Pandora match the name in media player sources … some apps add text to their name and we only support direct match to that or the app id (there’s a diagnostic sensor in newer HA 2022.2 to find the app id)