Hi there !
I have spent som time now struggling with templating (in a script, but not only).
I have read articles, found work-arounds, but nothing very that will be easily maintainable overtime.
My “problem” is that it seems that templating does not allow to set anything more than a simple “value” for a given “key”. You cannot create an entire “object” and assign it to a “key”.
For the sake of clarity, imagine the script below in “scripts.yml”:
(We try to dynamically create a scene then apply it altoghether.)
A requirement is that the scene can be very different from a call to another. It may not even include the same lights from a call to another… Or the list of lights could be passed as a variable…
test:
alias: test
sequence:
- service: scene.apply
data_template:
entities:
light.test_a:
state: 'on'
brightness: 100
light.test_b:
state: 'on'
brightness: 100
What if you want to include or exclude a light ?
What if you want to iterate through a list of lights ?
I’d need something that would build the list of entities. Something similar to this:
test:
alias: test
variables:
mode: 'dim'
sequence:
- service: scene.apply
data_template:
entities: >
{{ '{"light.test_a":{"state":"on", "brightness": 100},
"light.test_b":{"state":"on", "brightness": 100}}' | from_json }}
Of course the above code does not work (hence my question).
It is just an exemple. In real life you’d want to build the list of entities from a variable, then only include lights that are already ‘on’ for instance, and adjust different properties from a light to another.
But anyway, the real question here is: how do you guys achieve this kind of complexity ?
If you cannot create entire objects / trees and assign them under a “key” in the yaml file, how do you create complex scripts ?
Many thanx in advance for your time.