I was struggling with âifâ & âiifâ in â{{}}â. That all makes so much more sense now, thank you.
You have pressed that âiterableâ test should be used, & i get the logic now. But is it really needed?
(I only press the matter, because unnecessary code tends to be bad code, in my limited experience).
Shouldnât the âinput selectorâ have filtered for invalid values to begin with? Or is it accounting for variables inputed via yaml & if so, wouldnât the script fail to load if invalid variable were set?
I guess non existent entity_idâs could be fed into it, but they should be filtered out @ the âfilteredâ variable stage. & I wonder if the same logic couldnât be applied to the âdefaultâ filter. But I except the fact that you are much more experienced than I, so please donât take this as nit picking, iâm just curious.
Finally device_entities & area_entities donât permit lists being fed into them (as functions {from my understanding }), so have you got any suggestions about how to deal with this challenge, because currently this Blueprint script has two bugs.
1/ It canât handling multiple devices [lights_on always comes back as false with multiple devices].
2/ It throâs an error when trying to handle multiple areas [TypeError: unhashable type: âlistâ]
What I have so far is enough for my purposes, but i am curious about how you would deal with these problems (or even if it can be solved [is this A limitation])? My first thought is, it would require a loop or replace function? But I donât know how to do that yet, & then feed the results into an {{expression}} to be processed? My second thought is, maybe if device_entities & area_entities are applied as filters [ | ]? @petro Sorry, but I think my OCD is going to make me look into this further. I know you knew what a huge can of worms this was from the beginning, & i very much want to thank you for your time so far. I have bought you a couple of 's (you very much deserve them), tho I donât think itâs nearly enough.
What I have so far, with my very limited handling of the two bugs:
variables:
lights: !input lights
area: "{% if lights.area_id is defined and lights.area_id is iterable %} {{ area_entities ( lights.area_id | default ) if lights.area_id is string else area_entities ( lights.area_id | first ) }} {% else %} [''] {% endif %}"
device: "{% if lights.device_id is defined and lights.device_id is iterable %} {{ device_entities ( lights.device_id | default ) if lights.device_id is string else device_entities ( lights.device_id | first ) }} {% else %} [''] {% endif %}"
entity: "{% if lights.entity_id is defined and lights.entity_id is iterable %} {{ [ lights.entity_id ] if lights.entity_id is string else lights.entity_id }} {% else %} [] {% endif %}"
entities: "{{ device + area + entity }}"
filtered: "{{ entities | select( 'search' , '^light' ) | select('is_state', 'on') | list }}"
lights_on: "{{ filtered | count > 0 }}"
transition: "{{ iif ( lights_on , 90, 0 ) }}"