Toggle multiple switches with one click

Hi,

I’m new to HA, so I’m sorry if this is something that has been asked previously.

I made a 3D floor plan of my house inside a Picture Elements Card, and each room consist in two layers with lights on and off. In every room I placed a ‘mdi:lightbulb-on-outline’ icon so I can click on it and turn the corresponding light on or off.

The room turns on when the light is on and goes back to dark when the light is off.

The ‘mdi:lightbulb-on-outline’ icon is grey when the light is off and turns yellow when the light is on.


I am trying to replicate the same behavior for my living room, where I have 3 different switches that toggle 3 different lights. I want to be able to toggle all the lights in my living room with just one switch, so I can have my ‘mdi:lightbulb-on-outline’ icon changing color from grey to yellow, as well as my living room image layers switching between dark and illuminated.

I created the following script:

device_id: 38a6462cbafb499b8c37c85a6bc5b4d0
domain: switch
entity_id: switch.livingroomlights1
type: toggle

device_id: 38a6462cbafb499b8c37c85a6bc5b4d0
domain: switch
entity_id: switch.livingroomlights2
type: toggle

device_id: 38a6462cbafb499b8c37c85a6bc5b4d0
domain: switch
entity_id: switch.livingroomlights3
type: toggle

Then I added that script inside my Picture Elements Card on my lovelace UI. I changed the script icon to ‘mdi:lightbulb-on-outline’ and the lights turn on and off correctly, but my '‘mdi:lightbulb-on-outline’ remain grey.

I would like to know if there is a way to change the color of the living room icon according to the on / off state, just like in the other rooms of the house.

Any help is gretly appreciated!

Marco

Did you set state_color to true in your picture elements card?

Hi ceh,

no I think I haven’t.

This is an extract of my picture elements card for the corridor light:

  - entity: switch.corridorlight
    icon: 'mdi:lightbulb-on-outline'
    style:
      left: 54.5%
      top: 51%
    tap_action:
      action: toggle
    type: state-icon

The one for the living room lights looks the same with the only difference that I’m calling a script instead of a switch.

Sorry for the noob question, but where exactly should I specify the state_color value?

I believe you set it as below. The default value is supposed to be true, so this may not help, but I think it’s worth a try.

  - entity: switch.corridorlight
    icon: 'mdi:lightbulb-on-outline'
    state_color: true
    style:
      left: 54.5%
      top: 51%
    tap_action:
      action: toggle
    type: state-icon

Thanks ceh,
I specified the state_color value as ‘true’ but the light-bulb icon still remain grey :frowning:

I think its because a script hasn’t got a state, it is just executed.

Try making a group with your switches and using that group for the switch.

Or you might want to make a template light with each of the switches so they show as lights and the you can make a light group which will appear as a light entity

You may have to restart HA before you create the light group

light:
  - platform: switch
    name: Living Room Light 1
    entity_id: switch.livingroomlights1

  - platform: switch
    name: Living Room Light 2
    entity_id: switch.livingroomlights2

  - platform: switch
    name: Living Room Light 3
    entity_id: switch.livingroomlights3

- platform: group
  name: Living Room Lights
  entities:
    - light.living_room_light_1
    - light.living_room_light_2
    - light.living_room_light_3
1 Like

Hi Holdestmade,

yup, script definitely doesn’t let you know his state, it’s just a one-time run thing and that’s it. That’s why my light-bulb icon doesn’t change from grey to yellow.

I followed your instructions and I was able to create light switches for my living room lights in my configuration.yaml file

I then created a group in my group.yaml file where I added all the light switches of my living room.

I then linked that group as an entity in my picture elements card so that I could toggle it on or off as follow:

  - entity: group.livingroomlights
    icon: 'mdi:lightbulb-on-outline'
    style:
      left: xx.x%
      top: xx.x%
    tap_action:
      action: toggle
    type: state-icon

But the light-bulb icon color still doesn’t change.

I think that you are right and I should use a template. I read the documentation provided and I am kinda overwehlmed.

I think that “CHANGE THE ICON” is the closest example that I have to follow but I am a bit lost as to how and where to specify the color, since I just need a change of color based on the state of my group.livingroomlights entity and not a change of icon.

Can you please help me out on how to configure this template based on my group name/switches?

Also, another stupid question maybe, but once I have the template laid out, do I have to do something in particular or is it just a matter of intergrating it via raw editor of my picture elements card?

Thank you!

The light group is created in light:

The entity will start with light. and not group.

That will then work as a light.

1 Like

Hi Holdestmate,

sorry, I thought that I had to create the group under group.yaml file.

Doing as you suggested worked out perfectly!

Thank-you thank-you thank-you!

Marco

No probs, glad it worked out.

1 Like