I have a simple automation script that I am testing to alert me if my fridge door is left open for too long. It doesn’t seem to be working.
Specifically, the delay that I have seems to be ignored. When I open the fridge door, I am alerted almost immediately. It should delay for two minutes, yes?
automation:
alias: Alert when fridge is open
trigger:
platform: state
entity_id: sensor.fridge_left
state: 'Open'
action:
- delay: 00:02:00
- condition: state
entity_id: sensor.fridge_left
state: 'Open'
- service: notify.main
data:
message: "Fridge door is open!"
data:
tag: 'notification-about-sensor'
I used to have something like that set up in the automation section in the following way:
#TEST OPEN DOOR for X Minutes
- alias: "Test Door Sensor Open X Minutes"
trigger:
- platform: state
entity_id: binary_sensor.test_door_sensor
to: 'off'
action:
- delay: 00:05:00
- condition: state
entity_id: binary_sensor.test_door_sensor
state: 'off'
- service: notify.mypushbullet
data_template:
title: "Test HASS says:"
message: 'Test Door has been for 5 minutes now'
Disadvantage: It only notified me once after 5 minutes.
I have since switched to use an alert set up like this:
# Alert for Garage Door having been open for x minutes
alert:
garage_door_open_long:
name: Garage Door is still open!
entity_id: binary_sensor.garage_door_sensor
state: 'off' # Optional, 'on' is the default value
repeat: 5
can_acknowledge: true # Optional, default is true
skip_first: true # Optional, false is the default
notifiers:
- mypushbullet
This alert is now delivered every 5 minutes.
I have also set u a switch that allows me to switch the alert of off in the frontend, e.g. in cases where I know the garage door will be open for more than 5 minutes. This way I don’t receive a notification any more for something that I am already aware of. This might not be that relevant for you, but I thought I just let you know about this as well.
I’m pretty sure you need to quote the value for the delay. Although I don’t have any delays in my automation to confirm that delays are supported in automation actions. (I have all of my delays in scripts).