NOTE: Although the stuff in this post should still work, the HA devs put out an ‘Alert’ component shortly after I wrote this that does pretty much the same thing. I’ve created an updated post about it HERE. I am going to leave this post up as I feel that it might still be useful to accomplish other tasks.
This blog post builds on my last post about the Wemos D1 Mini Garage Door Controller.
Sending a notification via Home Assistant is a simple process, and it is mostly well documented. However, I had trouble finding a solution that repeatedly sends a notification about a device state until that state changes. In this case, I wanted something to notify me when my garage door is open for a while, and then continue sending me notifications every 30 minutes until it’s closed.
The solution I came up with isn’t as elegant as I would have preferred, but it works well. If anyone has any suggestions on a better method, please let me know. The way I did it involves 2 automations and 2 scripts.
Here are the automations that kick off the first script when the door is opened, and then turn the scripts off when the door is closed:
automation: - alias: 'Garage door still open' trigger: platform: state entity_id: cover.garage_door from: 'closed' to: 'open' action: service: homeassistant.turn_on entity_id: script.garage_door_alarm1 - alias: 'Garage door was closed' trigger: platform: state entity_id: cover.garage_door from: 'open' to: 'closed' action: - service: homeassistant.turn_off entity_id: script.garage_door_alarm1 - service: homeassistant.turn_off entity_id: script.garage_door_alarm2
And here are the scripts. When the first script is launched, it will wait 30 minutes, send a notification, and then kick off the second script script. The second script does the same thing and kicks off the first script. The cycle will continue until the garage door closes which triggers the second automation that turns off both scripts.
script: garage_door_alarm1: alias: "Garage Door Alarm1" sequence: - delay: '00:30:00' - service: notify.notify data: title: 'Garage door open: "{{now().strftime("%H:%M:%S %Y-%m-%d")}}"' message: 'The garage door has been open for "{{ relative_time(states.cover.garage_door.last_changed) }}"' - service: homeassistant.turn_on entity_id: script.garage_door_alarm2 garage_door_alarm2: alias: "Garage Door Alarm2" sequence: - delay: '00:30:00' - service: notify.notify data: title: 'Garage door open: "{{now().strftime("%H:%M:%S %Y-%m-%d")}}"' message: 'The garage door has been open for "{{ relative_time(states.cover.garage_door.last_changed) }}"' - service: homeassistant.turn_on entity_id: script.garage_door_alarm1
The notification sends the current time because on my iPhone, the pushbullet app wasn’t displaying the time of the notification. In the message body, it sends the amount of time that the door has been open.
Funny that you should be using a script for this when Home Assistant just released the Alert component:
https://home-assistant.io/components/alert/
Oh I know. I had mixed feelings when I saw that. I spent a lot of time getting this script working but I’m also glad they built something native.
Thank you! I had issues setting up alerts. This method works without issues.
No problem. Glad I could help.