Turn off first light in a set of 3 when third is turned on


#1

1) Give a description of the problem
My apartment has what is essentially one large room containing my kitchen, living room area, and computer desk. Each of those has a light but I never need more than 2 on at a time.

2) What is the expected behavior?
I’d like to create a piston (or multiple if necessary) that turns off the first light that was turned on if both of the others have come on.

3) What is happening/not happening?
Nothing is happening yet. This is my first relatively complex WebCoRE piston so I’m at a loss on how to begin even after poking around a bit. I have enough experience with other automation software (mainly Tasker) to learn quickly but also to know I could quickly trap myself in a loop where my lights are turning off every time I turn them on.

Thanks for your help! I’m loving the ST community so far and this seems like a wonderful extension of it.


#2

I haven’t tested it but it should work.

Created from my mobile at work.

Give this a try.

Fill in the names of your 3 lights in the All3Lights variable at the top.


#3

Thanks! I’ll check out when I get home. When you have a chance, could you give me a brief explanation of what it’s doing? Variables are my sticking point in WebCoRE right now and I learn best with examples. I’ll poke around in the script, too, to see what I can learn.


#4

Ok. Here goes.

LatestLightSwitchedOn.
This is storing the name of the device that was most recently switched on from the 3 in the All3Lights variable.

All3Lights.
This is storing the 3 lights that you want to monitor.

3rdLightOn.
This is copying the information from the LatestLightSwitchedOn block and storing it as the 3rd light you switched on.

2ndLightOn.
This is copying the info from 3rdLightOn variable.

1stLightOn.
This is copying the info from 2ndLightOn variable.

Effectively passing the information down from 3-2-1.

Ending in 1stLightOn being switched off every time another of the 3 lights is turned on.

This should make the 1st of the 3 lights go off every time the 3rd Light is Turned on. Therefore only allowing 2 of the 3 lights to be on at any one point in time. :grinning: please do bear in mind that after the first one is switched off then the second light you turned on now becomes the first light that was switched on out of the remaining 2 lights that were on so next time one of the 3 lights is switched on then this will become the new one that gets switched off and the loop will continue to evolve.

The second If block empties out the variable containers once all 3 lights are switched off so that you don’t run into the wrong lights going off after they’ve all been switched off.

HOPEFULLY IT WORKS! :flushed:


#5

It seems to be working! Though I’m not actually at home watching the lights themselves (my dog, however, probably thinks he’s going crazy).

Thanks again for your help!


#6

Clever dog ay!
22D924C4-E20F-43A6-B9F5-9AB016FB8A2A


#8

So in an unrealistic test of turning the lights off and on randomly, it runs into the problem of possibly switching off one of two lights as it isn’t dumping the variables until they’re all off, as you said. A possible solution I see (but don’t know how to implement) is always moving active lights up to the first and second slots when something is turned off. Is that possible?


#9

If you can explain an example of what you want to happen in the situation of when the first light you switched on is turned off by a third coming on. Which light do you then need switching off once the next 3rd(4th) Light is switched on.

So like. At the moment
Switch on 1 = 1 On
Switch on 2 = 2 On
Switch on 3 = 3 On 1 Off.

What do you want to happen when

Switch on 1 again? Because currently 2 will go off.

Hope that makes sense.


#10

Hmm. It’s becoming clear there are questions I haven’t answered yet. I’ll trial what you’ve given me for now and come back if I need more help or can’t learn to modify it myself. Thanks for your help!


#11

if it turns out that there is always one light that you want on all the time once all three have been turned on, then it will be easy to set up, so once the 3rd has turned on and the 1st off then you would want the (middle) 2nd one say to stay on and the (left) 1st and (right) 3rd ones to toggle between on and off… that would be simples :grin:


#12

this should work no matter which lights are turned on or off randomly. no more than 2 lights will stay on simultaneously. if a 3rd light is turned on the light that was turned on first will be turned off so only 2 lights are on at any given time.