I do not quite know where to start with this question, so having trouble searching for the right terms.
I have a LOT of scripts that look like this:
show_back_porch_in_livingroom:
alias: Show Back Porch in living room
sequence:
- service: input_text.set_value
data:
entity_id: input_text.show_where
value: "livingroom_tv"
- service: input_text.set_value
data:
entity_id: input_text.show_what
value: "http://192.168.130.93:81/mjpg/camBackPorch/vide.mjpg"
These come from two lists – a set of TV’s, and a set of security cameras, all combinations from them. Think of it as two nested loops, which is a lot simplier than a LOT of copy/pastes. The only thing that changes are the things in quotes and the script names (and I could change camera names so that the camera name matched spoken name).
It is necessary to have a separate script entry for each, as I want to use them with Google for voice control, e.g. “Activate show back porch in livingroom”.
There’s a lot you can do with templating; can you produce scripts from nested iteration?
Or do I need to write a bash script to generate the file (and I guess then manually reload it).
You cannot write scripts from jinja or yaml. Well can’t is a strong word. Let’s say if you are asking the question, you do not know jinja well enough to pull it off.
Perhaps yaml anchors will help, or custom template macros.
Some ninja jinja stuff for your reading:
Thank you. Will review, but it sounds like linux bash or similar is the simplest. Though I haven’t looked to see how restrictive HAOS is going to make that, but I could do it on another system and just copy the file over if needed (since I have to reload anyway).
You probably need lovelace_gen, but that requires YAML only mode, so no GUI.
It can be a big change to make on a running system, but the power of livelace_gen makes it worth in my eyes .
Lovelace_gen adds another Jinja2 passing before giving the result to the HA GUI engine.
This means no limitations on using variables anywhere in the first pass.
Sometimes it is possible to make the values that needs to change into variables that can then be passed to the function.
This can make the scripts a bit more dynamical.