I have a temp sensor for my freezer that I have to monitor temps. I created a threshold sensor with an upper limit of 10F and then used that sensor to feed into a template binary sensor sensor that triggers when the threshold has been met for 30mins continuously.
{{
is_state('binary_sensor.small_freezer_temperature_threshold_reached', 'on') and (now() > states.binary_sensor.small_freezer_temperature_threshold_reached.last_changed + timedelta(minutes=30))
}}
Then this template is what triggers an alert integration for my freezer. However, this template sensor doesn’t stay ON after restarts so it causes the alert to stay idle again until it triggers after 30mins. See the screenshot below that idle time was after a restart and 30mins later it triggered. How do I prevent this?
Well that is a different approach. I am not using an automation i’m using Alert the integration. I purposely kept it out of an automation bc i like its functionality. I just need a way to have a binary sensor persist across restarts. The issue I’m seeing tho is this threshold sensor tho that is the issue. It seems it changes values during restart.
Every entity is set to unknown as HA starts. They are then either restored or are updated as new values arrive.
Template sensors are not restored, they wait for source sensor updates. Triggered template sensors are restored after restart, so you could do this:
template:
- trigger:
- trigger: state
entity_id: binary_sensor.small_freezer_temperature_threshold_reached
to:
- 'on'
- 'off'
binary_sensor:
- name: Name Here
state: >
{{
is_state('binary_sensor.small_freezer_temperature_threshold_reached', 'on') and (now() > states.binary_sensor.small_freezer_temperature_threshold_reached.last_changed + timedelta(minutes=30))
}}
device_class: etc...
It should operate exactly the same as your current sensor except that it will be restored after a restart.
EDIT: Hmm. Or maybe not. last_changed will definitely reset to to the restart time, so that my stuff this method up. Give it a try and see what happens.