Light color based on input_select and xy_color/color_temp helpers

Hi all,

After using HA for quite some time now I am trying to make it more user friendly by adding certain settings to lovelace. What I want to achieve is the following:

A light can be set to a certain brightness and color via input_numbers. I do have this working using templates in the scripts that I call via automations. I do however want to make it a bit more sophisticated:

input_select, where xy_color or color_temp can be selected
input_number for entering the color_temp
input_text for entering the xy_color

The xy-color is working using the following piece of code:

service: light.turn_on
data:
  transition: 1
  xy_color:
    - '{{ states(''input_text.fg_default_color'').split('','')[0][1:] }}'
    - '{{ states(''input_text.fg_default_color'').split('','')[1][:-1] }}'
  brightness_pct: 25
target:
  entity_id: light.fg_door_lamp

This gets the X and Y colors from the input (i.e. [0.560,0.310]) and adds that to the light.turn_on service.

I do want to add the color_temp option too. Which I have working separately via the following code:

service: light.turn_on
data:
  transition: 1
  color_temp: '{{ states(''input_number.fg_default_color_temp'') | int }}'
  brightness_pct: 25
target:
  entity_id: light.fg_door_lamp

I am struggling to combine these two based on the setting of the input_select, which can be either color_temp (in which case I only want to add the color_temp to the light.turn_on service) or xy_color (in which case I only want to add the xy_color to the light.turn_on service)

How would I go about doing this? I guess even the header of color_temp/xy_color should be removed from the service call to make it work properly?

Thanks in advance.

I haven’t tried it yet, but apparently starting with the 0.115 release, keys inside service data can now be templated, too. See USE TEMPLATES DIRECTLY IN DATA AND SERVICE FIELDS.

If that doesn’t do it for you, then maybe use a choose statement???