Switch status for how long?

Hi, I am looking for something like this: IF a SWITCH has been ON/OFF >/< for a certain time, THEN.
It sure would be usefull to know the elapsed time within a switch. Maybe it's already a way of doing this. Any help is appreciated.

You can do some of that with Rule Machine, set up a rule like:

when switch * changes *
switch changes to on:
Wait (x) minutes
Do something
switch changes to off:
Wait (x) minutes
Do something else

But as far as an active timer that you can see, I don't know of a way to do that.

How are you wanting to "see" the time on/off? Notification, dashboard, something else?

When Cobra's website and apps are back up, his Super Tile Countdown flavor of Super Tile should get you a countdown on a dashboard, if that's what you're looking for, but what you actually want isn't clear to me.

If you do go with the rule in the first reply above, note that this will run every time that switch turns on or off and the timer will not "reset" if it gets flipped (within that timeframe), so you're likely to get unexpected behavior. Therefore, you likely want something like this instead:

Triggers:

Switch A *changed*

Actions:

IF (Switch A on) THEN
  Cancel Delayed Actions
  Delay 0:30:00 (cancelable)
  /* do other stuff here if needed */
ELSE
  Cancel Delayed Actions
  Delay 0:15:00 (cancelable)
  /* do other stuff here if needed */
END-IF

This will set a "timer" for 30 minutes after the switch is turned on at 15 minutes after it gets turned off (resetting if either changes before that's done). If you want a notification, you can do that where I've put "do other stuff here," but again, your goal isn't clear to me.

Hopefully some of this is helpful! Feel free to ask more.

Thank You all for your replies, but it is not a question about a timer. Say you have a virtual switch and you have a statement that checks this vitual switch for how long it has been off or on. If this time is within a certain time frame, the statement will execute. Is there something I'm missing?

I'm still missing something: what "statement" will check that switch to see how long it's been off or on? If you state your goal, someone might have a better idea, but without knowing what you actually want to accomplish, here's one idea for how you can do it in Rule Machine. Have one rule that tracks the state of the desired switch, then set a global variable (or two if you want to track both off and on) and "reset" that global variable (or two) when the time has elapsed. Here's an example:

Rule 1

Triggers:

Switch A *changed*

Actions:

IF (Switch A on) THEN
  Cancel Delayed Actions  
  Set Global Variable switchARecentOn to True
  Set Global Variable switchARecentOff to False
  Delay 0:30:00 (cancelable)
  Set Global Variable switchARecentOn to False
ELSE
  Cancel Delayed Actions  
  Set Global Variable switchARecentOff to True
  Set Global Variable switchARecentOn to False
  Delay 0:30:00 (cancelable)
  Set Global Variable switchARecentOff to False
END-IF

In any rule--including one with a trigger of whatever you're actually trying to do with the other switch or "statement" you're talking about--you'd then have these global variables available to check. If one is True, you know the switch has been turned on or off recently.

Thank You for your suggestions. Something like this then: