Rule - Turn Boiler On until reached a defined Temperature

Hi All

I have build an MQTT sensor that report to OPENHAB the water temperature in my Boiler.
Now I can see how warm are my boiler water on my mobile app.
The next phase of the project is to create multi selection button that activate a rule
This rule will turn ON my boiler until the water will heat to the desired temperature.
On the sitemap i create a Temp Dst. selection button with the values 40, 50, & 60 Celsius.
My problem is with the rule .

Thanks in advanced of any assistance.


My Items

Switch Heater60C "60 Celsius" <heating> [ "Switchable" ] {autoupdate="false"} 
Switch Heater50C "50 Celsius" <heating> [ "Switchable" ] {autoupdate="false"} 
Switch Heater40C "40 Celsius" <heating> [ "Switchable" ] {autoupdate="false"} 
Number TempDst  "Temp  Dst"  <heating> [ "Switchable" ] {autoupdate="false"} 

My Sitemap

Switch item=TempDst label="Temp Dst." icon="temperature" mappings=[60C="60°", 50C="50°", 40C="40°"]

My Rules

rule "Water Temp 60C"
Item Heater60C received command
while(DudeTemp.state < 60)

rule "BoilerTemp"
Item TempDst received command
if(receivedCommand=="60C") {
sendCommand("Heater60C", ON)
if(receivedCommand=="50C") {
sendCommand("Heater50C", ON)
if(receivedCommand=="40C") {
sendCommand("Heater40C", ON)

You don’t want to be using Thread::sleep in your rules. This will freeze all rules! Especially one with such a long timeout!

If you know the current temperature, you can just do a rule which fires when the value is updated, and if the current temperature is over your target temperature, send the OFF command.

Your problem is with the sitemap.

You cannot set a Number Item to 60C, you must use only valid numerical characters, in this case just 60.

But I will second Garry’s comment. You do not want to be using long Thread::sleeps in your rules. He is incorrect, it will not freeze all rules (there was a bug where a long Thread::sleep in a System started rule causes problems but that has been fixed) but it can cause you problems down the road. You do not want to use sleeps longer than a few hundred milliseconds. If you need longer you should use Timers.

Your use of { } is odd and makes following your code very difficult. You only need curly brackets when you are defining a new context such as an if statement or a switch statement. And even then the curly bracket is optional if there is only one line of code that needs to be executed when the if statement is true.

Finally, yes, Garry’s approach is much better.

rule "Boiler Temperature changed"
    Item DudeTemp changed
    if(DudTemp.state as Number < TempDst.state as Number && MySwitch.state != ON) MySwitch.sendCommand(ON)
    else MySwitch.sendCommand(OFF)

That is it. When your DudeTemp (I presume is your boiler’s temp sensor) changes the rule checks to see if it is below the value set for TempDst. If it is and the boiler isn’t already ON, turn on the boiler (I presume MySwitch is the Item that controls your boiler, notice the lack of ", I don’t know what you were trying to do with that). If the measured temp is >= the desired value it turns off the boiler.

Thanks a lot .
I’ll test and update you after.