Hi guys and gals,
Is this me or could this be a bug?
I’m having trouble getting this ‘virtual thermostat’ rule to work in OpenHab3. I have a small Infrared heating panel in my office, controled with a tradfri on/off switch. I also have a nodemcu that gives me the temperature over mqtt. Since i’m relatively new to Openhab, to get me going i searched and found a script on this forum and adapted it to my needs. I created all the necessary things and stuff in the sitemap but it just will not work. When i press ‘Run Now’ in ‘Edit Script’ in the UI, the openhab logfile gives me this:
2021-05-02 22:55:23.553 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘be716a4b4e’ failed: ___ rule ___ “Office heating”
when
Item OfficeHeatingMode chan ___ ged o ___ r
Item TempOfficeSetPoint changed or
Item TempOffice changed or
Item OfficeWindow changed
then
…etcetera…
end
- The method or field rule is undefined; line 1, column 0, length 4
- The method or field when is undefined; line 2, column 22, length 4
- The method or field changed is undefined; line 3, column 54, length 7
… and so on.
Here’s my code:
triggers:
- id: "1"
configuration:
startlevel: 40
type: core.SystemStartlevelTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/vnd.openhab.dsl.rule
script: >-
rule "Office heating" when
Item OfficeHeatingMode changed or
Item TempOfficeSetPoint changed or
Item TempOffice changed or
Item OfficeWindow changed
then
// 0="Off", 1="On", 2="Auto"
if (OfficeHeatingMode.state == 0) {
// heater off
PowerOffice.sendCommand(OFF)
} else if (OfficeHeatingMode.state == 1) {
// heater on
PowerOffice.sendCommand(ON)
} else if (OfficeHeatingMode.state == 2) {
// only fire up the heater if the office window is closed
if (OfficeWindow.state == CLOSED) {
// get the current setpoint for the office
var Number setpoint = TempOfficeSetPoint.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 nursery
var Number temp = TempOffice.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
PowerOffice.sendCommand(ON)
} else if (temp >= turnOffTemp) {
// turn off temp has been reached so switch off the heater
PowerOffice.sendCommand(OFF)
}
} else {
// heater off
PowerOffice.sendCommand(OFF)
}
}
end
type: script.ScriptAction
I also found on the forum this post Scripts in OH3 - #12 by stefan.oh which refers to this issue on Github: OH3 callScript - scripts are not executed · Issue #1990 · openhab/openhab-core · GitHub . That issue is closed however.
My question: is it me, or is something else bugging me? I’m not a developer but i don’t consider myself to be too stupid to get an openhab rule to work either Could anybody give me a hint? I’m on the main branch.
PS:
I have also tried to create a rule for this in the UI, but it seems not possible to compare the Item Status of one Iten to the status of another item, i.e, I can say do something when TempOffice < 15, but i can’t say do something when TempOffice < TempOfficeSetPoint. Or am i missing something?