I think I’m missing something obvious.
I have a binary_sensor template that checks if any sensors are not in their closed state. It does this by seeing if the count of open sensors is true (non-zero).
But, I wanted to keep the count in a variable for use later when setting an attribute and for setting the state. But, the “is_open_count” variable doesn’t seem to get set, and I’m not sure why.
Could someone be so kind as to explain why this isn’t setting the “is_open_count” variable?
- binary_sensor:
- name: Garage Closed
device_class: garage_door
unique_id: garage_door_opened_group
variables:
# Why is this not getting set to the count?
is_open_count: |
{{
label_entities("garage_sensor")
| reject('is_state', ['off' , 'closed'])
| list | count
}}
# This works:
another_count: |
{{
['one','two'] | count
}}
# This is setting the state correctly
state: |
{{
label_entities("garage_sensor")
| reject('is_state', ['off' , 'closed'])
| list | count
}}
attributes:
# Why no count here?
is_open_count: "{{ is_open_count }}"
# This works
count: |
{{
label_entities("garage_sensor")
| reject('is_state', ['off' , 'closed'])
| list | count
}}
another_count: "{{ another_count }}"
Here’s the two states (“off” and “on”):
Note that the state is “on” now, and “count” has changed, but not “is_open_count”: