i am trying to use raw to copy a sensor attribute value to a lovelace-gen variable. once its in the lovelace-gen variable the for syntax is something i use extensively in other places and it works fine.
if you would please help figure out the syntax for the set line i think i can get this to work. what would be the right syntax to use state and raw to copy the attribute value of a sensor name stored in a lovelace-gen variable to another lovelace-gen variable?
thanks.
edit:
{% set lovelace-gen-foo = {% raw %}states[{% endraw %}lovelace-gen-bar{% raw %}].attributes.devices{% endraw %} %}
I’m telling you that it will not work at all. Unless you provide more context than what you have above, that will never work with any combination of raw.
The only combination it will work in is this:
{% raw %}{% set theseLights = states['{% endraw %}{{ lightsOn }}{% raw %}'].attributes.devices %}{% endraw %}
{% raw %}
{% for l in range(theseLights | len) %}
- type: light
entity: {{ theseLights[l] }}
{% endfor %}
{% endraw %}
and I’m fairly sure tha’ts not what you want because it’s result is an invalid template that produces yaml.
i have a sensor that stores lights on count in state and list of lights that are on in an attribute called devices. the name of the sensor is store in a lovelace-gen variable.
so lovelace-gen-variable is set to someSensor.
using this information how do i create a light card for each light device stored in states['{{ lovelace-gen-variable }}'].attributes.devices?
o that part i got. but using my example if entity accepted a template i could have done this based on my example, for a sensor that has 5 devices in attributes.
Without having to build a dictionary array of lights for each area that i am interested in displaying individual light cards on demand. Much more efficient and lot less typing:
if lightsOn is the exact same entity in all cases, then there’s no need for raw because thats a JS template…
{% for i in range(5) %}
- type: light
entity: '[[[ return states["{{ lightsOn }}"].attributes.devices[{{ i }}] ]]]'
{% endfor %}
If lightsOn is pulled from the states object, or the number of iterations is pulled from the number of devices, what you want is not possible because that information is not available in Lovelace_gen.
lightsOn is a lovelace-gen variable but i would have preferred to pull the number of iterations from the number of devices but lets leave that aside for a moment.
i tried the code you shared with fixed number of iterations as in your code and below is the output. that’s what i meant when i said entity does not seem to accept a JS template, which is puzzling to me. what am i missing?
it may have been advanced 10 years ago. but 10 years since then HA has come a long way and its time to reconsider updating their stance to have this be the new basic now