I have a template sensor which I use to obtain a list of select entities that match a specific state.
template:
- sensor:
- name: "SHP Circuits Manual Mode"
unique_id: shp_circuits_manual_mode
icon: "mdi:home-automation"
state: >-
{{ states.select
| select('search', 'shp_circuit_\d+_mode')
| map(attribute='entity_id')
| select('is_state', 'Battery')
| list
}}
As you can see, this searches for all select entities with a name matching a regular expression. There are 10 circuits in total, the last one ā10ā is usually in an Off
state. The available states of these selects are: Auto
, Grid
, Battery
, Off
.
In creating the template, I am only interested in obtaining the entities with the state of Battery
.
The problem Iām having is that when I systematically go through the selects and change them to Battery, the sensor value (state) updates as normalā¦until I change the last circuit to Battery
. The last select changed has no effect on the sensor. If I change the select back to Auto
for example, it shouldnāt be included as per the sensorās template, but if I change it to Battery
, it should be included, because its state is Battery
.
Why doesnāt the sensor update to include this circuitās entity ID?
Obviously I have taken the template itself over to Developer Tools and performed the same tests thereā¦and there, it works just as expected: I change the select to Auto
, itās removed from the list, I change it to Battery
, itās included in the list. Why is the sensor giving a different result?
Iāve tinkered with it endlessly, Dev Tools shows the correct results when I change the state of the select but the sensor omits the last select changed to Battery
Iāve tried:
- Trigger based sensor with the template
- Simplifying the template to use only
select
- same result. - Using
rejectattr
instead - same result. - Writing/rewriting the template in the sensor any number of ways - same result.
Dev Tools with the template works fine - when I change the state of the select, itās represented in the Dev Tools output instantly. The sensor just doesnāt add the entity name of last changed select
.
Dev Tools:
Actual states:
The sensor (circuit 7 is missing as that was the last one that I changed to Battery
: