Multiple Lights and grouping Automation headache

So I have two lights in the living room.
Say L1 and L2
I have three buttons on the Dash
L1, L2 and Lg for group

We usually only use L1 and often turn L2 on when needed. I created an input.boolean for when both are on, or when I want to turn both on. The button on the dash represents this input boolean.

So the scenarios are L1 on, L2 off or L2 on and L1 off then Lg off and only when both are on does the Lg show as on. Everything works fine there. The only issue is when I turn one of them off HA turns off the other light since its turning the Lg off which in turn has an automation to turn both off. I had all this in one automation.

So is there a alternative to what I am doing? I thought to use another input.boolean helper to show on dash only represent when they both are turned on manually but then would need to do more to identify which input.boolean was on and off…maybe I am over complicating this… help!!

alias: Living 1 & 2
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.living_1_2
    from: "off"
    to: "on"
    id: Living 1 & 2 On
    enabled: true
  - platform: state
    entity_id:
      - input_boolean.living_1_2
    from: "on"
    to: "off"
    id: Living 1 & 2 Off
    enabled: true
  - platform: device
    type: turned_on
    device_id: 5b1aa419019dbf965f18d5001316c98c
    entity_id: 7ba4bb2b471714c9c14668145590d898
    domain: switch
    id: Living 1 On
  - platform: device
    type: turned_off
    device_id: 5b1aa419019dbf965f18d5001316c98c
    entity_id: 7ba4bb2b471714c9c14668145590d898
    domain: switch
    id: Living 1 Off
  - platform: device
    type: turned_on
    device_id: 63d6a17f97952e327293d89bd96581b3
    entity_id: 5df9275b1f30fb618eadf87a7239009d
    domain: switch
    id: Living 2 On
  - platform: device
    type: turned_off
    device_id: 63d6a17f97952e327293d89bd96581b3
    entity_id: 5df9275b1f30fb618eadf87a7239009d
    domain: switch
    id: Living 2 Off
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Living 1 & 2 On
        sequence:
          - metadata: {}
            data: {}
            target:
              entity_id:
                - switch.stairs_living_1_lights_left
                - switch.garage_living_2_lights_right
            action: switch.turn_on
      - conditions:
          - condition: trigger
            id:
              - Living 1 & 2 Off
            enabled: true
        sequence:
          - target:
              entity_id:
                - switch.stairs_living_1_lights_left
                - switch.garage_living_2_lights_right
            data: {}
            action: switch.turn_off
            enabled: true
      - conditions:
          - condition: or
            conditions:
              - condition: and
                conditions:
                  - condition: trigger
                    id:
                      - Living 1 On
                  - condition: device
                    type: is_on
                    device_id: 63d6a17f97952e327293d89bd96581b3
                    entity_id: 5df9275b1f30fb618eadf87a7239009d
                    domain: switch
              - condition: and
                conditions:
                  - condition: trigger
                    id:
                      - Living 2 On
                  - condition: device
                    type: is_on
                    device_id: 5b1aa419019dbf965f18d5001316c98c
                    entity_id: 7ba4bb2b471714c9c14668145590d898
                    domain: switch
        sequence:
          - action: input_boolean.turn_on
            target:
              entity_id:
                - input_boolean.living_1_2
            data: {}
      - conditions:
          - condition: or
            conditions:
              - condition: trigger
                id:
                  - Living 1 Off
                  - Living 2 Off
        sequence:
          - action: input_boolean.turn_off
            target:
              entity_id: input_boolean.living_1_2
            data: {}
mode: single

hi… the code you have is hard for us to help becuase you’re using device id’s instead of friendly entity id’s.

could you switch to friendly entity_id’s? it’ll not only help us help you, but it’ll be better for you for lots of reasons. here’s more info:

i’m not 100% clear on your question, but i’m guessing that you’re saying when l1 xor l2 you want lg to be on (you don’t have a choice if you’re using the built in light group helper). and input_boolean to be off? so input_boolean is on only when both lights are on?

if so, here’s an approach for you. note that i made up entity names below. you should replace them with the correct ones.

alias: Living 1 & 2
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.living_1_2
    id: bool_changed
  - platform: state
    entity_id:
      - light.alcove_2
      - light.ccc_1st_floor_steps
    id: lights_changed
    to:
      - "on"
      - "off"
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - bool_changed
        sequence:
          - metadata: {}
            data: {}
            target:
              entity_id:
                - light.living_1
                - light.living_2
            action: light.turn_{{ trigger.to_state.state }}
      - conditions:
          - condition: trigger
            id:
              - lights_changed
        sequence:
          - action: input_boolean.turn_{{ "on" if ( states('light.living_1') == "on" and states('light.living_2') == "on") else "off" }}
            target:
              entity_id: input_boolean.living_1_2
            data: {}

Sorry about that. I am trying to change them all soon. I have done this one. I have 6 triggers. L1 on/off L2 on/off Lg on/off

alias: New L1 & L2
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.living_1_2
    from: "off"
    to: "on"
    id: Living 1 & 2 On
    enabled: true
  - platform: state
    entity_id:
      - input_boolean.living_1_2
    from: "on"
    to: "off"
    id: Living 1 & 2 Off
    enabled: true
  - platform: state
    entity_id:
      - switch.stairs_living_1_lights_left
    from: "off"
    to: "on"
    id: Living 1 On
  - platform: state
    entity_id:
      - switch.stairs_living_1_lights_left
    from: "on"
    to: "off"
    id: Living 1 Off
  - platform: state
    entity_id:
      - switch.garage_living_2_lights_right
    from: "off"
    to: "on"
    id: Living 2 On
  - platform: state
    entity_id:
      - switch.garage_living_2_lights_right
    from: "on"
    to: "off"
    id: L2 Living 2 Off
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Living 1 & 2 On
        sequence:
          - metadata: {}
            data: {}
            target:
              entity_id:
                - switch.stairs_living_1_lights_left
                - switch.garage_living_2_lights_right
            action: switch.turn_on
      - conditions:
          - condition: trigger
            id:
              - Living 1 & 2 Off
            enabled: true
        sequence:
          - target:
              entity_id:
                - switch.stairs_living_1_lights_left
                - switch.garage_living_2_lights_right
            data: {}
            action: switch.turn_off
            enabled: true
      - conditions:
          - condition: or
            conditions:
              - condition: and
                conditions:
                  - condition: trigger
                    id:
                      - Living 1 On
                  - condition: state
                    entity_id: switch.garage_living_2_lights_right
                    state: "on"
              - condition: and
                conditions:
                  - condition: trigger
                    id:
                      - Living 2 On
                  - condition: state
                    entity_id: switch.stairs_living_1_lights_left
                    state: "on"
        sequence:
          - action: input_boolean.turn_on
            target:
              entity_id:
                - input_boolean.living_1_2
            data: {}
      - conditions:
          - condition: or
            conditions:
              - condition: trigger
                id:
                  - Living 1 Off
                  - Living 2 Off
        sequence:
          - action: input_boolean.turn_off
            target:
              entity_id: input_boolean.living_1_2
            data: {}
mode: single

So I have subbed the entities and added this to my automations. Sorry yaml not my strong suite. Some elements the visual editor wasnt able to display, so will test.

thanks

alias: Living 1 & 21
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.living_1_2
    id: bool_changed
  - platform: state
    entity_id:
      - switch.stairs_living_1_lights_left
      - switch.garage_living_2_lights_right
    id: lights_changed
    to:
      - "on"
      - "off"
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - bool_changed
        sequence:
          - metadata: {}
            data: {}
            target:
              entity_id:
                - switch.stairs_living_1_lights_left
                - switch.garage_living_2_lights_right
            action: switch.turn_{{ trigger.to_state.state }}
      - conditions:
          - condition: trigger
            id:
              - lights_changed
        sequence:
          - action: >-
              input_boolean.turn_{{ "on" if (
              states('switch.stairs_living_1_lights_left') == "on" and
              states('switch.garage_living_2_lights_right') == "on") else "off"
              }}
            target:
              entity_id: input_boolean.living_1_2
            data: {}

Update: Nope didnt work. turning the boolean off set off a series of on’s and off’s between the lights. Yes your automation was enabled and none of the others.

ah… fooey. we’re going to need a way to distinguish between when the input_boolean is switched by a person changing the ui, verses when it’s switched because one of the lights when on or off.

here’s a way to do all of it. it’s even simpler, but you need to modify your lovelace button.

  1. create a template binary sensor (helpers->create helper->template). se the template like this. this replaces your input_boolean. but as a sensor, it will automatically update without needing automation.:

  2. one simple script (make sure the names of the sensor and switches are right. this is what will be called when you want to turn both lights on/off. it replaces toggling the input_boolean:

sequence:
  - action: >-
      switch.turn_{{ 'on' if states('binary_sensor.both_living_room_lights')
      == 'off' else 'off' }}
    target:
      entity_id:
        - switch.stairs_living_1_lights_left
        - switch.garage_living_2_lights_right
  1. create your dashboard card to call the script. but you can configure it to look like a light and to have the on/off state of the light. replace the script name below with the name of the script you did in step 2 and the name of the binary sensor to the one you made in step 1:
show_name: true
show_icon: true
type: button
tap_action:
  action: perform-action
  perform_action: script.toggle_both_lights
  target: {}
entity: binary_sensor.both_living_room_lights
icon: mdi:lightbulb

by doing this in the ui, it distinguishes between when the input_boolean (now template sensor) is turned on/off because one of the lights turned on or off, or versus when a person turned it on or off.

Oh Foey indeed.

I added the template sensor as follows

I added the action you mentioned in this automation

alias: New L1 & L2
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.living_1_2
    from: "off"
    to: "on"
    id: Living 1 & 2 On
    enabled: true
  - platform: state
    entity_id:
      - input_boolean.living_1_2
    from: "on"
    to: "off"
    id: Living 1 & 2 Off
    enabled: true
  - platform: state
    entity_id:
      - switch.stairs_living_1_lights_left
    from: "off"
    to: "on"
    id: Living 1 On
  - platform: state
    entity_id:
      - switch.stairs_living_1_lights_left
    from: "on"
    to: "off"
    id: Living 1 Off
  - platform: state
    entity_id:
      - switch.garage_living_2_lights_right
    from: "off"
    to: "on"
    id: Living 2 On
  - platform: state
    entity_id:
      - switch.garage_living_2_lights_right
    from: "on"
    to: "off"
    id: L2 Living 2 Off
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Living 1 & 2 On
        sequence:
          - sequence:
              - action: >-
                  switch.turn_{{ 'on' if
                  states('binary_sensor.both_living_room_lights') == 'off' else
                  'off' }}
                target:
                  entity_id:
                    - switch.stairs_living_1_lights_left
                    - switch.garage_living_2_lights_right
      - conditions:
          - condition: trigger
            id:
              - Living 1 & 2 Off
            enabled: true
        sequence:
          - sequence:
              - action: >-
                  switch.turn_{{ 'on' if
                  states('binary_sensor.both_living_room_lights') == 'off' else
                  'off' }}
                target:
                  entity_id:
                    - switch.stairs_living_1_lights_left
                    - switch.garage_living_2_lights_right
      - conditions:
          - condition: or
            conditions:
              - condition: and
                conditions:
                  - condition: trigger
                    id:
                      - Living 1 On
                  - condition: state
                    entity_id: switch.garage_living_2_lights_right
                    state: "on"
              - condition: and
                conditions:
                  - condition: trigger
                    id:
                      - Living 2 On
                  - condition: state
                    entity_id: switch.stairs_living_1_lights_left
                    state: "on"
        sequence:
          - action: input_boolean.turn_on
            target:
              entity_id:
                - input_boolean.living_1_2
            data: {}
      - conditions:
          - condition: or
            conditions:
              - condition: trigger
                id:
                  - Living 1 Off
                  - Living 2 Off
        sequence:
          - action: input_boolean.turn_off
            target:
              entity_id: input_boolean.living_1_2
            data: {}
mode: single

I added a button on dash.

So I could not even test the scenario when Lg is turned on. When both lights are turned on individually both lights went into a frenzy of on and off. Then turned automation off and then after everything settled I turned on the automation and clicked the new button on dash and nothing happened. It said scriptnot found. I know you said replace name of script, but I didn’t create a script, as you asked to create a template. Sorry prob don’t understawhat what you meant.

button yaml is

show_name: true
show_icon: true
type: button
tap_action:
  action: perform-action
  perform_action: script.toggle_both_lights
  target: {}
entity: binary_sensor.both_living_room_lights
icon: mdi:lightbulb

Update: Maybe I have stuffed up somewhere. Let me check again

sorry if I wasn’t clear.

step #2 is a script. Create a script with only that small single action. disable the automations you had. don’t add that to your automation. the 3 steps plus your existing group is all you need.

name that script something… Like toggle_both_lights… whatever the script name is, use that in the dashboard yaml in step 3.

oh right I did get it wrong. lol. Thanks will try ASAP. Ok the lights are now much better but its gotten complicated. Before the way I had it all was working ok until I turn off 1 and the other one would turn off as well.

With the change I made as per above its all over the place. If the lights are turned on one at time sometimes both stay on, sometimes one of them turns off. Dash button for script reflects the state perfectly when both on or off but clicking it on to off turns off both lights then turns on one of the lights. Same happens if I turn one of them off it turns on and sometimes not. Sorry very erratic but not continuously. I cant even make out a pattern really… It seems it might the delay in the script firing and action actually taking place.

sorry i’m not understanding the description. try again?

there’s a fundamental problem with the original way you had it… that you wanted different behaviors between when you manually turned off the input_boolean (ie, when you manually turned it on or off you wanted all lights to come on/off) versus when it was turned off by your automation (ie, if light1 went off but light2 is on, you wanted the automation to turn it off). so you need to separate those two actions apart. that’s why this approach does.

I think I might have not explained it well. So I have two physical light switches which are also replicated on lovelace dash. I also wanted to be able to turn both of them on/off if I need more light for whatever reason. To allow for this I created the input boolean and added it to the dash as well.
So what I needed was ability to turn on/off L1 and L2 individually and both if needed. Turning on both individually turns the input boolean on which indicates to me both lights are on. At this if I want both lights off I can click the input boolean on dash and both turn off. The issue only was when we only wanted to turn one off and leave the other on.
I started separating the input boolean and then adding another button on the dash to only represent the two lights being turned on one at a time but then when I click on it nothing happens, which means that would not work.

Hope I am making sense…

and to make sure i have the understanding right, the input_boolean you created is on only if both 1 and 2 are on. if only one of them is one, then input_boolean is off, and pressing input_boolean would turn the other light on, whichever isn’t on currently. then when they are both on (and therefore input_boolean) is on, then you can press it once and they both turn off.

sure, that’s simple enough and what i gave up above (the 3 steps) does that (plus the 2 individual dashboard switches you already have for light1 and light2. i tested it on my lights and it works. there should be no other automation.

here’s how it works. 1) the binary sensor is there only to detect when the new 1+2 light (it’s no longer an input boolean) should be on or off. you can see that sensor’s template checks for the left and right lights to both be “on”.

  1. the script - this is the full script. create it and name it toggle_both_lights. when this script is invoked, it looks and sees if the sensor from #1 is on or not. if it’s off (you can see it checks to == ‘off’) then it calls turn_on of the left and right lights. if that sensor is on, then it calls turn_off for those two lights.

  2. this creates a button on your dashboard. if you tap it, it will call the script.toggle_both_lights. it will use the sensor to show the on off state.

you can keep your light1 and light2 button on your dashboard to turn the light1 and light2 off individually.

at this point there are no loops calling circularly. i believe this does exactly what you describe. again, my 3 steps stand alone. all the other automation you have for this purpose should be disabled.

yes the input boolean is only on when both are on. I also had the input boolean as a button on the dash to turn both of them on/off. Ok gonna test it out again. Will post back as soon as I do. thanks again for the assist.

Update: Made sure all other automation’s are turned off.

Ok somehow it works perfectly. I am still trying to understand how. Lol
I am sure eventually it will make sense to me.

Thank you so much for the help.

which ended up working? you had marked your post as the solution. but i don’t see how that works.

was my solution back on the one prior the one that worked?

if mine was the one that worked, and you’re not sure how… i’m happy to explain…hit me w/ questions…

Sorry marked the wrong one. Now corrected. Yes that was the one. I guess I am trying to understand how the separation between the template when both are turned on individually are reflected at the Dash Lg button, as its also a button to launch a script. Wasn’t aware that can be done.

I guess the

entity: binary_sensor.both_living_room_lights

brings up the state and the following is the action

tap_action:
  action: perform-action
  perform_action: script.toggle_both_lights
  target: {}
1 Like

that’s exactly right. the sensor gives the state. and that other yaml specifies what to do when the button is tapped.

and the sensor works because of the template we put in.

Yeah its giving me ideas to eliminate other automation’s…lol always dangerous.

Yaml isnt my strong suite and templates are neither. Probably wont touch anything else.

well, holler if you need help!

1 Like