Setup new Virtual Contact with Auto Off from the User code by cwwilson08

I've used it before but this time when I go to the preferences tab I get the option to Enable Auto On/Off but I don't get the ability to set the delay. Is that no longer possible or is something not working with that driver anymore? Thanks!

Is the input setup for auto off to have options for "Disabled" as well as times for delay? You may need to open that input selection to see the times, and it gets enabled when you choose a delay.

Something like this, on the driver I use:

input name: "autoOff", type: "enum", description: "Automatically sets contact closed after selected time.", title: "Enable Auto-inactive", options: [[0:"Disabled"],[1:"1s"],[2:"2s"],[5:"5s"],[10:"10s"],[20:"20s"],[30:"30s"],[60:"1m"],[120:"2m"],[300:"5m"],[600:"10m"],[1800:"30m"],[3200:"60m"]], defaultValue: 0

This is all that is on the Preferences tab.

It would be helpful if you could provide a link to the code. But maybe you were using a similarly named driver by a different author previously?

It has been a long time since i looked at any of this code.

A few forum search shows the original code and also some more variations with modifications. I dont remember if i added the auto off or someone else did.

If you are using the code noted in the below post it looks like the auto off is hardcoded for 12 seconds with no input option to change it.

It shouldnt be too hard for someone to add an input if sondesired.

1 Like

Ya this is the code:

metadata {
definition (name: "Virtual contact with auto-off Switch", namespace: "cw", author: "cwwilson08") {
capability "Sensor"
capability "Contact Sensor"
capability "Switch"
}
}

preferences {
section {
input (
name: "AutoOff",
type: "bool",
title: "Enable auto off",
required: false,
displayDuringSetup: false,
defaultValue: false
)
}
}

def on() {
sendEvent(name: "contact", value: "closed")
sendEvent(name: "switch", value: "on")
if (AutoOff) {
runInMillis(500, off)
}
}

def off() {
sendEvent(name: "contact", value: "open")
sendEvent(name: "switch", value: "off")
}

def installed() {
}

I thought it had a option for the auto off but I see now it's hard coded. Easy enough to tweak that. I must have been thinking about a different auto off driver.