I am trying to create a automation, if i am at home and I get a phone call that al de media players that are playing is paused, and after the phone call that only the media players that are playing before are restored.
For the trigger an condition part is easy… but for the “only the media that is playing music” and restore i am not quit there.
I have a text helper “input_text.oncall_players” that i created en wanted to use to store all the playing media devices before i paused them.
i also have creator a template sensor that saves update with the “playing” media players. “sensor.media_playing”.
if i trey to use this in a input.text.set_value services i can not get this to work …
This is the action part of this automation.
if i run this action the input_text.oncall_players is updated with the string # “{states(‘sensor.media_playing’) | string }}” # not with the value/ state of this templated-sensor ?
The next part is than finding out how to use this string of 1 or more device to pause / play them …
There is already something in HA, that is made exactly for this use case: Scenes
Take a look at how to create a scene on the fly:
You create a scene where you save the states of all your media players, do the call and afterwards restore from that on-the-fly scene.
Works great, not only for media_players, it’s great for lights while watching a film, or for the AC to tone it down while having the balcony door open or…
EDIT: The errror in your example is because you forgot one of two needed { in your value. "{{states('sensor.media_playing') | string }}"
Thanks for pointing me to the “Scenes” section of HA, this is something i did not used before… i was in the mind that this was only for setting devices is a predefined state… did not crossed my mind to use this to capture and restore de state of devices !
i am just reading the scenes docs, and looks very promising, you can create scenes on the fly in you automation and these scenes will then be removed after the automation has finished .
Exactly! The only “downside” is, you sometimes get a warning in the logs, because the scene that you will create on the fly is not ready at the system startup. But you can safely ignore these, and they do only happen sporadically.