I have taken a look at a bunch of posts but can’t get my Automation to operate as needed
Aim - I have a side gate that I’ve placed a reed switch on, I’m trying to work out how to make it send an alert every time the gate is left open for longer than 1 minute. I can make the automation run once and it will send an alert but I would like it to keep checking and sending the alert every 60 seconds until the state changes back to close
Code I am trying to use
- id: '1558930450283'
alias: SideGate
trigger:
- platform: time_pattern
seconds: '/60'
condition:
- condition: state
entity_id: binary_sensor.esp8266_gate1
state: 'on'
- condition: template
value_template: '{{ ((as_timestamp(now()) - as_timestamp(binary_sensor.esp8266_gate1) | default(0)) | int) > 60 }}'
action:
- data:
message: Side Gate is open and should be checked
title: Warning
service: notify.smtp
When I compare the above code to others working examples my code is correct but it doesn’t work. I can manually run the automation and it sends the alert email but when I open the side gate the automation doesn’t run
I am sure it is something simple I am just not seeing it
The way your automation is written it could take longer than 60 seconds (up to 119 seconds) to fire. Consider what happens if you open the gate when your system time is hh:mm:30 . The trigger does not fire for another 30 seconds when the pattern matches. Then the second condition fails (has only been 30 seconds so far), so you have to wait another 60 seconds for the trigger to fire again. That’s 90 seconds since the gate opened before you get a message.
Yes okay, I see that but didn’t know what the “state” and “last_changed” was for so I removed them. After that change, I am now seeing the following in the logs
Actually physically use the gate to trigger the automation. If you manually trigger the automation using the development tools there will be no last_changed timestamp for your gate sensor. Thus, the error you see.