@mike.maxwell
At the present time, the only options for times are very short ones, the maximum being 5 seconds. Can this please be expanded, up to later, to 5 minutes.
Help yourself (5 minutes is 300000 msecs):
metadata {
definition (name: "Virtual Switch", namespace: "hubitat", author: "Bruce Ravenel") {
capability "Switch"
capability "Refresh"
}
preferences {
input name: "autoOff", type: "enum", title: "Enable auto off", options: [0:"Disabled",500:"500ms",1000:"1s",1500:"1500ms",2000:"2s",5000:"5s"], defaultValue: 0
input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true
input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true
}
}
void logsOff(){
log.warn "debug logging disabled..."
device.updateSetting("logEnable",[value:"false",type:"bool"])
}
void installed() {
log.warn "installed..."
off()
runIn(1800,logsOff)
}
void updated() {
log.info "updated..."
log.warn "debug logging is: ${logEnable == true}"
log.warn "description logging is: ${txtEnable == true}"
if (logEnable) runIn(1800,logsOff)
}
void parse(String description) {
if (logEnable) log.debug "parse ${description}"
if (description == "on") on()
else if (description == "off") off()
}
void refresh() {
sendSwitchEvent(device.currentValue("switch"))
}
void on() {
sendSwitchEvent("on")
if (autoOff != null && autoOff != "0") runInMillis(autoOff.toInteger(),off)
}
void off() {
sendSwitchEvent("off")
}
void sendSwitchEvent(value) {
String descriptionText = "${device.displayName} ${ (value == device.currentValue("switch")) ? "is" : "was turned" } ${value}"
if (txtEnable) log.info descriptionText
sendEvent(name:"switch", value:value, descriptionText:descriptionText)
}
4 Likes
Or you can use this one: