Template card don't refresh data

Hello, I am programming a card to show when a sensor is open a time (with different colors in function on open time), but I have the problem that the card does not update.
The card works and changes color correctly, but only if I manually refresh the page, not automatically.
Could you help me to know what is happening?
Thank you very much for your help.

{%- set sensor_test = states.binary_sensor.sensor_frigorifico_contact -%} {# My Sensor to show #}
{%- set change_time = (as_timestamp(now())-as_timestamp(sensor_test.last_updated) )|int(0) -%}
{%- if (sensor_test.state == 'on')  -%}
  {%- if (change_time > 300) -%}
     # <font color = 'red'><center> Sensor Open </center></font>   
  {%- else -%}
    {%- if (change_time > 120) -%}
       # <font color = 'orange'><center> Sensor Open </center></font>
    {%- else -%}
       # <center>Sensor Open </center>   
    {%- endif -%}
  {%- endif -%}
{%- endif -%}

Which template card?

This template will only update when binary_sensor.sensor_frigorifico_contact or at the top of each minute. If you want a higher frequency, you have to make a template sensor with a trigger that updates the template more.

1 Like