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
| selectattr('entity_id', 'search', 'shp_circuit_\d+_mode')
| rejectattr('state', 'in', ['Auto', 'Off'])
| map(attribute='entity_id') | 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 not interested in the states of Auto
and Off
so I “reject” them from the obtained list.
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 not in Auto
or Off
, but it isn’t.
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. - 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
:
1 post - 1 participant