any help please, I am trying to trigger a control relay (mr_brm_ht) when (mr_brm_ht_sw) is changed state by user if temp is outwith set value (mr_brm_ht_set). temp is read via (mr_brm_ht_sr)
I am using HABPanel so no sitemap, where am I going wrong
when
Item mr_brm_ht_sw changed or
Item mr_brm_ht_set changed or
Item mr_brm_ht_sr changed
then
// 0=“Off”, 1=“On”, 2="Auto"
if (mr_brm_ht_sw.state == 0) {
// heater off
mr_brm_ht.sendCommand(Off)
} else if (mr_brm_ht_sw.state == 1) {
// heater on
mr_brm_ht.sendCommand(On)
} else if (mr_brm_ht_sw.state == 2) {
// get the current setpoint for the main bedroom
var Number setpoint = mr_brm_ht_set.state as DecimalType
// calculate the turn on/off temperatures
var Number turnOnTemp = setpoint - 0.5
var Number turnOffTemp = setpoint + 0.5
// get the current temperature in the main bedroom
var Number temp = mr_brm_ht_sr.state as DecimalType
// determine whether we need to turn on/off the heater
if (temp <= turnOnTemp) {
// turn on temp has been reached so switch on the heater
mr_brm_ht.sendCommand(ON)
} else if (temp >= turnOffTemp) {
// turn off temp has been reached so switch off the heater
mr_brm_ht.sendCommand(OFF)
}
} else {
// heater off
mr_brm_ht.sendCommand(OFF)
}
}
You’ve not really said whether any of it is working or is it just the ‘Auto’ temperature controlled part?
If you just toggle the mr_brm_ht switch ON/OFF does the relay work?
Your first two checks on mr_brm_ht_sw.state equal to 0 and 1 use non standard Off and On case in sendCommand rather than OFF and ON. Can’t say without testing whether OH will complain but consistency is king for ease of reading code so good practice either way.
After that you need to be reading the log files openhab and events and put some logInfo messages in your rule code so you can trace the execution path and see the values of variables like setPoint and temp at runtime to help test your maths and conditions.
Hi Ray, thanks for taking the time to reply. I noticed the capitalisation issue last night and corrected but still same result, if I assign mr_brm_ht to a button and toggle the relay actions, mr_brm_ht_sr shows the current temp in gui and changes state when I subject it to heat changes. the relay doesn’t fire if I change the setpoint to a lower value, I can see in the logs that this is being recorded, it also doesn’t fire if the temp sensor mr_brm_ht_sr falls below setpoint mr_brm_ht_set, its as though the rule isn’t firing
2017-12-06 12:30:00.887 [ItemStateChangedEvent ] - mr_brm_ht changed from ON to OFF
2017-12-06 12:30:01.832 [ItemCommandEvent ] - Item ‘mr_brm_ht_set’ received command 20
2017-12-06 12:30:01.835 [ItemStateChangedEvent ] - mr_brm_ht_set changed from 25 to 20
2017-12-06 12:30:20.014 [ItemStateChangedEvent ] - Wifi_Level changed from 2 to 1
2017-12-06 12:30:26.700 [ItemStateChangedEvent ] - mr_brm_ht_sr changed from 25.312 to 30.625
Good to break down the problem and test the parts. So you’re confident the relay fires, the values are there and changing etc so you need to start monitoring the openhab.log and add plenty of log entries to your rule so you can firstly ensure the rule is executing and then trace and validate it’s logic.
So you put something like this after the initial ‘then’:
logInfo("heating-control.rules", "Enterting Main Bedroom heating...")
then add as many more as like in different parts of your rule to trace the execution and show values like:
} else if (mr_brm_ht_sw.state == 2) {
// get the current setpoint for the main bedroom
var Number setpoint = mr_brm_ht_set.state as DecimalType
logInfo("heating-control.rules", "State=2 setpoint=" + setpoint)
} else if (mr_brm_ht_sw.state == 1) {
// heater on
mr_brm_ht.sendCommand(ON)
} else if (mr_brm_ht_sw.state == 2) {
// get the current setpoint for the main bedroom
var Number setpoint = mr_brm_ht_set.state as DecimalType
logInfo(“htg”, “state=2 setpoint=” + setpoint)
// calculate the turn on/off temperatures
var Number turnOnTemp = setpoint - 0.5
var Number turnOffTemp = setpoint + 0.5
// get the current temperature in the main bedroom
logInfo(“htg”, “state=2 temp=”)
var Number temp = mr_brm_ht_sr.state as DecimalType
// determine whether we need to turn on/off the heater