OH2 rule doesnt work in OH3

Hi,

rule worked well in OH2, but not in OH3. There is no error I can see in the logs, so I´m just wondering what the reason may be.

Item SaunaTemp1 exists and receives values.

var boolean Notify = false

rule "SaunaTemp1"

when
	Item SaunaTemp1 changed

then
     if ((SaunaTemp1.state) > 60 && Notify == false ) {
       {sendNotification("XXX@xxx.com", "Sauna Temperatur:  " + SaunaTemp1.state + " C")
	  logInfo("Sauna", "Sauna over 60")
	   Notify = true}
              }

else if ((SaunaTemp1.state) < 30  && Notify == true ) {
       {sendNotification("XXX@xxx.com", "Sauna unter 30 C:  " + SaunaTemp1.state + " C")
	  Notify = false} 
              }
			  
		  
end

Hard to say without a little more information.

Is this rule in an .rules file or have you added via the main UI? If it’s in a .rules file, are there other rules also in the file and are you sure the file is being parsed and loaded when you save changes to it?

You say there are no errors in the logs, but do you see any indication the rule runs at all in the logs? Is the problem that the rules doesn’t run at all or that the rules runs but your ‘if’ and ‘else if’ conditions never trigger?

Also, this shouldn’t be the problem but just to help improve readability, you have some extra sets of ()'s and {}'s in your code:

  1. You don’t need the ()'s around SaunaTemp1.state
  2. You need only one set of {}'s around the code executed as a result of an if or else if block

Maybe is related with this
https://community.openhab.org/t/upgrading-to-oh3-rules-dsl-problem-if-statements

But what values, may we see?
Your Item type might have changed.

this is a rules-file based rule, all other rules work fine after importing them to OH3

the item type was the “bad boy” here

simply changed from “number temperature” to “number” and voila, it works fine again!

btw: what ist the difference between them?
these values are sent from a Fibaro binary sensor, e.g “- Item ‘SaunaTemp1’ changed from 21.56 to 21”

Many thanks for your hints and help, guys!

It’s probably better to change the rule to handle the Number:Temperature type.
See “comparisons” -

Another question: Did you setup the item to Number:Temperature yourself or was this set by openHAB?

Number:Temperature would carry the Unit of Measurement (°C in this case). The state should be 36.3 °C, not 36.3. If a channel uses UoM, it’s best to use it.
The rule is not more complex.

var Boolean Notify = false

rule "SaunaTemp1"
when
    Item SaunaTemp1 changed
then
    if(!(SaunaTemp1.state instanceof Number))
        return;
    val nTemp = (SaunaTemp1.state as Number).floatValue

    if(nTemp > 60 && !Notify) {
        sendNotification("XXX@xxx.com", "Sauna Temperatur:  " + String::format("%.1f °C",nTemp))
        logInfo("Sauna", "Sauna over 60")
        Notify = true
    } else if(nTemp < 30  && Notify) {
        sendNotification("XXX@xxx.com", "Sauna unter 30 °C:  " + String::format("%.1f °C",nTemp))
        Notify = false 
    }
end

I had set up it manually as “Number:Temperature”, so it was my “fault”.
I´ve modified the rule like you proposed, thanks!