Need help with heating rule

Have you looked in openhab.log? I bet you will see an error saying something about not being able to call operator > on null or something like that. You are missing the .state on your last else if.

else if(temp_WZ.state == 1 && wTemperature.state > 10) {

I highly recommend VSCode for editing Rules. It catches errors like this.

Cron triggered Rules for something like this is somewhat of an anti-pattern. OH is an event driven system so Rules should be written to respond to those events. In this case you have two events that may change your heating, temp_WZ changing or wTemperature changing. So trigger your Rule based on those changes instead of running it every 15 seconds wasting resources doing nothing.

rule "Heizen Wohnzimmer"
when
    Item temp_WZ changed or
    Item wTemperature changed
then
...

As for the body, definitely add some logging as yves suggests.

  • first line of the Rule to see that it is being triggered
  • in each if statement
  • last line of the Rule to see that it is exiting

It’s kind of a matter of style, but I prefer to side on fewer Rules with centralized logic over lots of different Rules.

Finally, @NilsAcht, I recommend Design Pattern: How to Structure a Rule which will let you separate the logic a bit and avoid duplicated code and perhaps make it easier to debug.

rule "Heizen Wohnzimmer"
when
    Item temp_WZ changed or
    Item wTemperature changed
then
    // 1. determine if we need to run the Rule at all
    if(temp_WZ.state == 1 && wTemperature.state == 10) return;

    // 2. Calculate what needs to be done
    var newTemp = 14 // covers temp_WZ.state == 2 and temp_WZ.state == 1 && wTemperature.state > 10

    if(temp_WZ.state == 3) newTemp = 21
    else if(temp_WZ.state == 1 && wTemperature.state < 10) newTemp = 22

    // 3. Do it
    logInfo("heating", "Changing target temp to " + newTemp)
    eg_wz_hz_sp.sendCommand(newTemp)
    wz_hz_fritz_sp.sendCommand(newTemp)
end
1 Like