On/off at certain temperature

Can somebody help me on my way?

I’ve got 3 knx items:

  • Switch1 (heating ON or OFF)
  • Switch2 (cooling ON or OFF)
  • Number (temperature read from a sensor in the room)

I would like now to put the heating or cooling on till a certain temperature is reach, based on the readout of the sensor.

Any examples on how I put this in a script, and place this in one sitemap rule? fe

Temperature (25)     DOWN 28 UP

Where 25 is the actual degrees, and 28 is the wanted degrees.

This may be more comprehensive than you are after but it should get you started.

Following the example, I ended up with the config below.
I’m close to a working solution, I feel it. I think that my issues is linked somewhere with the if &&. When I drop the Heating_Mode.state part, it seems to works?

At the moment fe, my wanted temperature (Bureau_TargetTemp) is set to 15), and the real temperature (SCH_BURO1_TEMP) is 19.74. So only the airco part should be triggered.
But both parts are triggered as you can see below in the log.

Items:

Number  SCH_BURO1_TEMP      "Deur [%.2f C]"                     <temperature>           (TEMP_ALL)              { knx="3/2/0"  }
Number  Bureau_TargetTemp	"Gewenste Temperatuur [%.1f °C]"	<temperature>
String 	Heating_Mode 		"Globale HVAC Mode [%s]"

Part of my rule:

// =========================
rule "HVAC Bureel Activatie"
when
        Item SCH_BURO1_TEMP changed
then
// Heating ON (NO since 16 < 19.74)
        if ((((Bureau_TargetTemp.state as DecimalType)+1)>(SCH_BURO1_TEMP.state as DecimalType)) && (Heating_Mode.state == "Werk")) {                
                logInfo("HVAC_Bureel", "De temperatuur is lager dan gewenst [" + SCH_BURO1_TEMP.state + " < " + Bureau_TargetTemp.state as DecimalType +"]")
                if (HVAC_BureelKoeling.lastUpdate.isBefore(now.minusHours(2))) HVAC_BureelVerwaming.sendCommand(ON)
                logInfo("HVAC_Bureel", "De verwarming is opgezet")
                }
        else {
                logInfo("HVAC_Bureel", "De temperatuur is lager dan gewenst [" + SCH_BURO1_TEMP.state + " < " + Bureau_TargetTemp.state as DecimalType +"]")
                logInfo("HVAC_Bureel", "De Verwarming is niet aangezet omdat HVAC modus niet op werken staat.")
                }

// Heating & Cooling OFF
        if ((SCH_BURO1_TEMP.state as DecimalType)==(Bureau_TargetTemp.state as DecimalType)) {
                logInfo("HVAC_Bureel", "Gewenste temperatuur is bereikt [" + SCH_BURO1_TEMP.state + " = " + Bureau_TargetTemp.state as DecimalType +"]")
                sendCommand( HVAC_BureelVerwarming, OFF )
                sendCommand( HVAC_BureelKoeling, OFF)
                logInfo("HVAC_Bureel", "De verwarming & Airco zijn uitgezet")
                }

// Cooling ON (YES since 20.74 < 15)
        if ((((SCH_BURO1_TEMP.state as DecimalType)+1)>(Bureau_TargetTemp.state as DecimalType)) && (Heating_Mode.state == "Werk")) {
                logInfo("HVAC_Bureel", "De temperatuur is hoger dan gewenst [" + SCH_BURO1_TEMP.state + " < " + Bureau_TargetTemp.state as DecimalType +"]")
                logInfo("HVAC_Bureel", "De Airco is aangezet")
                }
        else {
                logInfo("HVAC_Bureel", "De temperatuur is hoger dan gewenst [" + SCH_BURO1_TEMP.state + " > " + Bureau_TargetTemp.state as DecimalType +"]")
                logInfo("HVAC_Bureel", "De Airco is niet aangezet omdat HVAC modus niet op werken staat.")
                }
end

openhab.log

2018-03-11 16:10:09.775 [INFO ] [e.smarthome.model.script.HVAC_Bureel] - De temperatuur is lager dan gewenst [19.740000000000002 < 15.0]                                                           
2018-03-11 16:10:09.778 [INFO ] [e.smarthome.model.script.HVAC_Bureel] - De Verwarming is niet aangezet omdat HVAC modus niet op werken staat.                                                     
2018-03-11 16:10:09.788 [INFO ] [e.smarthome.model.script.HVAC_Bureel] - De temperatuur is hoger dan gewenst [19.740000000000002 > 15.0]                                                           
2018-03-11 16:10:09.792 [INFO ] [e.smarthome.model.script.HVAC_Bureel] - De Airco is niet aangezet omdat HVAC modus niet op werken staat.

Any ideas or suggestions?

Heating_Mode.state is not a string, so the comparison is always false. Change these to…

&& (Heating_Mode.state.toString == "Werk")

Also be aware that anything in parentheses will be evaluated, even if it is not used. If performance is a concern, use parenthesis only when required.

1 Like

Not sure that I understand this correctly.
Do you mean that without the parenthesis, it will always work if fe the state is not the correct value?
And with parenthesis, it will crash?

The two are unrelated. The problem is the missing toString. The parens are simply not needed.

1 Like