Virtual Contact Sensor "Close" State

I have a virtual contact sensor that closes a wifi lock via a routine in alexa. The lock will close as triggered, but how can I get the virtual contact sensor to "close", I would want it to auto close after a minute, but I do not know how to do this or get a work around.

This will need to happen in hubitat side I assume, but I know there are others who have mastered it, just need a little assistance for a novice user.

What happens when you open the contact sensor? If you want it to auto close, that implies it starts out open.

There are two ways to do this: one is to come up with a modified Virtual Contact Sensor driver that has an autoclose feature, and the other is to use a simple rule in Rule Machine:

That uses a 'custom action' to close the contact sensor, something a virtual contact sensor can do that a real one cannot:

As for the first way, which is better, there is a driver in our public repo called Virtual Omni Sensor, that includes a contact sensor, so could be used for this. It would take two lines of code to add an auto-close feature to that driver. See here: HubitatPublic/virtualOmniSensor.groovy at master ยท hubitat/HubitatPublic ยท GitHub

The two lines are, first

input name: "autoClose", type: "enum", title: "Enable auto close", options: [0:"Disabled",1:"1s",2:"2s",5:"5s",10:"10s",20:"20s",30:"30s",60:"1m"], defaultValue: 0

That would go after line 41.

And also this:

if(autoClose != null && autoClose != "0") runIn(autoClose.toInteger(),close)

That one would go after line 117.

3 Likes

Do I delete on whats on line 41 and 117 or do paste it on the last text?

Can you please send a screen shot on how it suppose to be displayed?

The code looks like this:

and