Inverting contact sensors for Normally open

My garage door sensors on my Elk are wireless CADDX sensors. Apparently they are normally open sensors. So in HE, when the doors are shut, the contact is open; and when the doors are open, the contacts are closed.

Is there a way in HE to tell it that it's inverted?

If you are using a custom driver, you can simply edit the code and swap the open/close events.

I have other contact sensors that are not inverted though.

Edit the code and save it with a new driver name.
"Elk Contact Sensor Inverted" or whatever you feel is appropriate. This way you will have a driver for each scenario.

I don't think it's that simple. There is one Elk driver, and it creates all the child devices. In the Devices section, the Elk shows up as a device, and it has all of my devices indented underneath it (this is the only driver that I've seen do this).

Another option is to create a virtual contact switch and make a rule that copies that state over but inverted.

Agree with @stephack here. Is the problem device the Double Garage Door? If so click into it and confirm the type is set to “Virtual Contact Sensor” as I believe it is based on your screenshot and my quick scanning of the Elk code on github. If this is the case then you would just need to create your own custom driver and invert the open and closed and set this device to use this new driver instead. This won’t affect any of your other child devices on the Elk.

1 Like

Agree with @ritchierich.
Also, I think your best option is to reach out to the developer of this integration. They are using the built in Virtual Contact Sensor driver. It should be fairly simple for them to build their own virtual driver with a toggle that would allow you to invert the readings based on the type of sensor you have. This way others can benefit and all the code will be in one place.

@signal15, give this driver a shot. There is a toggle to invert the open/close events.

https://raw.githubusercontent.com/stephack/Hubitat/master/drivers/Virtual%20Contact%20Sensor%20with%20Inversion/Virtual%20Contact%20Sensor/Virtual%20Contact%20Sensor.groovy

3 Likes

Ha, I was working on the same thing:
https://raw.githubusercontent.com/mlritchie/Hubitat/master/Drivers/Virtual%20Contact%20Sensor

3 Likes

:rofl: I won that race....
I figured I would need my this driver one day anyway, so why not build it now.

2 Likes

@stephack, I installed yours (since you posted it first.) :slight_smile:

It seems to work. However, I can only test it my manually clicking the button in the device because for some reason, my events are not registering. The debug log shows when the door is opened or closed, but they never make it to the event log for the device and the contact attribute never updates. No idea why this is. I emailed the guy who made the driver for the Elk, but haven't heard back.

The weird thing is, other contact sensors work. The only difference with this one is I manually deleted the garage door sensors which were discovered automatically because they came in as motion sensors, and then recreated them manually (in the Elk app) with the virtual contact sensor driver. Ever since I did that, the events stopped coming in.

At one point, I was getting an error that said I had duplicate devices. After I rebooted, I don't get that duplicate device error anymore, but it makes me wonder if there's something on the backend that I can't see that's a duplicate device and the HE is sending the events there instead of where it should send them.

Thanks for the driver!

The Virtual Contact sensor that you originally had was a child device. When an app or driver creates another, they are linked together. The creating device (parent) can talk to the created device (child). If you delete the child device, you are breaking this link. I don't know how your devices are linked together but you may need to start over at this point...you should talk to the dev to see if there is a way to automatically recreate the child device.

Once you have everything back to where it was and reporting as usual, you can then change the driver of the device without breaking the link between parent and child.

I recreated the child via the Elk app, it shows up as a child of the Elk.

Does it register the open and closed events with the stock driver?

Hi @stephack . I had a similar need to invert a contact sensor and came across this. I installed your custom driver and applied it to a zigbee contact sensor. I can manually change state in the UI but the sensor does not update state correctly. thoughts?

Unfortunately that's not how it works. The virtual contact sensor is just that "virtual". It can't be used directly with a physical zigbee contact sensor ...so you would need to re-apply the correct driver to your physical sensor. Then you can then setup a rule that ties your phyical sensor to the virtual one and use the virtual one in your dashboards etc.

1 Like

Thank you for this information.

1 Like