I modified the code to allow specifying data_eval
which is a single template that should evaluate to the valid structure for the data option. The downside is you have to specify every data option within it, but the upside is you can use a template for any part of it, including the data keys themselves.
action:
service: light.turn_on
entity_id: light.waqi
data_eval: >
{
"brightness": 255,
"rgb_color":
{% if is_state('sensor.waqi', 'Good') %}
[0, 255, 0]
{% elif ... %}
...
{% endif %}
}
I’m not sure how likely it would be for a change like this to actually go through though…
https://github.com/tboyce1/home-assistant/commit/180c18f521021f2cc07b26198be9ce278b6b9e80
I made a slightly safer version that expects the template to render to valid JSON rather than using eval()
, so maybe it’s more likely to get accepted.
https://github.com/tboyce1/home-assistant/commit/15ed8101495c33ab7788e8d972a55b5c9de4c85f