#GOAL I want to get a list of all
1 messages · Page 1 of 1 (latest)
Well, technically... it shouldn't work, so it's working as expected
Rob has a good example here of just creating a list based on the criteria: #frontend-archived message
As I wrote, it looks like I have to use a for loop, which is fine.
Sure... it still seems like it's top secret on what you plan on doing with the list, so that's your best bet
I still don't get it though. Why is the |int(0) conversion not working in this case
:))))
I plan to create daily scheduled alert, which runs this template code to check, and then runs it again in the aciton to send me a list of batteries i need to replace on whatsapp
In case you are interested, the following works as expected, although less elegant
{%- set low_battery = namespace(entities=[]) -%}
{%- set entities = states
| selectattr('attributes.device_class', 'defined')
| selectattr('attributes.device_class', 'eq', 'battery')
| rejectattr('state', 'in', ['unavailable', 'unknown', 'none'])
-%}
{%- for entity in entities | sort(attribute='state') -%}
{%- if entity.state|int <= 15 -%}
{%- set low_battery.entities = low_battery.entities +
[entity.state|int ~ '% ' ~ entity.entity_id ~ ' (' ~ entity.name ~ ')'] -%}
{%- endif -%}
{%- endfor -%}
{{ low_battery.entities | join('\n') }}
you cant set a variable in a loop and call it outside of a loop. you need to use namespace