I’m scratching my head with this one and can’t make sense of why it’s not working.
I have a template binary_sensor that I use for an alert in case I stop receiving data from one of my sensors.
For some reason the sensor’s status is always off. Here is the sensor
Now if I enter that value_template {%- if (as_timestamp(now()) - (as_timestamp(states.sensor.currentcost_power.last_updated) | int)) > 300 -%}on{%- else -%}off{% endif %} in the dev tools, I get the value on yet the binary_sensor returns the value off.
value_template: >-
{%- if (as_timestamp(now()) - as_timestamp(states.sensor.currentcost_power.last_updated)) | int > 300 -%}
on
{%- else -%}
off
{%- endif -%}
OK…that is a different issue. The template is not rendered on every update and hence the binary_sensor stays at off. You should use an input_boolean along with an automation to set it on/off based on the template.
Thanks, though I’m a bit confused.
I’m trying to generate an alert if a sensor has not been updated in >300 sec.
As I can’t use templates in alerts, I’ve created a template binary sensor to circumvent this, as per the docs.
you mean to say I need to create an input_boolean on top of this?
What I mean is that binary_sensor will not work for what you are trying to accomplish.
Actually, if you just want to create an alert if the sensor is not updated for 300 seconds, you don’t even need a sensor. Just use an automation directly