I want to emulate what google nest devices do - lower music volume when assistant in action. Is it possible to do it in HA?
At the moment I created automation to set volume to X and after delay set it to Y. It works, but I want to use volume value that was before automation started.
Or alternative automation - lower volume to 20% of current music volume and in the end go back to initial volume.
You use the scene.create action to make a “snapshot scene” of your media_player entity prior to changing its volume using media_player.volume_set. Later you restore the snapshot scene (which reverts the media_player to its previous state).
The behaviors you described depend on the underlying integration and/or the music source. Some produce fewer unwanted side-effects.
In your case, the side-effects are undesirable so you’ll have to revert to using either a script variable or an Input Number helper (or the suggested Trigger-based Template Sensor) to store/restore the media_player’s volume. Which one you choose depends on the application. For example, if just one automation handles both storing/restoring then a script variable is ideal.
I did it in YAML and Visual editor says it doesn’t like this configuration.
Anyway it works too.
I like Define variables block method more because it’s more straightforward.
The challenge was to found a proper syntax for volume state. And use YAML a bit