#GOAL I want to get a list of all

1 messages · Page 1 of 1 (latest)

hoary dawn
#

Maybe it's wise to create a thread, so we can follow debugging process.

sudden pond
#

Well, technically... it shouldn't work, so it's working as expected

hoary dawn
#

As I wrote, it looks like I have to use a for loop, which is fine.

sudden pond
#

Sure... it still seems like it's top secret on what you plan on doing with the list, so that's your best bet

hoary dawn
#

I still don't get it though. Why is the |int(0) conversion not working in this case

sudden pond
#

Refer to my picture of the template editor

#

That is exactly why

hoary dawn
#

:))))
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

hoary dawn
#

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') }}
fading kindle
#

you cant set a variable in a loop and call it outside of a loop. you need to use namespace