Mixing both template lights and virtual lights in configuration.yaml?

Hello everyone, I’ve been learning HASS/Node-RED fast enough to migrate all of my SmartThings/WebCoRE automations to HA, but I’m still far behind in understanding how YAML works and how it is supposed to be written. I’m mostly copying and pasting stuff and checking if it works :S

When I first started, I created some template lights, because I just needed “virtual dimmer” devices with “brightness” control (which are not really lights, they are just variables that I can set using Google Assistant).
They look like this in the configuration.yaml file:

light:
      next_wash_cycle:
        friendly_name: Next Wash Cycle
        turn_on:
        turn_off:
        color_template: "({{states('input_number.h_input') | int}}, {{states('input_number.s_input') | int}})"
        set_level:

Now I was going a bit deeper and I needed to create an RGB virtual light with color temperature setting too, so I installed Virtual Components and created that other light in the configuration.yaml:

light:
  - platform: virtual
  living_ceiling_light:
    name: 'Living Ceiling Light'
    initial_value: 'on'
    support_brightness: true
    initial_brightness: 100
    support_color: true
    initial_color: [0,255]
    support_color_temp: true
    initial_color_temp: 255
    support_white_value: true
    initial_white_value: 240
    initial_availability: true

After creating this, I noticed that the first lights disappeared, and Studio Code Server says “duplicate key” to the right of “light:”, but I can’t find a way to “mix” these two different types of virtual lights into the same structure.

Could anyone point me on the best direction to go here? Should I ditch any of these methods and use only one? Is it possible to keep them both together?

Thank you!
R.

You can only have a single instance of each top level domain key in any given file, you need to remove light: from the second one and properly format you entries into a list.

light:
  - platform: template
    lights:
      next_wash_cycle:
        friendly_name: Next Wash Cycle
        turn_on: ## A TURN ON ACTION IS REQUIRED ##
        turn_off: ## A TURN OFF ACTION IS REQUIRED ##
        color_template: "({{states('input_number.h_input') | int}}, {{states('input_number.s_input') | int}})"

  - platform: virtual
    name: 'Living Ceiling Light'
    initial_value: 'on'
    support_brightness: true
    initial_brightness: 100
    support_color: true
    initial_color: [0,255]
    support_color_temp: true
    initial_color_temp: 255
    support_white_value: true
    initial_white_value: 240
    initial_availability: true
1 Like

Thanks @Didgeridrew for your reply, it seems I needed to add a dash to the first “platform” for it to work. Also, I was thinking that the lines below the virtual platform needed more spaces at the start, but it is working this way now :slight_smile:

One more question, I see these “## A TURN ON ACTION IS REQUIRED ##” in your reply, also Studio Code says “incorrect type, expected object”. Do I need to write something here or is it ok like this?

Thanks,
R.

You need to specify an action as you would in a script or automation. Truthfully, I’ve never tried to set one to a null value like you had in your original, so I can’t say it won’t work… but the docs state that turn on and turn off actions are required.

1 Like