Roku state slow to update (ie from play to pause)

Hi

While working on my new automation to turn on my home theater lights when I pause my Roku I’m having an issue. The automation works - but it’s taking 10-15 seconds for the Roku state to change from playing to paused - and also from paused to playing. When I press pause the Roku does pause the video immediately - but the state in the card is what is taking 10-15 seconds to update therefore my lights don’t turn on for 15ish seconds - kinda anti-climatic - odd to ask everyone just to wait a sec until the lights turn on :slight_smile:

I just reloaded my test instance of Home Assistance - running on a VM in Virtual Box now (was running Core) just to see if my Core install was part of the issue - that doesn’t seem to be the case. I have tried this with both my Roku’s that I have setup.

I’m running Home Assistant 2021.12.9. The setup is a laptop running Ubuntu with Virtual Box installed and then a Virtual Box VM running the Home Assistant OS VDI file. I have checked the configuration.yaml file and there isn’t anything there for the Roku - I expect as its was discovered and installed automatically - I did see one post that tried to adjust the polling frequency but didn’t help so I didn’t add anything to the configuration.yaml yet…but if that is something to try let me know and I will.

Let me know if there are any methods to increase the updating of the Roku state. And if I have left out any information you need let me know and I will update.

Thanks Kevin

Hi Everyone

Just to add on to my question on Roku state delay - if there isn’t much that can be done to address this on the Roku…what other options do work?

Let me know

Kevin

always check the information on the integration. It’s a local polling integration, meaning the states are requested every 30 seconds, it does not push the state when the state changes.

You can turn off automatic polling and make an automation that polls it more frequently using homeassistant.update_entity service, however it may not work. You’ll have to try it to see if it works for that integration.

1 Like

Hi Petro - thanks for the response. I did see a post from back in 2019 and adding the scan interval and mentioned that in my main post - I haven’t tried it as it didn’t work for that user. But I’m willing to try. I will add it and see what happens.

Kevin

Hi Petro…this is what I have just tried. Not sure I’m 100% correct on the configuration.yaml as the Roku is directly integrated now. But this is what I added - and I did a “check configuration” before restarting Home Assistant - the “check configuration” passed with these settings:

media_player:
  - platform: roku
    host: x.x.x.x - I entered the IP of the Roku I'm testing with - it has a DHCP reservation in my router
    scan_interval: 5

Just played a movie on Netflix and using the Media Card from Home Assistant - it identified I was playing Netflix - I pressed pause on the Media Card - movie paused right away - but it took 13 seconds for the Media Card to update to a state of paused. Same when I pressed play it took 14 seconds to update the Media Card state to Playing…

Let me know if I have missed something in the configuration.yaml…

Kevin

You can’t configure this through YAML. You have to remove polling from the integration through the UI and then create an automation that polls the device using homeassistant.update_entity

Take a look at the release notes on HA 2021.6 - Disable polling updates on any integration

Hi Guys, thanks for the help. I will keep working on this…it still looks like I’m not getting something quite right. Here is what I have done just for FYI

  1. Disabled polling for the Roku I’m testing with
  2. Setup an Automation to force polling using the homeassistant.update_entity
  3. Updated my test automation for turning the lights on in the Theater when Roku is paused to also run the forced polling in the action section using the homeassistant.update_entity as the first action, then run the scene to turn the lights on as the 2nd action, and then force the polling again as the 3rd action…to set the current state
  4. I changed the trigger as well to be state based not device based

Still missing something…as it doesn’t work when I pause the Roku - BUT - it sits there paused now doing nothing - which makes sense as I disabled the auto polling. So as soon as I as I trigger the automation to force polling the Roku…the the lights turn on…

So there is something I must still be confused on…on how to include forced polling in my automation as I believe I’m close - I think I just need to have the forced polling adjusted - just don’t know where I missing it right now…

It’s difficult trying to help when you don’t publish your code. What I did was set up an update roku automation to run every 3 seconds. It cut my delay way down but still not instantaneous.

- alias: Run Entity Update
  trigger:
    - platform: time_pattern
      seconds: '/3'

  action:
    - service: homeassistant.update_entity
      entity_id: media_player.roku_ultra
1 Like

Hi Cyn

Sorry about omitting the code…for the polling I had the incorrect platform

alias: poll roku basement
  trigger:
  - platform: time
    at: 00:00:00
  action:
  - service: homeassistant.update_entity
      entity_id: media_player.basement

I was too quick on picking the platform - missed the time-pattern in the drop down of the UI. I have now updated it as you have above:

alias: poll roku basement
  trigger:
  - platform: time_pattern
    seconds: '3'
  action:
  - service: homeassistant.update_entity
      entity_id: media_player.basement

I will see if this extreme timing helps - I have also pulled the polling out of the actual automations on the “pause - turn lights on” as I don’t think that helps anything…and I have 2 triggers for state and device…the code for that automation now looks like this

  - platform: state
    entity_id: media_player.basement
    from: playing
    to: paused
  - platform: device
    device_id: 6752356b2ff6d763390e64c848ff6a37
    domain: media_player
    entity_id: media_player.basement
    type: paused
   action:
  - scene: scene.ht_lights_on

Testing now for bit on the polling interval as I expect 3 seconds might be a bit extreme…thank you for the help so far.

Kevin

As well - I caught an “error” in my code for the polling:

seconds: '3'

should be and I have changed it to (for using an interval)

seconds: '/3'

testing more…it’s better…it sees the state change in about 3-4 seconds now and the lights are on within 4-5 seconds…better than 15 seconds for sure

Kevin

I develop the HA Roku integration. The update_entity service is one way but the polling rate was lowered to 10s in 2022.2. Also one clarification, we do queue a followup poll immediately after most actions to reduce the state delay.

It seems that we may hit an internal HA cool down period of 10s between coordinated polls (designed to reduce back to back requests) which could be why the poll requested after play/pause is roughly 10s longer than expected

2 Likes

I’m going to reduce the cooldown to improve the state responsiveness.

Thanks Chris…I working currently with 2 automations.

  1. poll at 30 second intervals “normally” when Roku is not playing
  2. once the Roku starts playing pole at 3 second intervals

It’s working pretty good but I may try 1 or 2 seconds just while I’m acting watching something via the Roku as even at a 3 second interval there is still delay of when pause or play is pressed.

What I’m trying now (I doubt there will be any difference) is to basically state if Roku is playing “Turn Lights off” - any other state turn lights on.

Too test your cooldown and such I assume I would have to re-enable the polling correct?

Hi Chris

I updated to 2022.2 to test your new the cooldown and my automations. This may be as good as I can get it - I’m using “device” for the trigger - here is the code - is there anything I can do on my side to get it closer to lights on when pause pressed? Still can be a 3-5 second delay…

 trigger:
  - platform: device
    domain: media_player
    entity_id: media_player.home_theater
    type: playing
  condition: []
  action:
  - scene: scene.ht_lights_off

Is there any advantage of using STATE instead of DEVICE for the automation? Or is there something I should add to the automation that I have missed…thanks for the work on the integration for Roku

Kevin

His new code wasn’t delivered to the current release. It will be next month.

Ok thanks - I’ll test then

Would be happy to see shorter polling for this integration! With 10 - 15 seconds the lights take very long to change between starting content or pausing/stopping. Thanks!

so the changes made (coming in 2022.3) should allow for refreshing the status within half a second of vs forcing 10s cooldown since previous refresh took place so like back to back actions wouldn’t get near instant updates after performing the action via HA, previously.

this change of course does little for the times you use a physical remote, since we don’t know you pressed it til next poll (upto 10s with default polling) the only exception is that calling update_entity does request a refresh vs forcing one so the cooldown would potentially impact how often your update entity service call actually results in a refresh (this may be why you see varying results /timing)

I’m honestly not sure you will ever get the delay to near instant (2-3s seems realistic if everything aligns) even with HA performing the actions and near-immediately refreshing status. I hope that getting it down to <5s has atleast helped the awkward waiting). You may want to look into a physical button that could be used to trigger an action that pauses and turns light on concurrently. that would give you the fastest results.

Ok thanks for all the work on the update Chris. Once I get 2022.3 installed I will test and check out the change.

I am also looking as you mention at a button to pause and turn lights on.

Kevin