Esphome - turn 2 lights on

I want to turn 2 lights on instead of 1 …

          - light.turn_on: 
              id: gangkeuken
              id: gangslaapkamer
              brightness: 1.0

when compiling it gives an error … Duplicate key “id”

what am I doing wrong ?
is there another way ?

full yaml :

binary_sensor:
  - platform: gpio
    name: "Keuken 0"
    id: buttonkeuken0
    pin:
      mcp23xxx: mcp23017_hub
      # Use pin number 0
      number: 0
      # One of INPUT or INPUT_PULLUP
      mode:
        input: true
        pullup: true
      inverted: true
    on_click:
      then:
        - if:
            condition:
              light.is_off: gangkeuken
            then:
              - light.turn_on: 
                  id: gangkeuken
                  id: gangslaapkamer
                  brightness: 1.0

            else:
              light.turn_off: gangkeuken
            #  light.turn_off: gangslaapkamer
    on_press:
      then:
      - if:
          condition: 
            light.is_off: gangkeuken
          then:
          - delay: 0.5s
          - while:
              condition:
                binary_sensor.is_on: buttonkeuken0
              then:
                - light.dim_relative:
                    id: gangkeuken
                  #  id: gangslaapkamer
                    relative_brightness: 5%
                    transition_length: 0.1s
                - delay: 0.1s
          else:
          - delay: 0.5s
          - while:
              condition:
                and:
                  - binary_sensor.is_on: buttonkeuken0
                  - light.is_on: gangkeuken
              then:
                - light.dim_relative:
                    id: gangkeuken
                  #  id: gangslaapkamer
                    relative_brightness: -5%
                    transition_length: 0.1s
                - delay: 0.1s

Thanks

I suspect that the error message is not really helping. I think the issue is that light.turn_on only supports one id.

Put two actions, one for each light.

got it ! thanks !

You can also group lights via Helper as an alternative option…

huh ?
a helper INSIDE Esphome ?
aren’t helpers a HomeAssistant thing, outside Esphome ?

You can make partition light and join multiple lights on that.
But what’s the point?, just copy-paste the light.turn_on for every light.

          - light.turn_on: 
              id: gangslaapkamer
              brightness: 1.0
          - light.turn_on: 
              id: gangkeuken
              brightness: 1.0

It helps if you understand how the order of operation works in code. Here is an example from my landscape lighting.

Everything below and tabbed to the RIGHT, they all belong to and are actions of whatever is above and to the left. Switch is all the way to the Left so, everything below it belongs to Switch. The first set of config options below and 2 spaces Right are the properties/configuration setings of Switch.

In that list of Switch configurations is the config for “turn_on_action” because it is a direct configuration of Switch and to give it a single action or a list of actions,
they will all line up below and 2 spaces to the Right.

  turn_on_action:   
         
      - light.turn_on: 
          id: center_flood
          brightness: 100%

so, anything below and tabbed Right will belong to “turn_on_action” which as 2 parts. The first is the action “light.turn_on” and to specify what configuration options belong to that light.turn_on:" so, it knows what light to turn on, they go underneath and tabbed to the right…

switch
  - platform: template
    name: "Pre-set Brightness Master"
    id: accent_led_master
    optimistic: true    
    turn_on_action:   
         
      - light.turn_on: 
          id: center_flood
          brightness: 100%
        
      - light.turn_on: 
          id: fence_led
          brightness: 40%

      - light.turn_on: 
          id: arborled
          brightness: 50%

 
    turn_off_action:  ## This config is aligned to the left and lines up directly underneath 
                               ## it's counterpart, "turn_on_action:" 
     
      - light.turn_off: center_flood
      - light.turn_off: fence_led     
      - light.turn_off: arborled



Hopefully that makes some sense and helps…

1 Like