Is it possible to trigger a Restful sensor scan/poll as an action?

I’m using a value from a dropdown as a way to select a node in a sensor, it’s important that the sensor and the dropdown are in sync

 - platform: rest
    resource: http://127.0.0.1:8091/cgi-bin/song.py
    value_template: '{{value_json[states.input_select.playlist.state]}}'
    name: song

Currently I solve it by polling every second, but it would be much nicer with an automation that triggers a rescan of the sensor.

 - platform: rest
    resource: http://127.0.0.1:8091/cgi-bin/song.py
    value_template: '{{value_json[states.input_select.playlist.state]}}'
    name: song
    scan_interval: 5

Does this give you any ideas? This is how I keep my Harmony input select synched when I start an activity from the hub itself rather than HA:

- alias: "AnroidTV started from Harmony Hub"
  trigger:
    platform: state
    entity_id: remote.living_room
  condition:
    condition: template
    value_template: '{{ trigger.to_state.attributes.current_activity == "AndroidTV" }}'
  action:
    service: input_select.select_option
    entity_id: input_select.living_room_tv
    data:
      option: "AndroidTV"

Thanks but no, I need it the other way around, once the inpupt_select get chagned I want the sensor to update it’s value.

Sorry, I misunderstood.

1 Like

I too am looking for the same thing. I have a REST sensor which reads the state of the TV (current program, power state, etc), and I’d like to update it once I use scripts within Home Assistant to change the channel or turn it off/on. Currently it polls the state every 5 minutes.

I was hunting on how to do the same, and found a solution amongst a bunch of other threads here. So, for the future user who’s also looking for the same, here’s how you do it:

Use the homeassistant.update_entity service, with the name of the restful sensor, which will refresh it ahead of the regular polling period.

8 Likes