Template Sensor Not Fully Updating

Since I think 2025.1, one of my previously highly reliable and responsive template sensors seems to not been fully updating as it used to previously.

The template sensor listens for the ZB linkquality of all my ZB sensors, and counts how many have LQI < 50. In the Template sensor screen, the preview value = 2, which corresponds to the current position where 2 ZB sensors are below LQI 50. No issues here.

But when I go into more-info, the count is stuck at 1 and has been for ~12 hours. This “stuck” value is then what is displayed on my button (the entity is the template sensor), not the current value which the template sensor preview shows. It should ordinarily bounce around, similar to the middle section of the graph.

image

I need to restart HA for the sensor to show the real time value again - this works OK for a few hours, then something happens and it seems to get “stuck” at a certain value again.

Is there anything I should look at to work out what is happening and how to fix this?

Any help would be much appreciated.

I started having this issue with 2025.12 update.

Template correctly counts in the developer tools, but it’s stuck as a sensor. This is the definition:

template:
    sensor:
      - unique_id: counter_lights_open_id
        name: Number of lights on
        default_entity_id: sensor.lights_on_count
        icon: mdi:lightbulb-on-outline
        state: '{{ states.light | selectattr("state", "eq", "on") | rejectattr("attributes.friendly_name", "search", "Home Assistant Connect ZWA-2 LED") | list | length }}'

Please read the deprecation notice and check that you have not committed one of the common errors listed in the top post: