[RELEASE] Switch Timer with Reset

Switch Timer with Reset
Modified version of @Cobra Switch Timer driver, with a reset if switch is triggered again before delay expires. It is 99% @Cobra code, I just added the reset for an application I needed.

Features:

  • Switch driver that has automatically switches OFF/ON after configurable delay
  • Configurable delay reset option - if switch is triggered again before delay expires, reset the delay timer
  • Unschedules any scheduled delay OFF/ON events if switch manually turned OFF/ON before delay expires

Installation:

  1. Install Driver code in Hubitat
  2. Create new virtual device, and define type as Switch Timer with Reset
  3. Open virtual device and configure preferences

Driver can be found on my GitHub

V1.0.0 - 1/5/19 - Initial Version

1 Like

Can I ask a question....if a switch is on, how do you "trigger it again"? Do you mean toggle it twice (off and back on)?

A few ways, actually. Click the ON button from device details, write ON to it from app/code, etc.

Every time the ON event is triggered, regardless what the current state of the switch is, the ON event code runs.

Another example:
An RM sets a switch on when a door contact opens. Every time the contact opens, it triggers the switch ON event - RM does not look at the state of the activity device. Whether the switch is ON or OFF, it just sends the ON command when told to.

So every time the door opens, the switch timer resets. I use this for a few things I don't want repeated in a high frequency if people are coming in/out of the door. I find this more straight forward than using the RM private boolean/off delays to prevent quickly repeated executions.

But there are many ways to do the same thing.

Could also use it for a watchdog or dead man timer, too. And with a small code changer could use it as a '# of times something happened within a time period' counter.

1 Like

Okay...so this is more of a "variable storage device" than a device you would actually interact with then? That makes sense to me. I was sitting over here going, "If you trigger an on switch, it turns off". I was not going that route. I was like, "Is this guy losing it or is it just me?" :stuck_out_tongue:

I do the same thing but with PB. Like you said, many ways to do the same thing. Thanks for explaining though.

1 Like

Well, I use one RM to mirror a door contact to the virtual switch.

Then I use that virtual switch for all of the logic/RM/apps I want to use that contact for,

Hi!
I'm just getting started with Hubitat, so please excuse my basic understanding on custom code. Also, I have a Hubitat C7 hub running version 2.2.7.126 (the latest as of May 2021).

I know this is an old post but what you describe is EXACTLY what I want to do:

  1. Upon press of Button 1, turn on Outlet 1 and start timer for 10 min. After timer expires, turn off Outlet 1
  2. If Button 1 is pressed again before timer expires, then restart timer for another 10 min (OK if another "ON" is sent to Outlet 1).
  3. If Button 2 is pressed at any time, Turn off Outlet 1 (OK if timer continues to run and/or another "OFF" is sent to Outlet 1)

I figured out how to do this with Habitat's Basic App EXCEPT for resetting the timer. In the basic rules, I can't see any way to reset the timer.

In your post, you said "driver can be found on my GitHub". My question is that there are several files but none seem to be related to "Switch Timer with Reset". Could you tell me which file(s) I should download?

Thanks!

This is awesome. Thank you for sharing. I used this to automate the closing of my garage door.

I used an IFTTT applet to turn on my garage lights (Hubitat connected switch) and this switch (Hubitat connected) when my garage door (MyQ) is opened.

Then I created another IFTTT applet to close my garage door when this switch turns off.

Then I added a motion detection trigger (Alexa connected Cloud Cam) to turn on this switch which keeps resetting the timer while there is motion in the garage, this functions as a motion delay on the timer.

This is a bit of a work-around, but it is required due to MyQ's lack of integration options.

Blast from the past here... I forgot I even made that driver. lol

EDIT: I should really say I forgot I modified Cobra's switch driver to add a few more features. LOL

Glad it is still working!

1 Like

Nice driver! It covers a serious gap of hubitat. I use it multiple times for the timing of several rules at the same time.

But a hint for use: Better not copy a line containing a condition with such a device (to another rule). Pasting leads to the error "Command 'currentValue' is not supported" and the rule is defect.
And the import of a rule with such a device causes defect devices in these conditions.

@JasonJoelOld
I've done the installation.
image
But I don't understand how you would use this timer.
I my mind I would associate the timer with another device somehow but don't see a way to do that in the timer preferences.
Can you give some specific steps or examples?
Thanks for doing this timer.

Steve

I can see a lot of uses for this device/driver, but I'm having trouble benchtesting it when using the device in a rule's "Required Expression".

I have a button device that I want to do different things when it is pressed, depending on how recently it was pressed. For example, if the button has not been pressed in the last 15 seconds, I want it to trigger "rule 1". If the button has been pressed in the last 15 seconds, I want it to trigger "rule 2". I want rule 2 to also turn off the timer immediately.

Ruie 1 has a required expression of "if timer is off...". Rule 2 has a required expression of "If timer is on...". The timer is defined as "Default state = off", "OFF = seconds", and "Delay before on/off = 15". The timer works as expected, i.e., when it is turned on by a rule, it turns off after 15 seconds. If a different rule turns the timer off before the 15 seconds is up, it turns off immediately.

The problem I'm having is that the rules always evaluate to "timer off". If I press the button once, then again 5 seconds later, the second button press drives "rule 1" as if the timer is still off, instead of driving "rule 2". I can see on the device panel that the timer is on when I press the button the second, third, etc., times within the 15 second window.

Any suggestions?

I created two more rules. One writes a log message when the virtual timer is turned on. The other writes a log message when the virtual timer is turned off. When I turn the timer on or off from the device screen (or it turns off because the time expired), I can see the log messages from the driver, but I don't see any log messages from the two new rules.

Is there something that has to be done to make an on/off event from this driver capable of triggering a RM rule?