Is it possible to detect if a simple switch turns ON twice?


#1

1) Give a description of the problem
Is it possible to detect if a simple switch turns ON twice?

I have a light which I want to turn on, wait for 15 minutes and then turn off,
BUT if another piston has also turned this light on during those 15 minutes of wait, then I want the 15 minutes will start again from the 2nd event.
(In short, i want the light to turn off after 15 minutes from the last action of “Turn On”)

I couldn’t find any event that is triggered when turning a light on while the light is already on.
Any idea on how can i achieve that?


#2

not 100% sure what you want to achieve but I believe using a variable is the way to go.


#3

In my mind, the easiest way would be to check if the light is on before you turn it on (in each piston that acts on the light). Just a simple “IF The_Light is not on” added to your other triggers.


#4

Seems like something simple like this might work:

if switch turns on
then
  with switch
    cancel all pending tasks
    wait 15 minutes
    turn off
  end with
end if

The cancel all pending tasks would cancel the previously set 15 minute timer and then you start a new 15 minute timer and then turn off. If the switch is turned off, the light would still go off an the turn off after 15 minutes would just do nothing. Not sure if this is your full intent.

Edit:
never mind. This would not catch repeated on commands from pistons (which are usually ignored). My bad.I think any piston that wanted to turn on that switch would be required to call a special control piston to make this work.


#5

Exactly, that’s the problem.

Turning ON the light when it’s already on won’t trigger this event.

@Pantheon your suggestion will work but i’m trying to avoid doing that as it will complex the automation.

The questions - is there a way to get a switch ON event even if the switch is already on?


#6

Not really… “On changing to On” won’t re-trigger the piston… Although, you can:

  • Add code to both pistons to reset the timer… or
  • Turn off and then Turn on, to reset the timer… or
  • Change another element of the light, and use that as the trigger (level, color, etc)

#7

If you create a ‘switch on the light’ piston and always call it instead of just turning on the switch then it would cover all situations except physically turning on the switch when the light is already on. Does slightly complicate any other piston that wants to turn on the light but other than what @WCmore suggested would be the only way to make it work.


#8

Well you could use webCoRE pistons with command optimizations disabled to control Virtual Switches and use ‘on events from’ to process the ‘change’ events. However, more generally it depends on who wrote the device handler.


#9

Thanks for the help guys,
I will try the suggested solutions.