How to get a single switch button on HA for two light switch

I know this is the configuration for lights in HA:

light:
  - platform: mqtt
    schema: json
    name: mqtt_json_light_1
    state_topic: "home/rgb1"
    command_topic: "home/rgb1/set"
    brightness: true
    rgb: true

But if I have to make a configuration such that, I can start two light switches at the same time as well as one at a time. I will have to deal with command topic for that but not getting any information to get a common light switch on screen to switch both of the lights at the same time.

Any help will be appreciated.

Thanks in advance.

Hm, don’t understand exactly what you want, but switching 2 lights with 1 button could be easily achieved with an automation. For example, button press turns on both lights. Button press again turns them off. However this will not make it possible to switch both lights separately (or you would have to add conditions to it).

Thanks @jimz011 for replying, as you described that I can have a single button for both the lights what would be my configuration in configuration.yaml file?

Also my plan is to switch then on and off simultaneously but also I can switch then on and off separately one at a time, is it possible?

Thanks again.

Put your two lights in a group and/or Lovelace entities card.

You can switch the group on and off using the group or Lovelace header toggle or individually using the switches for the lights.

Have a look here:

I have multiple lights in the bedroom and multiple switches, but they all work the same, so you can just focus on one switch.

this is what it does:

  • single click: toggle dedicated light (a plug in my case)
  • long press : toggle ceiling light
  • double click: switch off all lights

You could adjust that for your needs and depending what actions you can get from your switch. Mine are the Xiaomi Buttons (the old ones)

Most proper way to do this is probably setting up a group. But someone reacted before I had the chance :stuck_out_tongue:

I will post an automation based on this when I get home. Doing this on a phone is horrible haha. But what it comes down to is that your trigger would be the button and the action will be toggling the group you’ve set up.

I will add the code later on (within 2 hours or so) when I have a proper computer available. Though the other answer with the single/double/triple click is something you might consider as well if you are looking for something more flexible.

Edit: just checked his github page and it uses an Aqara button for this (made by xiaomi). This single/double/triple click might only work with those buttons. I don’t know what kind of button you use. But by the looks of it it is probably something like a Sonoff (or other mqtt button). I doubt the automation will work for your case. But if you do have an Aqara button than you could just use his automation as it is perfect for those button.

Create a group that contains your two or more switches. Then you can turn the group off/on or the individual lights.