[SOLVED] Send message once when threshold reached

Hello,

I need, that I get a information via telegram, if the temperature under 3 Degree.
If I use …

rule "temperature"
when
   Item eg_temp01 changed
then
   if(eg_temp01.state<3) {
       sendtelegram("bot1", "Information ...")
   }
end

… by every change from the temperature fire the ruleand and I get a telegramm message.
I only need the message once when the temperature breaks the e.g. 3 degree limit.
How can I this config?
Thanks! Michael

  • Platform information:
    • Hardware: RaspPi 3
    • openHAB version: 2.3

You need to add what is called a flag

var tempFlag = 0  // Add this at the very top of the rules file

rule "temperature"
when
   Item eg_temp01 changed
then
    if(eg_temp01.state<3) {
        if (tempFlag == 0) {  // The flag is 0 - First Time
            sendtelegram("bot1", "Information ...")
            tempFlag = 1 // Set the flag to 1 
    } else if (tempFlag == 1) { // If the temp goes over 3 AND the flag is 1
        tempFlag = 0 // Reset the flag
    }
end
1 Like

That was the part I was always missing, thanks :+1:

When I need more rules, I change to “tempFlag1” etc. ?

Yes