Number of open windows is not updated promptly

Hello,

I have created the following template sensor, which shows me the number of open windows/doors from the DeviceClass “door”.
The calculation also works so far. However, I have the problem that the template sensor is not updated immediately as soon as I open/close the window. Instead, it takes about 1 minute.

How and where can I influence or change this? It would be great to have a solution where I don’t have to record/declare each window/door individually, but that this is recognized based on the DeviceClass?

Thank you very much

Templates accessing all states directly are rate limited to one update a minute. See: https://www.home-assistant.io/integrations/template/#rate-limiting-updates

Limit your template to a specific domain (e.g. states.binary_sensor ) and it will update every second.

Or create a group of all your door sensors and expand that and select the required entities. This will update as soon as any sensor changes state.

Thank you for the quick response.

Ok, but where do I set states.binary_sensor exactly?

Because I can’t explicitly select binary_sensors here?

Please share your template as text correctly formatted for the forum and I’ll show you. Use the </> button.

{{ states 
   | selectattr('attributes.device_class', 'eq', 'door') 
   | selectattr('state', 'eq', 'on') 
   | list | count }}
{{ states.binary_sensor 
   | selectattr('attributes.device_class', 'eq', 'door') 
   | selectattr('state', 'eq', 'on') 
   | list | count }}

And the other option that will update faster than every second:

First create a group of all your door sensors, call it “All Doors”. Then:

{{ state_attr('group.all_doors', 'entity_id') 
   | selectattr('state', 'eq', 'on') 
   | list | count }}

Ok, I have now created the group and it also changes when the window opens/closes, for example, and this is what the sensor template looks like now:

This is the group:

However, this does not change immediately when the window is opened. What am I doing wrong here :(?

Sometimes it is the sensor that is slow to report.
Check the state of a single sensor in the developer tools.
If you have multiple types/brands of sensors then check each type/brand also.

Does the window you are opening update immediately in Home Assistant?

Yes, the Window Sensors are updated immediately:

But the template sensor does not change:

The Development View:

I have also just noticed. When I open a second window, this is no longer displayed. Only when the event changes, e.g. window is closed, is something entered in the logbook.