Sending reminder when the window isn´t closed after a period of time

Hi there,

i already got a rule to check if an window is open for more than 60 minutes.
After using this for almost a month now, i found something that could be better.

The current rule only sends an Telegram message when the window was open for 60 minutes, but now reminders if i didn´t closed it !
Now i would like to have something like a loop that sends me another reminder every 30 minutes that i don´t close the window.

  1. wait 60 minutes -> 1. Message
  2. wait another 30 minutes -> 2. Message
  3. stop sending messages when the window is finally closed.

The current rule:

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*

import org.joda.time.*

var Timer timerFenster = null

rule "Warnung Badezimmer Fensterkontakt"

when

    Item itmFenster_Badezimmer changed from CLOSED to OPEN

then

// Prüfung ob der item state initialisiert ist
    if(previousState!=OPEN && previousState!=CLOSED)
    {
        logInfo("RuleFensterBadezimmer", "Regel wird abgebrochen, die Items sind nicht initialisiert.")
        return(false)
    }

// Prüfung ob der aktuelle Monat zwischen März und September liegt
    if(now.getMonthOfYear() >3 && now.getMonthOfYear() <9)
    {
        logInfo("RuleFensterBadezimmer", "Die Regel wird abgebrochen, es ist Sommer.")
        return (false)
    }

// Abbruch des Timers wenn das Fenster erneut geöffnet wird
    if(timerFenster!=null)
    {
        logInfo("RuleFensterBadezimmer", "Die Regel wird neugestartet, das Fenster wurde erneut geöffnet.")
        timerFenster.cancel
        timerFenster=null
    }

// Erstellen eines Timers für 60 Minuten und anschließenden Versenden einer Telegram Nachricht
    timerFenster = createTimer
    (
        now.plusMinutes(60), 
        [|
            if (itmFenster_Badezimmer.state == OPEN)
            {
                sendTelegram("bot1", "Achtung, das Fenster im Badezimmer ist seit 1 Stunde offen!")
                sendTelegram("bot2", "Achtung, das Fenster im Badezimmer ist seit 1 Stunde offen!")
                logInfo("RuleFensterBadezimmer", "Die Regel wurde erfolgreich ausgeführt.")
            }
            else
                timerFenster=null
        ]
    )
end


(The comments are german :slight_smile:)

Cheers
Michael

I’ve done this a number of ways and in the end the simplest to implement ended up being using persistence and a cron triggered rule that checks the states every few minutes and if the contact is opened more then an hour (I.e. the state is OPEN and lastUpdate if more than 60 minutes ago. )

Then I set a flag or a timestamp to check so it only reports every half hour.

Ultimately i ended up reworking it to only report once because I don’t need to be constantly reminded.