I use AppDaemon for any automation, but with all the nice enhancements in the last few years, I was a bit curious, and wanted to see how far the automations in Hass have come since last I used them.
But I think I need a bit of help to get started.
I’m trying to make an automation that:
- Triggers on sensor state change
- Sends an actionable notification
- Waits 5 minutes
- Calls a service, but only if the actionable notification was NOT replied with one specific event/reply.
And it’s this last part I don’t really know how to do.
In AppDaemon I’d set up a listen_state
for the state change, and a listen_event
for a custom event, that I’d add in the actionable notification, set up a run_in
linked to a timer to run the service call, but have the event (returned by the actionable notification) cancel that timer.
**How I would do it in AppDaemon, if that makes it more clear**
import hassapi as hass
class Alarm(hass.Hass, globals.Entities):
def initialize(self):
self.listen_state(self.alarm, "binary_sensor.occupancy", state="off")
self.listen_event(self.disable_alarm, event='mobile_app_notification_action', action='disable_alarm')
self.timer = None
def alarm(self, entity, attribute, old, new, kwargs):
self.notify(new_state)
self.timer = self.run_in(self.set_alarm, 600)
def set_alarm(self):
self.call_service("alarm_control_panel/alarm_arm_away")
def notify(self, new_state):
title = "Alarm Arming in 5 Minutes"
message = "The house is empty, I will arm the alarm in 5 minutes"
data = {
"actions": [
{
"action": "ignore",
"title": "OK"
},
{
"action": "disable_alarm",
"title": "Don't Arm",
}
]
}
self.call_service("notify/mobile_app_some_phone", title=title, message=message, data=data)
def disable_alarm(self, event_name, data, kwargs):
try:
self.cancel_timer(self.timer)
except:
self.call_service("alarm_control_panel/alarm_disarm")
Is there a way to do this with the Automations
panel in the UI? It doesn’t seem like you can switch to yaml mode for automation as there is for e.g. Developer Tools
→ Services
.