Hello everybody.
I’m new with home assistant and I’m trying to create a simple automation.
I’ve a group with entity id binary_sensor.my_doors.
Into configuration.yaml I’ve added sendmail notify.
I whould like to send an email every time change the status of a door.
I need to get the sensor name and status to create a custom message like “The door {name of the door} is {status of the sensor}”
It’s possible or I need to create an automation for each doors?
You do not need to make a separate automation, but I would suggest to add several triggers to the automation - one for each door. Then you can achieve this with the trigger ID and a template.
Tnx FPro, any examples?
This is current yaml code:
alias: Door open/close
trigger:
- platform: state
entity_id:
- binary_sensor.my_doors
for:
hours: 0
minutes: 0
seconds: 2
from: null
to: null
condition: []
action:
- service: notify.send_email
metadata: {}
data:
message: "Name of the door was status of the door"
mode: single
I don’t think you can do that from a group with this trigger:
trigger:
- platform: state
entity_id:
- binary_sensor.my_doors
for:
hours: 0
minutes: 0
seconds: 2
from: null
to: null
If one door is open the group will be on
. If another the door opens the group state does not change. It will still be on
.
You can’t even do it with this trigger that also monitors the group attributes:
trigger:
- platform: state
entity_id:
- binary_sensor.my_doors
As there are no attributes that change either.
You have to list all the doors:
trigger:
- platform: state
entity_id:
- binary_sensor.door_1
- binary_sensor.door_2
- binary_sensor.door_3
- binary_sensor.door_n
for:
hours: 0
minutes: 0
seconds: 2
from: null
to: null
Or if you don’t want annoying notifications at start up:
trigger:
- platform: state
entity_id:
- binary_sensor.door_1
- binary_sensor.door_2
- binary_sensor.door_3
- binary_sensor.door_n
for:
hours: 0
minutes: 0
seconds: 2
not_from:
- unknown
- unavailable
not_to:
- unknown
- unavailable
Then your action can be:
action:
- service: notify.send_email
metadata: {}
data:
message: "{{ trigger.to_state.name }} changed to {{ 'open' if trigger.to_state.state == 'on' else 'closed' }}."
work like a charm
amazing