schford
(Stuart)
1
Hi guys, this code is bringing back more than I think it should. I need to work out what is showing so I can put in some rejects.
Can anyone tell me how I can change it to list the entities it counts?
{{ states.sensor
| selectattr('attributes.device_class', 'defined')
| selectattr('attributes.device_class', 'eq', 'battery')
| map(attribute='state')
| reject('in', ['unknown', 'unavailable'])
| map('int', -1) | select('le', 41)
| select('ge', 0)
| list | count
}}
petro
(Petro)
2
remote the | count
…
Unless you want entity_id’s then it would be an overhaul
{% set ns = namespace(items=[]) %}
{% for s in states.sensor
| map(attribute='entity_id')
| select('has_value')
| select('is_state_attr', 'device_class', 'battery')
%}
{% if 0 <= states(s) | int <= 41 %}
{% set ns.items = ns.items + [ s ] %}
{% endif %}
{% endfor %}
{{ ns.items }}
schford
(Stuart)
3
Thanks that shows me the values - I can see a bunch of zeros oh well will just change the select i guess!
schford
(Stuart)
4
Ideally wanted the IDs to work out which were cuasing the issue but this short term fix worked
{{ states.sensor
| selectattr('attributes.device_class', 'defined')
| selectattr('attributes.device_class', 'eq', 'battery')
| rejectattr('entity_id', 'search', '(iphone|ipad|disc|low)')
| map(attribute='state')
| reject('in', ['unknown', 'unavailable', ''])
| map('int', -1) | select('>', 0)| select('<', 41)
| select('ge', 0)
| list
}}
schford
(Stuart)
6
AWESOME!!! thanks so much Now I can properly sort it!
schford
(Stuart)
7
eureka!
{{ states.sensor
| selectattr('attributes.device_class', 'defined')
| selectattr('attributes.device_class', 'eq', 'battery')
| selectattr('entity_id', 'search', 'battery')
| rejectattr('entity_id', 'search', 'ipad|iphone')
| map(attribute='state')
| reject('in', ['unknown', 'unavailable'])
| map('int', -1) | select('le', 41)
| select('ge', 0)
| list | count
}}