Hey everyone!
I wanted to share my recent experience setting up an automation in Home Assistant to notify me when any of my three door sensors are triggered. It’s been a bit of a learning curve, but I’m happy to share what I’ve discovered!
The Goal:
I have three door sensors in my home, and I wanted a single automation that would send me a notification whenever any of them are opened. The challenge was figuring out how to include the specific door name in the notification message.
The Setup:
I started by creating a new automation in the Home Assistant UI. I set up three triggers, one for each door sensor. Each trigger is based on the state change of the respective sensor entity. The action I wanted was a notification to my phone, but I needed the message to specify which door was opened.
The Challenge:
At first, I tried using a static message like “A door has been opened!” but that didn’t tell me which door it was. I knew I needed to include dynamic data in the message, but I wasn’t sure how to do that. After some research, I discovered that I could use the {{ trigger.entity_id }} variable in the notification message to pull in the specific sensor that triggered the automation.
The Solution:
Here’s how I structured the automation:
yaml
- alias: Door Open Notification
trigger:- platform: state
entity_id:- sensor.front_door
- sensor.back_door
- sensor.garage_door
to: ‘on’
action:
- service: notify.mobile_app_android
data:
message: “{{ trigger.entity_id.split(‘.’)[1] }} door has been opened!”
- platform: state
This automation checks for a state change to ‘on’ on any of the three door sensors. When triggered, it sends a notification to my phone with a message like “front door has been opened!” or “garage door has been opened!”.
The Learning Experience:
It took some trial and error to get the syntax right, especially figuring out how to extract just the door name from the entity ID. The split('.') function was key in isolating the door name from the full entity ID. I also learned that using trigger.entity_id is a powerful way to make automations more dynamic and adaptable to different triggers.
The Outcome:
Now, I have a single automation that handles notifications for all three doors, and each notification clearly states which door was opened. It’s been a huge improvement over having separate automations for each door, and it’s much cleaner to manage in the UI.
Final Thoughts:
This project was a great way to dive deeper into Home Assistant’s automation capabilities. I’m excited to explore more advanced features and see how else I can streamline my smart home setup. If anyone has tips or suggestions for improving this automation, I’d love to hear them! ![]()