I’m trying to wrap my mind around the correct syntax for this automation.
Basically, any time an entity in the “media_player” domain turns off, I want to reset it’s volume to ‘0.5’.
The reason being is that I have lots of smart speakers and I want to reset their volumes to this specific level after any activity.
But I don’t think you’ll be able to do what you want because domain isn’t part of the state_changed event structure. You can check in Developer Tools->Events if you listen for state_changed. Instead, you’ll probably need to just trigger on every state_changed event and use a condition to filter out only media_player entities that were just turned off:
Also review this for what trigger variables are available for each trigger platform. You’re mixing up event triggers and trigger variables for a state trigger.
Question for you.
How would you do the same but rather than the split with the comparison operator, using match and the is_state() method?
Something like this.
value_template: "{{ (trigger.event.data.entity_id) is match('^media_player', ignorecase=True) and is_state(trigger.event.data.new_state.state, 'off') }}"
Is this possible?
This method could prove useful with regex matching for other automations.
Either I can’t get the syntax correct or I suspect I’m running into an issue with limited templates. I couldn’t find definite answers of what qualifies as a “limited template”.
Kind of confusing when the below recommendation is highlighted on that page.
It is strongly advised to use the states() , is_state() , state_attr() and is_state_attr() as much as possible, to avoid errors and error message when the entity isn’t ready yet (e.g., during Home Assistant startup).
Basically a “limited template” is a template that cannot contain any functions.
That might be a bit of an oversimplification but (at this point in time) it’s effectively true.
Not to sound defeatist but many things you would normally want to do with a template, can’t be done with a “limited template” (which makes the word “template”, in “limited template”, a stretch but there it is).