I would like to monitor my garage door with an Aqara Zigbee Window sensor.
Main issue is that I can’t find the perfect position where the sensor triggers only once when opened or closed. E.g. when closing the door it goes from OPEN to CLOSED, then back and forth a few times, and may end up on whichever state.
To navigate around this issue, I introduced a 10 second delay after the first sensor signal to ignore the noise, which works as expected:
var lastTriggerGarageVorne = now
val String filename = "Kontakte.rules"
rule "Garagentor vorne Steuerung"
when
Item C_Garage_vorne changed
then
if (lastTriggerGarageVorne.isBefore(now.minusSeconds(10))) { // to prevent double-triggering
if (C_Garage_vorne.state == OPEN) {
logInfo(filename,"Garage vorne geöffnet.")
lastTriggerGarageVorne = now
} else if (C_Garage_vorne.state == CLOSED) {
logInfo(filename,"Garage vorne geschlossen.")
lastTriggerGarageVorne = now
}
}
end
And this is the Log output:
2021-01-15 15:56:40.709 [ome.event.ItemCommandEvent] - Item 'SA_Garage_vorne' received command ON
2021-01-15 15:56:40.731 [nt.ItemStatePredictedEvent] - SA_Garage_vorne predicted to become ON
2021-01-15 15:56:40.775 [vent.ItemStateChangedEvent] - SA_Garage_vorne changed from OFF to ON
2021-01-15 15:56:41.803 [vent.ItemStateChangedEvent] - C_Garage_vorne changed from CLOSED to OPEN
2021-01-15 15:56:41.824 [INFO ] [marthome.model.script.Kontakte.rules] - Garage vorne geöffnet.
2021-01-15 15:56:41.934 [vent.ItemStateChangedEvent] - C_Garage_vorne changed from OPEN to CLOSED
2021-01-15 15:56:42.155 [vent.ItemStateChangedEvent] - C_Garage_vorne changed from CLOSED to OPEN
2021-01-15 15:56:42.196 [vent.ItemStateChangedEvent] - C_Garage_vorne changed from OPEN to CLOSED
2021-01-15 15:56:42.276 [vent.ItemStateChangedEvent] - SA_Garage_vorne changed from ON to OFF
2021-01-15 15:56:42.427 [vent.ItemStateChangedEvent] - C_Garage_vorne changed from CLOSED to OPEN
2021-01-15 15:56:42.581 [vent.ItemStateChangedEvent] - C_Garage_vorne changed from OPEN to CLOSED
2021-01-15 15:56:42.770 [vent.ItemStateChangedEvent] - C_Garage_vorne changed from CLOSED to OPEN
Two questions:
-
after saving the rules file, the first movement does not trigger the rule. I assume this is due to some issue with how I introduce lastTriggerGarageVorne? After the first movement, when lastTriggerGarageVorne has been set once by the rule, all works fine.
-
Sometimes, the sensor overshoots. E.g. when closing, it goes OPEN -> CLOSE -> OPEN. In my rule, the next movement (OPEN -> CLOSE -> OPEN) would trigger “Garage door closed” again. Also, the state of the door in my sitemap is wrong in this case.
I tried to introduce a boolean state GarageVorneOffen that would be set along with the first sensor signal and also ignore the noise for 10 seconds.
I added
var GarageVorneOffen = new Boolean("true")
and
GarageVorneOffen = true
GarageVorneOffen = false
in tht respective parts of the if/else clause. How do I best monitor the state of this variable?
openHAB 2.5.11