We are almost there, but it fires off alerts twice once the trigger happens. Might be a result of the zonedump_interval f the Envisalink, which is currently set to an interval of 15. I wonder if perhaps I need to adjust 300 seconds to be just over 300 or just under 300, since perhaps that is getting in the way here.
Here is my current automation code.
- alias: Window left open longer than 5 minute
trigger:
- platform: state
entity_id:
- binary_sensor.office_windows
from: 'off'
to: 'on'
for:
minutes: 5
- platform: template
value_template: '{% if states.binary_sensor.office_windows.last_changed %}{{(as_timestamp(now())-as_timestamp(states.binary_sensor.office_windows.last_changed)) > 300 }}{% else %}True{% endif %}'
condition:
condition: state
entity_id: binary_sensor.office_windows
state: 'on'
action:
- service: notify.file1
data_template:
message: |
{{now().strftime("%a %b %d %H:%M:%S %p")}} Windows has been open for 5 minutes!!
Log file (relevant lines):
2018-04-25 09:22:40 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=binary_sensor.office_windows, old_state=<state binary_sensor.office_windows=off; last_tripped_time=36325, friendly_name=Office Windows, device_class=window @ 2018-04-24T23:17:46.365349-04:00>, new_state=<state binary_sensor.office_windows=on; last_tripped_time=0, friendly_name=Office Windows, device_class=window @ 2018-04-25T09:22:40.756377-04:00>>
2018-04-25 09:27:39 INFO (MainThread) [homeassistant.components.envisalink] Envisalink sent a zone update event. Updating zones…
2018-04-25 09:27:39 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=binary_sensor.office_windows, old_state=<state binary_sensor.office_windows=on; last_tripped_time=10, friendly_name=Office Windows, device_class=window @ 2018-04-25T09:22:40.756377-04:00>, new_state=<state binary_sensor.office_windows=on; last_tripped_time=15, friendly_name=Office Windows, device_class=window @ 2018-04-25T09:22:40.756377-04:00>>
2018-04-25 09:27:41 INFO (MainThread) [homeassistant.core] Bus:Handling <Event logbook_entry[L]: name=Window left open longer than 5 minute, message=has been triggered, domain=automation, entity_id=automation.window_left_open_longer_than_5_minute>
2018-04-25 09:27:41 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=automation.window_left_open_longer_than_5_minute, old_state=<state automation.window_left_open_longer_than_5_minute=on; last_triggered=2018-04-24T22:25:17.068872-04:00, friendly_name=Window left open longer than 5 minute @ 2018-04-24T21:55:58.141402-04:00>, new_state=<state automation.window_left_open_longer_than_5_minute=on; last_triggered=2018-04-25T09:27:41.204928-04:00, friendly_name=Window left open longer than 5 minute @ 2018-04-24T21:55:58.141402-04:00>>
2018-04-25 09:27:52 INFO (MainThread) [homeassistant.components.envisalink] Envisalink sent a zone update event. Updating zones…
2018-04-25 09:27:52 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=binary_sensor.office_windows, old_state=<state binary_sensor.office_windows=on; last_tripped_time=15, friendly_name=Office Windows, device_class=window @ 2018-04-25T09:22:40.756377-04:00>, new_state=<state binary_sensor.office_windows=on; last_tripped_time=10, friendly_name=Office Windows, device_class=window @ 2018-04-25T09:22:40.756377-04:00>>
2018-04-25 09:27:52 INFO (MainThread) [homeassistant.core] Bus:Handling <Event logbook_entry[L]: name=Window left open longer than 5 minute, message=has been triggered, domain=automation, entity_id=automation.window_left_open_longer_than_5_minute>
2018-04-25 09:27:52 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=automation.window_left_open_longer_than_5_minute, old_state=<state automation.window_left_open_longer_than_5_minute=on; last_triggered=2018-04-25T09:27:41.204928-04:00, friendly_name=Window left open longer than 5 minute @ 2018-04-24T21:55:58.141402-04:00>, new_state=<state automation.window_left_open_longer_than_5_minute=on; last_triggered=2018-04-25T09:27:52.309112-04:00, friendly_name=Window left open longer than 5 minute @ 2018-04-24T21:55:58.141402-04:00>>