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.
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.
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.
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.:
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:
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:
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.
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.
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.
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â.
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.
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.
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