I’m looking into a way of conditionally polling a sensor and updating an input_number with the received value.
Being a conditional action, I’d use automation. But invoking the rest_command from automation on a time_pattern trigger (every X mins) in case a condition is met, I cannot access the value returned by the rest_command to update an input_number via its set_value service.
Use case: if the TV is accessible on the local network, syncronize its volume value with an input_number (the TV being controllable via both remote and HA).
Use another automation that triggers on change of the input number to call the restful command to set the volume. This will also trigger the first automation, but will not get past the condition.
In the end I gave up on this approach, however having a sensor’s scan interval increased to one day or more and triggering its update with homeassistant.entity_update service when the condition on a different sensor’s state is met would have worked if the platform had the right service defined (e.g. poll for TV’s volume value only if the TV is turned on). It did not have.
I moved everything under a command_line sensor that polls for the TV’s state and if it’s on do further polls on volume, channel, etc.
It’s a one-liner like this below, a one long liner