Actionable Notifications with Home Assistant

I hooked up my front door lock to my z-wave network recently and wanted to setup some automations around it. One of the automations was to be a notification from home assistant if the lock was unlocked for more than some time period, with two actions on it, one to immediately lock the door, and the other to do nothing.

I hadn’t used actionable notifications from home assistant before, so this was a new feature to check out in the system. This does end up using more yaml than I normally use in my configurations, however it’s not too hard once you know what needs to be done.

Trigger

The trigger for my automation is nice and simple. If the lock has been in the unlock state for more than 5 minutes, then we’ll want to send our notification.

Actions

The actions however are where the real fun begins. We start with sending a notification to the home assistant app on my phone.

Followed by waiting for the triggers, the lock trigger, or the do nothing trigger. This has a timeout setup in order to avoid the automation hanging, waiting for an action that’s not coming.

Lock and do nothing actions with a timeout.

Next up we have the actual action for those triggers. This is where we check which action should be triggered and take the relevant steps.

More than what meets the eyes in this block

This choose block was created in YAML rather than the visual editor. Below are what it ended up to be.

choose:
- conditions: "{{ wait.trigger.event.data.action == 'LOCK' }}"
sequence:
- device_id: b37a63b3a0aa839974208da36fc29bd0
domain: lock
entity_id: lock.front_door_lock
type: lock
- conditions: "{{ wait.trigger.event.data.action == 'NOTHING' }}"
sequence: []

Conclusion

This is working pretty well on my system, though the timeout on the notification is silent so there’s no way to know when it’s done and no action can be taken from it any longer. There are some other ways to handle the actions that I need to look into to potentially make this a more robust system. For my first actionable notification though, it is a success and I’ll be able to use the knowledge for future automations.