I have an automation that I’m using to alert me if I’ve left my garage door open as shown below. It is using mode: restart so what I would expect to happen is that if it is in the 30 minute wait action, and there is a new trigger, it would completely cancel the actions and start over. However, what I’m seeing in the trace is that it is not cancelled and actions fire after the 30 minute wait completes. Is there something about action.delay that prevents mode: restart from actually restarting?
alias: Garage Door Left Open
description: Send alert if the garage door has been left open
trigger:
- platform: state
entity_id:
- binary_sensor.garage_occupancy
for:
hours: 0
minutes: 0
seconds: 0
- platform: state
entity_id:
- cover.main_door
to: closed
- platform: state
entity_id:
- cover.main_door
to: open
condition:
- condition: state
entity_id: cover.main_door
state: open
- condition: state
entity_id: binary_sensor.garage_occupancy
state: "off"
action:
- delay:
hours: 0
minutes: 30
seconds: 0
milliseconds: 0
- service: notify.all_devices
data:
title: Garage Door is Open
message: Close the door!
data:
url: /lovelace-tesy/garage
clickAction: /lovelace-tesy/garage
color: red
sticky: true
importance: high
visibility: public
- service: automation.trigger
data:
skip_condition: false
target:
entity_id: automation.garage_door_left_open
mode: restart
alias: Garage Door Left Open
description: Send alert if the garage door has been left open
trigger:
- platform: state
entity_id: cover.main_door
to: 'open'
for:
minutes: 30
condition: []
action:
- service: notify.all_devices
data:
title: Garage Door is Open
message: Close the door!
data:
url: /lovelace-tesy/garage
clickAction: /lovelace-tesy/garage
color: red
sticky: true
importance: high
visibility: public
What are your other requirements that all of the other stuff in your example is meant to fulfill?
I don’t want the alert to trigger if there is someone in the garage which is why I added the motion sensor. I want the alert if both the door is open, and no motion for 30 minutes.
alias: Garage Door Left Open
description: Send alert if the garage door has been left open
trigger:
- platform: state
entity_id: cover.main_door
to: 'open'
for:
minutes: 30
- platform: state
entity_id: binary_sensor.garage_occupancy
to: 'off'
for:
minutes: 30
condition:
- condition: state
entity_id: cover.main_door
state: 'open'
- condition: state
entity_id: binary_sensor.garage_occupancy
state: 'off'
action:
- service: notify.all_devices
data:
title: Garage Door is Open
message: Close the door!
data:
url: /lovelace-tesy/garage
clickAction: /lovelace-tesy/garage
color: red
sticky: true
importance: high
visibility: public
I like the refactoring. I think that to ensure that both conditions are met for 30 minutes I would need the “for” parameters in the conditions instead of in the triggers. Also one of my requirements I failed to mention before is that I’d like it to re-alert every 30 minutes, so we need to add back the trigger action at the end.
There are lots of ways to skin the cat and I appreciate your help. I’m still wondering though why what I started with was not working. I can see from the traces that new triggers did not cause the automation to restart, rather it seems to have run both instances in parallel.
If you do that and open the garage door but never enter the garage, the automation won’t execute its action. In other words, the door is left open for over a half hour but you’re never notified.
Use repeat or the Alert integration.
EDIT
Redacted. I was too harsh. Let’s just say it’s not the way to loop an automation.
No, it should still evaluate the conditions here is what the documentation says about automation.trigger:
This service will trigger the action of an automation. By default it bypasses any conditions, though that can be changed via the skip_condition attribute.
Which I have set to false. If I leave the hold-offs in the trigger conditions I believe that I could get an alert if the door was open for 1 minute and the occupancy was false for 30 right?
Just noticed that I can upload pictures so show what I’m talking about with the restart not working. Modified my timer to 30 seconds instead of 30 minutes (call me impatient)
In the first image, notice that the 30 second timer action starts at 18:14:07.
In the second image, another trigger caused the automation to run again at 18:14:14
Since the automation is set to “restart”, why did the timer ever finish?