How do I modify/append yaml properties based on template conditionals?

I’m having trouble setting the color_temp of a light. Since you are unable to set the color & color_temp at the same time, I’d like to set one or the other based on a variable. For example, something like:

  action:
  - service_template: light.turn_on
    data:
      entity_id: '{{ trigger.event.data["name"] }}'
      {% if trigger.event.data["color"] == 'softwhite' } 
      color_temp: 350 
      {% else %}
      color_name: '{{ trigger.event.data["color"] }}'
      {% endif %}

Any insight would be greatly appreciated! Thanks

I don’t think you can template yaml data keys like this.

You’d be better off exploring a choose or if-then-else, using your trigger.event.data to set different templated conditions.

1 Like