[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.

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

Download the Hubitat app