I agree the rendered value can be a dictionary but that dictionary’s keys cannot be (YAML) options.
That’s exactly what Mario_held is attempting to do, use a template to generate options. In one case he wants the template to produce a single option (entity_id) and in another he wants it to produce two options (group_name and scene_name). That’s not supported.
I was clarify the reason why it’s not available. It’s not available because data is not templateable, not because they are options. Specifically, it currently just fails validation. The data field might actually be templateable.
In theory, it should be possible (ever since templates were enhanced to support types) to make a template generate options (as per my example shown above) for data.
In practice, it cannot currently be done due to a minor technicality (fails validation).
If I got that right then I would definitely be in favor of a PR to “make this happen” because it adds another tool to the templating toolbox. Having said that, in this particular case, it would be easier for the OP to use choose. That template’s syntax can befuddle a casual user.
{ {{"\"entity_id\"" if is_aus else "\"group_name\""}}: {{ "\"light.wohnzimmer\"" if is_aus else "\"Wohnzimmer\""}},
{{"\"transition\"" if is_aus else "\"scene_name\""}}: {{ "-1" if is_aus else states(trigger.entity_id)}} }
Thank you for giving more details of the underlying problem. Maybe it should be mentioned in the docs that it is not possible to use templates for data, eventhough it is tempting.
I also agree that it would be a good idea to make a PR for this. Maybe you could do this task, as you have a lot more knowledge about this topic?
Thats true for this use case it is clearly better and easier to use choose: instead of templating, but there is sure enough more use cases where templating data: can be usefull.
use repeat for loops. Make a list and store it in a variable, then use repeat.index to grab each item as you move through the repeat. This can also be combined with choose. The current automation engine is excellent and can pretty much do anything in yaml without templates. Templates only compliment them. And if you’re good enough, you can take long yaml automations and tighten them up with variable templates.
I’m so excited. I actually get to answer a question for petro! I stumbled across your comment here looking for something totally different (info on zwave.refresh_values).
The data: parameter of a service call DOES accept a template! I didn’t realize it myself until I tried it out helping out a fella on this thread. Maybe this has been added since your comment (this is an old thread after all) but I really don’t want to go back through all the release notes to check.
That guy never did report back if it worked for him but I tried it out locally with a test script to call another script in my config and it worked a treat.
I’m sure there has to be a more efficient way to do it, but this does work.
I do have a question. Is there an easier way to build the dictonary? I did something very similar here but it feels like there should be an easier way to work with the dictonary than building it as a string. Maybe not since that was the approach @123 used in this thread.
I use it to get around validation on yaml, like when you need to put a string representation of an object in a notification message. Normally that would fail with “Message needs to be a string”, but if you template the whole data section, it doesn’t validate the data for message.