Tasmota device with auto off options

@garyjmilne is there a way to configure a switch to act as a button, or with an option like to Enable auto off option?

I modified a Sonoff switch to act as a dry switch to use it at a garage door connected to the door motor, but it just turns on or off.

The option I am looking for is like the one that is included on a Virtual switch like this, with the Auto off option

I guess I can set a RM rule that takes care of the switch turning on, and after a second change to off, but just want to make sure there is no easier way to do it.

Thank you for your help.

As you said you could add it to the driver like this:

input name: "autoOff", type: "enum", title: "Automatically switch back to off this many seconds after being turned on:",
options: [[0:"Do not automatically switch off"],[1:"1 second"],[2:"2 seconds"],[5:"5 seconds"],[10:"10 seconds"],[30:"30 seconds"],[60:"60 seconds"],[120:"120 seconds"],[300:"300 seconds"]]

//What happens when switch is set to on.
void on() {
if (logEnable == true) log.debug "on()"
if (txtEnable == true && device.currentValue("switch") != "on") log.info "${device.displayName} is on"
if (state.isSwitch == true) {sendEvent(name: "switch", value: "on")}
if (autoOff) {
Integer disableTime = autoOff as Integer
if (disableTime > 0) {
runIn(disableTime,"off")
}
}
}

Or do it via Rule Machine.

Pro's and con's to each approach.

1 Like

If it’s a tasmota device you can set a rule for this on the device itself.

Rule2 On power1#state=1 do backlog delay 10; power1 0 endon

Rule2 1

2 Likes

Of course, great catch! Only thing to bear in mind is that you can't turn it off too quick otherwise the rule that does the Hubitat sync won't work. A wait of 2 or more seconds should be sufficient.

1 Like

Just change delay 10 to 20 or whatever you need. It’s 0.1 second values.

Yes this is exactly what I was thinking about.

One thing to bear in mind - I suggested rule2 - assuming you might have a rule1 already. Check to make sure you’re not already using rule2 before overwriting it. I can’t recall which rule the community tasmota driver uses.

You can check rule1 through rule3 by simply typing rule1 in the console and check if there’s already a rule written and if the rule is on.

@woodsby thank you for your help.

I’m in the process of doing some testing with different options, starting from easy to not-so-easy.

In tasmota this is called pulse time You can set it right on the device in the console..

2 Likes

I forgot all about pulsetime. That’s definitely more elegant… then a delay and power off command.

2 Likes