Multiple switches in light switch platform

Hi,

I’m sure this is an easy one for someone. I’m trying to add more than one switch in the light switch platform but all the methods to add a second switch have failed.can someone tell me the right way to do it?

Thanks

1 Like

Do you have any example code?

I am guessing you might be doing something like:

light:

  - platform: mqtt
    name: "KitchenCupboards"
    state_topic: "stat/sonoffKit/POWER1"
    command_topic: "cmnd/sonoffKit/POWER1"
    availability_topic: "tele/sonoffKit/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

light:

  - platform: mqtt
    name: "KitchenCeiling"
    state_topic: "stat/sonoffKit/POWER2"
    command_topic: "cmnd/sonoffKit/POWER2"
    availability_topic: "tele/sonoffKit/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

But you need to have it like:

light:

  - platform: mqtt
    name: "KitchenCupboards"
    state_topic: "stat/sonoffKit/POWER1"
    command_topic: "cmnd/sonoffKit/POWER1"
    availability_topic: "tele/sonoffKit/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

  - platform: mqtt
    name: "KitchenCeiling"
    state_topic: "stat/sonoffKit/POWER2"
    command_topic: "cmnd/sonoffKit/POWER2"
    availability_topic: "tele/sonoffKit/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

You also could do it like this, but I prefer the first option:

light 1:

  - platform: mqtt
    name: "KitchenCupboards"
    state_topic: "stat/sonoffKit/POWER1"
    command_topic: "cmnd/sonoffKit/POWER1"
    availability_topic: "tele/sonoffKit/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

light 2:

  - platform: mqtt
    name: "KitchenCeiling"
    state_topic: "stat/sonoffKit/POWER2"
    command_topic: "cmnd/sonoffKit/POWER2"
    availability_topic: "tele/sonoffKit/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false
1 Like

Hi Will,
It’s the light switch platform

light:
  - platform: switch
    name: Christmas Tree Lights
    entity_id: switch.christmas_tree_lights

How are you adding the additional ones?

Do the switches work OK before adding them as lights?

Then you should be able to define extra lights like so:

light:
  - platform: switch
    name: Christmas Tree Lights
    entity_id: switch.christmas_tree_lights

  - platform: switch
    name: Thermonuclear War Launch
    entity_id: switch.thermonuclear_war_launch
1 Like

Thanks Tom, I had not tried that! Works great!

To be fair it is the format @wills106 posted earlier.

I presume it is not possible to simplify the code further? I was thinking since all the light’s platforms are switches, it would be nice to somehow indicate that outside the list and apply to all, ie:

light:
  platform: switch
  - name: Christmas Tree Lights
    entity_id: switch.christmas_tree_lights

 -  name: Thermonuclear War Launch
    entity_id: switch.thermonuclear_war_launch