I’m trying to get this automation to fire for every entity with device_class of door. When the state changes I want to get notified. I also don’t want to have to list every entity_id manually, looking for an automated way to get this automation to work. Thoughts?
Can’t quite figure out the trigger.
- id: '1590437448747'
alias: Notify if any door opens
description: ''
trigger:
platform: template
value_template: '{%- for item in states.binary_sensor -%}{%- if item.attributes.device_class == "door" -%}true{%- endif -%}{%- endfor -%}'
condition:
- condition: template
value_template: '{{ trigger.from_state.state != trigger.to_state.state }}'
action:
- data: {}
service: notify.discord_webhook
data_template:
message: '
{% set option = trigger.to_state.state %}
{{trigger.to_state.name}} is now {{ "open" if option == "on" else "closed" }}'
I have something similar for lights; and can likely be modified to do what you want. Code below. You can’t use a template like you propose as it’s not updated as not specific entities.
You can make it into a sensor, and trigger on that, as you can specify it to update on the sensor.time.
Interesting approach. This won’t give me the name of the triggered entity will it? Or even, will it only give me 1 name at a time if 2 doors open (2 separate notifications)?
Or do I have to specify each entity_id for that granularity?