I’ve added open / closed sensors to all my external doors. The first iteration of this burglar alarm is to simply email me when any of the doors changes state.
I have it set up and working, but the config is very repetitive. I wonder if there’s a generic way of doing it.
Here’s an example from my automations.yaml file which covers two of the four doors:
- alias: Side Door Opened
trigger:
- platform: state
entity_id: binary_sensor.doorside
to: 'on'
action:
- service: notify.smtp_ken
data:
title: "Door (Side) Opened"
message: "Side door opened."
- alias: Side Door Closed
trigger:
- platform: state
entity_id: binary_sensor.doorside
to: 'off'
action:
- service: notify.smtp_ken
data:
title: "Door (Side) Closed"
message: "Side door closed."
- alias: Patio Door Opened
trigger:
- platform: state
entity_id: binary_sensor.doorpatio
to: 'on'
action:
- service: notify.smtp_ken
data:
title: "Door (Patio) Opened"
message: "Patio door opened."
- alias: Patio Door Closed
trigger:
- platform: state
entity_id: binary_sensor.doorpatio
to: 'off'
action:
- service: notify.smtp_ken
data:
title: "Door (Patio) Closed"
message: "Patio door closed."
You can see that it’s the same template repeatedly. Can this be done in a more compact, less repetitive way? If the answer is “no” I’m OKay with that, because I’m poised to do it in Python anyway!
In the first instance, I don’t mind if the email doesn’t announce the door, so long as it tells me if it’s opened or closed.
Thanks!