Is there a simple way of writing an automation that uses all entities of a specific domain as trigger?
I am using a large amount of entities and it would be super handy to have a whole domain as trigger…
I also checked some forum posts and feature requests on github about similar ideas (like Regex Wildcard / Entitiy Groups -> Which are not supported - for good reasons)
Thank you very much for your help.
Best regards
Fabian Baumann
I’d just use an event trigger and filter in a condition.
I’m assuming youw ant a state change, so here’s an example of that.
mode: parallel # Need to be able to do multiple of these at a time
max: 10 # Set the max to handle at once, based on CPU probably
trigger:
platform: event
event_type: state_changed
condition:
- "{{ 'my_domain' == trigger.new_state.domain }}"
action:
...
You might have to set this one to parallel mode if you have a ton of state_changes happening so you can handle each one at the same time.
Thank you very much for the help. I just tested the automation with the domain filter and it works perfect…
Follow up question:
Is there a way to check for a delay? We would like to have an automation that will fire 5 minutes after ariving at home.
Example:
- alias: "Testautomation that should fire 5 minutes after coming home"
trigger:
- platform: event
event_type: state_changed
mode: parallel
max: 25
condition:
condition: and
conditions:
- condition: template
value_template: '{{ trigger.event.data.new_state.domain == "person" }}'
- condition: template
value_template: '{{ trigger.event.data.new_state.state == "home" }}'
action:
- some action which is not relevant
I know that the automation like that is working but we prefere to filter on the domain, beause we have about 50 people to track:
- alias: "Automation using States Platform"
trigger:
- platform: state
entity_id:
- person_health.fabian_baumann
- etc.
to: "home"
for: "00:05:00"
action:
- some action which is not relevant
Thank you very much for your help and best regards
Fabian Baumann
The ‘for’ clause just makes sure the entity was in that state for at least that long. It’s to help with false updates and debouncing.
If you just want to wait, just wait in the actions.
action:
- delay:
minutes: 5
- < my other actions >
If you want a wait with an abort, we can use a wait_template
action:
# Wait for 5 minutes to see if this entity transitions away from home.
# As soon as this transitions state, the wait_template will finish.
# Or, the timeout will happen.
- wait_template: "{{ not is_state_attr(trigger.event.data.entity_id, 'home') }}"
timeout: "00:05:00"
continue_on_timeout: true
- condition: template
# wait.completed is true if the condition was met. False otherwise.
# Halt the sequence if the condition was met. i.e. return false if the state went away from home.
value_template: "{{ not wait.completed }}"
# Timeout happened. This person is still home. Do the rest of the actions.
- my_normal_actions ...
Yeah, don’t put quotes around it. Quotes would mean you pass in literally “trigger.event.blah”. We want the string that that variable represents instead. So, no quotes around all of them.
so states(trigger.xxxx), is_state(trigger.xxx), state_attr(trigger.xxx), etc.