But I want to change the template values that go into it based on the state of input_select.lifx_devices_all. The problem is when I reload my script I get this error:
Invalid config for [script]: expected dict for dictionary value @ data['sequence'][0]['data_template']. Got None. (See /config/configuration.yaml, line 382).
If you use double-quotes inside the template (which you have) then you must use single quotes outside the template (and vice-versa).
You don’t need outer quotes if the template employs the > line-continuation character. in other words, this is valid:
colors: >
{{ states("sensor.lifx_themes") }}
In addition, the last line of your if-elif chain doesn’t appear to be valid. Each elif supplies three variables to the rest_command (colors, brightness, label) but the last one doesn’t and attempts to supply the name of a script to the rest_command. If you thought it would execute the script, it won’t because data_template is meant to supply additional information to the service (i.e. to rest_command.photons_apply_theme).
But I’m still getting the same error… Any thoughts? Also, I removed the last elif that calls another script, but I’m trying to think of a way to implement that. Basically, what I want to do is if the value of the input_select is anything but “All”, then call the REST_command with the data_template I already have, otherwise run script.photons_apply_theme_all.
I see, so the part that’s wrong is when I get the state_attr “brightness” from my device? Which is “generating an option” and therefore invalid because you can’t do that in templates?
And this is only the case in a data/service/etc template? Because when using the same template in the below script, it works perfectly:
Also, this solution you proposed looks very nice, thank you. However, I am still unsure how to incorporate the last case where a script is run when input_select.lifx_devices_all is selected. See, I have 5 options for lights and 1 option for “All lights”. With your solution, it will work perfectly for the 5 lights, but if I select “All”, it’s going to try to send a REST command where the entity you specified is light.all, which doesn’t exist. I am struggling to conceptualize how I would use your solution for 5 of the input_select options, and just run a simple script for the last option.
If it matters, that script I want to run is actually just running this REST command 5 times, inputting the data for each light in succession, instead of just one.