Simple UI based Fridge/Freezer open alarm

I needed to writ a rule to send some sort of notification if my kids leave our freezer open - I found some other articles but think my solution is simpler and easier to understand. I use the expire metadata attribute in a sort of different way than I think its intended but it works well for my use case:

  1. I have an item which is type contact named StudyFreezerDoorSensor_OpenClose from a sensor thing on the freezer door (mine is a Xiaomi window sensor controlled through deconz zigbee adapter but any contact will do) that has the two states OPEN or CLOSED.

  2. I have an item of string type named StudyFreezerDoorTimer

  3. This string item has an expire metadata atribute that expires after 5 minutes to send command ALARM to itself

  4. The StudyFreezerDoorTimer item is linked to the same channel as StudyFreezerDoorSensor_OpenClose with the Profile of REGEX with the Regular Expression of (.*)

Thats it for the items, I have one rule

Freezer Door Alarm
StudyFreezerDoorTimer changed from OPEN to ALARM
Send a notification (or do whatever you want to alert someone the door is open)

The secret is in the state of the StudyFreezerDoorTimer - it only triggers the alarm notification when it goes from OPEN to ALARM, but not CLOSED to ALARM, the expire timer sets a third state which I dont care waht it is only what it transitioned from - so it always shows the state as ALARM but that doesnt really matter.

Hope this helps someone

Thanks to @rlkoshak for simplifying this down to a single rule.

This is a nice use of Design Pattern: Expire Binding Based Timers. But I think there is a way to get rid of rule 1 and 2.

  1. Link the StudyFreezerDoorTimer to the same Channel as StudyFreezerDoorSensor_OpenClose. You might need to add a passthrough transformation profile (something like REGEX:(.*)) which will convert the OpenClosedType to a String that is usable by the String Item.

  2. If you don’t transform the OPEN/CLOSED to ON/OFF, you’ll need to change the trigger on the third rule to trigger on changed from OPEN to ALARM.

It’s pretty much the same approach with fewer rules.

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 }

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.

1 Like

Thanks @rlkoshak - always something to learn and your always the man to do it - I have changed the initial post with your suggestions - much simpler!

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.