[SOLVED] Help with timer

  • Platform information:
    • Hardware: Raspberry PI 3
    • OS: openHABian
    • Java Runtime Environment: compliant with OH2.4 update
    • openHAB version: 2.4
  • Issue of the topic:

Hello Everyone,

Let’s start laughing…my cat loves ham and he can open the fridge to steel it! But he don’t close the door!

I placed a Xiaomi Aqara contact in the fridge door and I need a rule that warns me by broadcast notification to OH app, that the fidge door is opened more then 2 minutes.

I have read a lot of posts but nothing works well… can someone help me writing a rule for this?

Thank you everyone!

Really easy :slight_smile:

Contact MyDoorContact
var Timer tDoorAlarm = null

rule "door alarm"
when
    Item MyDoorContact changed
then
    if(MyDoorContact.state == OPEN)
        if(tDoorAlarm === null)
            tDoorAlarm = createTimer(now.plusMinutes(2), [|
                // sendMail("mail@address", "Fridge Alarm!", "Fridge door is open since two minutes..." )
            ])
    else {
        tDoorAlarm?.cancel
        tDoorAlarm = null
    }
end

Of course you can do other forms of notification, sendMail is just an example of how to do it.

2 Likes

No way… you totally need a video camera to catch this transgression

What’s really needed is a lock bar which can’t be opened by the cat, but that’s another thing :wink:

Would be nice to implement it with an ID3 Tag, installed to the collar of the cat, so the fridge is locked whenever the cat comes near… never do it low tech when there is a high tech option :smiley:

The mechanism from a chip reading catflap, no collar needed. You could get the kids chipped as well, work out a timed permission schedule.
It’ll all go wrong when the cat figures out how to coerce the kid, though.

Thank you so much Udo.
It’s working but now I have a new problem: everytime we open the fridge, I receive a notification, even when is open and close in a few seconds. How I cancel the timer if the door is open less then 2 minutes?

Best regards

And it’s a big cat :slight_smile:

A big step the tag… but a great idea for other things… thank you

Maybe viral in youtube… “The cat who stole the ham and ruined the fridge content :slight_smile:)”

Ah, sorry, as there are two if statements in a row, we need another pair of curly brackets.

var Timer tDoorAlarm = null

rule "door alarm"
when
    Item MyDoorContact changed
then
    if(MyDoorContact.state == OPEN) {   // <-- additional curly bracket
        if(tDoorAlarm === null)
            tDoorAlarm = createTimer(now.plusMinutes(2), [|
                // sendMail("mail@address", "Fridge Alarm!", "Fridge door is open since two minutes..." )
            ])
    }                    // <-- additional curly bracket
    else {
        tDoorAlarm?.cancel
        tDoorAlarm = null
    }
end
1 Like

It Works! Amazing!
The cat is going to be busted :slight_smile:
The real problem is not the ham but the ruined food after hours of open door…

Tested and implemented.
Thank you so much for the help!

Kind regards from Portugal

Antonio