currentValue for contact is open (i.e. not updated), even though latest event says closed

Hi,

I have a strange issue with currentValue(...) not updating. I have an app that reads multiple contact sensors and pass on the information to a "master" contact sensor. The master contact sensor I use as an indication on my dashboard to tell me if any of the contact sensors are in "open" state. However, I see quite often that the master says "open" even though all contact are closed. I have tried to debug this issue now for quite some time, and I see the following strange behavior: if I read the currentValue("contact", true) I receive "open", however if I read the latest event on the device the event is closed. See code below:

Using currentValue:

log.debug door.label + ": " + door.currentValue("contact", true)

2020-10-27 22:26:04.972 [debug] Kontaktsensor ytterdør: open

Using events:

log.debug door.label + ": " + door.events()[0].name + " - " + door.events()[0].value

Result: 2020-10-27 22:26:04.994 [debug] Kontaktsensor ytterdør: contact - closed

Even stranger is that the dashboard status is correct for the contact sensor (Kontaktsensor ytterdør) but not for the master (Åpen dør):

Anyone have any idea what is going on? Is this a system bug.

The only way I can fix the issue is by opening and closing the contact sensor that reports the wrong value.

Any difference if you read the cached value

door.currentValue("contact")

Instead of the db value

door.currentValue("contact", true)

I would guess no, but was curious.

Thanks for the reply. The skip cached value was my first attempt at fixing this, so no. Skipping the cache seemd to reduce the number of times this happend, however this could just be a coincident.

The place where this is a bit more critical is in the Rule Machine. I have a button next to my main entrance which enables arm away when pressed with the door open, and arm home when door closed. This sometimes fails and put the house in the wrong mode.

1 Like

I have an update on this one. I managed to find a (nasty) workaround that almost eliminated the issue. I.e. it reduced this from happening every second day to happen perhaps once a week. What I did was that I modified the contact sensor driver code to send the "closed" event twice, no fancy logic or anything, just simply sending the event twice:

sendEvent(name:"contact", value: "closed", isStateChange: true)
sendEvent(name:"contact", value: "closed", isStateChange: true)

Which contact sensor, and which driver?

It is an Aqara contact sensor with the driver from here: [Release] Xiaomi / Aqara / Opple Drivers with Presence!

However, I have seen the issue on a Smartthings multisensor (with the default driver) as well.

I have one aqara sensor on my desk where it is easy to recreate the issue by simply waving the magnet in front of the sensor a couple of times. I haven't removed any of the smartthings sensors, so there it is a bit more difficult to recreate the issue as I have to open and close the door in rapid succession.

The failure mode is always the same, the dashboard and event log is correct, while the currentValue() is incorrect, which in turn affects my app and Rules engine.

Try this driver for the Aqara sensor:

https://raw.githubusercontent.com/veeceeoh/xiaomi-hubitat/master/devicedrivers/xiaomi-door-window-sensor-hubitat.src/xiaomi-door-window-sensor-hubitat.groovy

2 Likes

This looks very promising, just done some quick testing, but no failures so far. Thank you!

I can confirm that the issue is completely resolved. I have tried opening and closing doors over the weekend and I have seen no issues what so ever. Thanks again @aaiyar!

1 Like