Sonoff - mqtt - multiple lights

Need some help with config of the light component when with multiple lights. I understand that I need two different topics for the mqtt but cant figure out how to set up the config for lights when having more than one light. Do I use the “devices” to separate and if so - how?

Below example of set-up with one light.

light:
  - platform: mqtt
    devices:
    name: "Köksfönster Vänster"
    state_topic: "stat/sonoff/POWER"
    command_topic: "cmnd/sonoff/POWER"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    retain: true

e.g.

light:
  - platform: mqtt
    name: "Family Room bright lamp"
    state_topic: "stat/sonoff-001-FRbright/POWER"
    command_topic: "cmnd/sonoff-001-FRbright/POWER"
    availability_topic: "tele/sonoff-001-FRbright/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: true

  - platform: mqtt
    name: "Jane's Study downlights"
    state_topic: "stat/sonoff-002-JSdown/POWER"
    command_topic: "cmnd/sonoff-002-JSdown/POWER"
    availability_topic: "tele/sonoff-002-JSdown/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: true

Of course, you will need to set the MQTT topics properly on the sonoff devices first.

Yep it’s as simple as @PianSom says, go into the Mqtt config in the second Sonoff’s web UI, change the topic field which from your code will currently say just ”sonoff” to for example ”sonoff2”.

Then in your HA config copy and paste the code you have for the first one and in the second one change name: to whatever you want to call it and then change

state_topic: "stat/sonoff/POWER"
command_topic: "cmnd/sonoff/POWER"

to

state_topic: "stat/sonoff2/POWER"
command_topic: "cmnd/sonoff2/POWER"

Thank @Bobby_Nobble and @PianSom! It all works now! :slight_smile:

1 Like