I have a minute timer that I want to filter so it is returned only if it’s value is greater than zero.
I thought I could do something like this but it does not work…
{% set msg_grt0_ct = label_entities(‘Msg_grt_0’) | select(‘is_state’, ‘>0’) | list %}
This above should return an array of entities with the label ‘Msg_grt_0’ then filter and return only the entities that are greater than zero.
If I check for the state to be a specific value it does work…
{% set msg_grt0_ct = label_entities(‘Msg_grt_0’) | select(‘is_state’, ‘21’) | list %}
In this case if the entity equals 21 then it will be returned.
===================
Does anybody know how to filter on a range (entity > 0)?
Thanks
So, states are string values. I don’t think is_state works that way. It should be a string comparison. Since 21 is not equal to ‘>0’, it should not do what you think.
{% set ents = label_entities('Msg_grt_0') | select('has_value') | list %}
{% set msg_grt0_ct = zip(ents, ents | map('states') | map('float', 0) | list)
| selectattr(1, 'gt', 0) | map(attribute=0) | list %}
Thanks!
I just changed ‘float’ to ‘int’ and ‘}}’ to ‘%}’ and it worked perfectly.
Now I’ll have to look up all those filters so I can understand what is happening 
{% set ents = label_entities('Msg_grt_0') %}
{% set msg_grt0_ct = zip(ents, ents | map('states') | map('int', 0) | list)
| selectattr(1, 'gt', 0)
| map(attribute=1)
| list %}