Didn’t quite know what to title this post, but here’s basically what I want to do. Forgive my pseudo-yaml:
automation:
- alias: Volume up then back down
trigger: <whatever>
action:
- service: variable.set
entity_id: variable.previous_volume
value_template: >
{{ state_attr('media_player.google_home', 'volumelevel') }}
- service: media_player.set_volume
entity_id: media_player.google_home
value: <something loud>
- service: tts.google_say
entity_id: media_player.google_home
data:
message: "Some announcement"
- service: media_player.set_volume
entity_id: media_player.google_home
value_template: >
{{ states('variable.previous_volume') }}
I don’t need “variable.previous_volume” to be accessible outside of that automation. I don’t really want to have to create this variable in any configuration outside this automation. Just a throw-away variable that I can set in a sequence, and use later in the same sequence.
Is there anything similar to this existing in HA today? Or do I have to create an input_number just to be used for the run of this automation, and useless all other times? I don’t particular like this because I’d have to create one for each instance of this pattern, or otherwise run the risk of the value being changed during the run of an automation containing a ‘delay’ or being generally long-running.
Alternatively, I could use the template-style variables, if only we could call services from inside templates. I would love to be able to do something like:
action_template:
{% set previous_volume = state_attr('media_player.google_home', 'volumelevel') %}
{% media_player.set_volume('media_player.google_home', '0.75') %}
{% tts.google_say('media_player.google_home', 'some announcement') %}
{% media_player.set_volume('media_player.google_home', previous_volume) %}