Hey, I’m really sorry to have led you down this wild goose chase.
I seem to have been bitten by the “template entity” bug.
Templates are only ever evaluated when one of the associated entities updates. But now() isn’t an entity so the now()) time changing doesn’t trigger an evaluation of the template so even if the conditions of the template are met then the template never evaluates therefore never sets the binary sensor state to on. You can fix that situation by adding an entity_id to watch for a change in to force the sensor to update.
I knew it was that way for regular analog sensors but wasn’t even thinking about that in relation to the binary sensor.
That said there are two ways you can proceed.
The first and recommended way is to add the sensor.time entity_id to the binary sensor. That will cause the template to re-evaluate every minute. But you’ll have to ensure you add the date_time sensor (and all of it’s different entities) to your HA config. It isn’t hard and it should be standard anyway since it’s immensely useful. Just like in this case.
The downside to this method will be that it won’t necessarily evaluate at exactly seven minutes that the door is open since the door will open sometime within the minute and the sensor time will only update every minute at the 0 seconds mark. So it’s possible that the binary sensor won’t update at exactly seven minutes but may be up to almost a minute later. It probably isn’t a big deal in this situation but it might be in some other use case. So keep it in mind.
The second way is to create an input boolean and set it’s state with an additional two automations and completely forego the binary sensor. Then you can use the state of the input boolean in the alert config instead of the binary sensor. The benefit here is that the alert will trigger at exactly 7 minutes. The downside is you have to create an input boolean and two more automations.
here are both setups…
using the sensor.time:
sensor:
- platform: time_date
display_options:
- 'time'
- 'date'
- 'date_time'
- 'date_time_utc'
- 'date_time_iso'
- 'time_date'
- 'time_utc'
binary_sensor:
- platform: template
sensors:
door_open_for_7_minutes:
entity_id: sensor.time
value_template: "{{ is_state('binary_sensor.ecolink_door_window_sensor_sensor_2', 'on') and (as_timestamp(now()) - as_timestamp(states.binary_sensor.ecolink_door_window_sensor_sensor_2.last_changed))/60 > 7 }}"
then just use the alert as above.
or using the input boolean:
input_boolean:
door_open_for_7_minutes:
automation:
- alias: turn boolean on
trigger:
- platform: state
entity_id: binary_sensor.ecolink_door_window_sensor_sensor_2
to: 'on'
for:
minutes: 7
action:
- service: input_boolean.turn_on
entity_id: input_boolean.door_open_for_7_minutes
- alias: turn boolean off
trigger:
- platform: state
entity_id: binary_sensor.ecolink_door_window_sensor_sensor_2
to: 'off'
action:
- service: input_boolean.turn_off
entity_id: input_boolean.door_open_for_7_minutes
alert:
back_door_open_warning:
name: Back door open for 7 minutes
message: "Please don't forget to close the back door!"
done_message: "Thank you for closing the door"
entity_id: input_boolean.door_open_for_7_minutes
state: 'on'
repeat:
- 4
can_acknowledge: true
skip_first: true
notifiers:
- tts.google_translate_say
- notify.alexa_media
hopefully one of those options works for you.
again, sorry for leading you down a rabbit hole.