I use Xiaomi contact sensors for almost all my windows and doors. I find that it needs to be installed at a specific distance from the magnet just so that it would report being OPEN when the door is slightly open. This distance is quite far because the magnet is strong. If I installed the magnet right next to the sensor, I can open the window quite far apart and it would still think it’s closed. Even so, I can close my windows just so the sensor would report it being closed, but the window doesn’t “click” to lock.
My fridge door has a habit of not closing unless you actually push it closed. It doesn’t “auto close” even when it’s cracked open by 5mm. There must be something I need to adjust in the legs to make it auto close, because most other fridges seem to self close.
Anyway, the rules you described, can be achieved just like this in jruby, without using an extra expire based item.
rule 'alert when fridge is open' do
changed StudyFreezerDoorSensor_OpenClose, to: OPEN, for: 5.minutes
run { # send notification or do whatever }
end
That’s it. One single rule. No extras. The for: 5.minutes
argument does the magic under the hood. If the fridge is opened and closed in less than 5 minutes, the rule won’t fire. It will only fire if the door remains unchanged in the OPEN state for 5 minutes.