Handling a 2nd "switch physically changes to on" event?


#1

1) Give a description of the problem
My son and I are trying to create a “light cycling” feature. It’s our first attempt at WebCoRE. We have a wall switch that controls the ceiling light, and a socket that controls a lamp. Switch 6 is the wall switch controlling the ceiling light, and switch 8 is the socket.

2) What is the expected behavior?
When we click the switch “on” to turn on the ceiling light, we want to toggle the lamp. So, the first time we turn the switch on, the ceiling light comes on (default behavior). If we hit “on” again, turn on the lamp too. Hit it a 3rd time, and the lamp turns off.

3) What is happening/not happening?
The following event handler doesn’t fire when “Switch 6” is already on.

if Switch 6 physically changes to on

**4) Post a Green Snapshot of the piston!

So, is there another event or something I can try? I want to handle a 2nd “on” when the light is already “on”.


#2

Check out the post below. I don’t think there is any way to turn a switch on twice. I think you will have to set a timer and check if you toggle the switch x times within y seconds. I can try to put something together but it will be a variation of @Gopack2’s switch time piston. Right now it’s too late and I need to go to bed. :sleeping:


#3

Perhaps an easier method is to have it cycle thru 4 variations, instead of 3. Something like this:

  • 1st On = Switch On
  • 1st Off = Lamp On
  • 2nd On = Both On
  • 2nd Off = Both Off

If you like this concept, the coding is quite simple:

IF Switch changes to Off  <-- Trigger
Then
    IF Lamp is On         <-- Condition
    Then
        Turn Off Lamp
    Else
        Turn On Lamp
    END IF
END IF

(No coding is needed for when the switch turns on)


#4

Ok, I get it. Good idea. So maybe, if he turns it on twice in 2 seconds, or something like that, the lamp comes on as well. I’ll play with that. Thanks


#5

Ok, that’s a good idea. My only issue is that intuitively, “off” should be just plain “off.”

Yeah, the first mistake we made was thinking we needed to programmatically turn on the ceiling light when the switch turned on. Newbie mistake, I’m sure. That comes without any code at all.

Your idea seems pretty straightforward. Every time the ceiling light is switched off, toggle the lamp. Going back and looking at what my son wrote yesterday, he did something very similar, once we understood that the On and Off triggers don’t fire a 2nd time. I didn’t understand at the time what he was doing, but he liked it. His code was just: if switch ON (trigger), toggle the lamp.


#6

You can definitely ‘invert’ my code above if it suits you…
Even something like this if it’s more intuitive for your family:

  • 1st On = Both On
  • 1st Off = Lamp On
  • 2nd On = Switch On
  • 2nd Off = Both Off

(the sequence comes out differently than my previous example)

IF Switch changes to On  <-- Trigger
Then
    IF Lamp is On        <-- Condition
    Then
        Turn Off Lamp
    Else
        Turn On Lamp
    END IF
END IF

Unfortunately, neither of these versions turns off both lights each time you press off. (only every second press) That concept would require substantial more code, and likely the use of variables.