Im trying to add a variable to one of my rules to basicly only turn on the radiator valve if the temperature is lower in the room than the set point and also only when the bedroom window is shut to save on heating a room with an open window.
My initial Rule which works perfectly to control the valve just based on the temperature is as follows.
rule "Kids Bedroom heating"
when
Item Kids_Bedroom_Temp_Setpoint changed or
Item Kids_Bedroom_Temperature changed
then
var Number cur_temp = Kids_Bedroom_Temperature.state as Number
var Number setpoint = Kids_Bedroom_Temp_Setpoint.state as Number
val Number hysteresis = 0.2
if (cur_temp < (setpoint - hysteresis) ){
if (Kids_Bedroom_Radiator_Valve.state != ON) {Kids_Bedroom_Radiator_Valve.sendCommand(ON)}
}
else if(cur_temp > setpoint + hysteresis) {
if (Kids_Bedroom_Radiator_Valve.state != OFF) {Kids_Bedroom_Radiator_Valve.sendCommand(OFF)}
}
end
Ive already tried to add a second variable by doing the below with no success. Any ideas?
rule "Kids Bedroom heating"
when
Item Kids_Bedroom_Temp_Setpoint changed or
Item Kids_Bedroom_Temperature changed
then
var Number cur_temp = Kids_Bedroom_Temperature.state as Number
var Number setpoint = Kids_Bedroom_Temp_Setpoint.state as Number
val Number hysteresis = 0.2
if (cur_temp < (setpoint - hysteresis) ){
if (Kids_Bedroom_Radiator_Valve.state != ON) (Kids_Bedroom_Window.state != 0) {Kids_Bedroom_Radiator_Valve.sendCommand(ON)}
}
else if(cur_temp > setpoint + hysteresis) {
if (Kids_Bedroom_Radiator_Valve.state != OFF) {Kids_Bedroom_Radiator_Valve.sendCommand(OFF)}
}
end
Ive tried your suggestion and now the rules does not fire at all? Obviously the window state is currently 0.
rule "Kids Bedroom heating"
when
Item Kids_Bedroom_Temp_Setpoint changed or
Item Kids_Bedroom_Temperature changed
then
var Number cur_temp = Kids_Bedroom_Temperature.state as Number
var Number setpoint = Kids_Bedroom_Temp_Setpoint.state as Number
val Number hysteresis = 0.2
if (cur_temp < (setpoint - hysteresis) ){
if (Kids_Bedroom_Radiator_Valve.state != ON && Kids_Bedroom_Window.state != 0) {Kids_Bedroom_Radiator_Valve.sendCommand(ON)}
}
else if(cur_temp > setpoint + hysteresis) {
if (Kids_Bedroom_Radiator_Valve.state != OFF) {Kids_Bedroom_Radiator_Valve.sendCommand(OFF)}
}
end
How could you tell? Did it fire before? The rule as written is expected to fire but do nothing sometimes under some conditions.
Why not use logInfo() to find out if and when the rule runs, and what the important conditions are at the time it runs.
2021-05-02 11:56:48.056 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'heating-1' failed: An error occurred during the script execution: index=1, size=1 in heating
The rules is now running like previously, before adding your additional code to the rule (i restarted openhab and it seemed to start working). But now the valve is coming on when the window is both open and closed so the added code isnt working. ive also tried changing the state its looking for from 0 to OFF to see if that would solve the issue with no luck.
This error was due to my error in the placement of loginfo()
Alright, when you want some help post the rule as it is now (if different from previous version) and log out what the state of the key conditions are.
Make rational not random changes. What is the state of the Item?
Let’s find out, first line in rule - logInfo("test", "My rule is running and the window is " + Kids_Bedroom_Window.state.toString)
This is the rule now with your additions. which works perfectly to the setpoint and temp changes but does not seem to take into account the status of the window.
rule "Kids Bedroom heating"
when
Item Kids_Bedroom_Temp_Setpoint changed or
Item Kids_Bedroom_Temperature changed
then
var Number cur_temp = Kids_Bedroom_Temperature.state as Number
var Number setpoint = Kids_Bedroom_Temp_Setpoint.state as Number
val Number hysteresis = 0.2
if (cur_temp < (setpoint - hysteresis) ){
if (Kids_Bedroom_Radiator_Valve.state != ON && Kids_Bedroom_Window.state != 0) {Kids_Bedroom_Radiator_Valve.sendCommand(ON)}
}
else if(cur_temp > setpoint + hysteresis) {
if (Kids_Bedroom_Radiator_Valve.state != OFF) {Kids_Bedroom_Radiator_Valve.sendCommand(OFF)}
}
end
This is the log entry when the window is shut
2021-05-02 12:40:17.773 [INFO ] [org.openhab.core.model.script.test ] - My rule is running and the window is 0
Thus is the log entry when the window is open (this log seems to repeat itself every couple of secconds.
2021-05-02 12:42:41.031 [INFO ] [org.openhab.core.model.script.test ] - My rule is running and the window is 1
2021-05-02 12:42:42.139 [INFO ] [org.openhab.core.model.script.test ] - My rule is running and the window is 1
2021-05-02 12:42:43.236 [INFO ] [org.openhab.core.model.script.test ] - My rule is running and the window is 1
2021-05-02 12:42:44.099 [INFO ] [org.openhab.core.model.script.test ] - My rule is running and the window is 1
2021-05-02 12:42:44.873 [INFO ] [org.openhab.core.model.script.test ] - My rule is running and the window is 1
2021-05-02 12:42:45.707 [INFO ] [org.openhab.core.model.script.test ] - My rule is running and the window is 1
2021-05-02 12:42:49.333 [INFO ] [org.openhab.core.model.script.test ] - My rule is running and the window is 1
2021-05-02 12:42:50.287 [INFO ] [org.openhab.core.model.script.test ] - My rule is running and the window is 1
2021-05-02 14:18:03.300 [INFO ] [org.openhab.core.model.script.test ] - My rule is running and the window is 0
2021-05-02 14:18:03.302 [INFO ] [org.openhab.core.model.script.test ] - Numeric match
the value of the cur_temp comes from a temp sensor and the value of setpoint is a setpoint item so currently set to 19 degrees.
The part of the rule that isnt working for me is that when the window is open i dont want the valve to turn on. when the window is closed i want the valve to come on heating the room if said cur_temp and setpoint have a difference of 0.2 degrees.
Im just basicly wanting to in a sence enable or disable the valve item being turn on depending on the state of the window aswell as the sepoint if that makes sense? i do apologise as im not very good with debugging and explaining myself!
I have managed to come up with a temporary work around using both textual rules and ui rules on openhab3 by disabling the valve rule when the window is open and enabling it once its shut, but im looking for an all in one textual solution if possible.
Okeydoke, that’s ambiguous in an openHAB context.
Some Items are just plain old Numbers, they have a numeric value such as 19.0
Some Items are Quantities, like a Number:Temperature type. The unit of measurement is part and parcel of the value, such as 19.0 °C
Depends where they come from and how you set them up.
Who cares? Well, you do once you start comparing or doing maths - is 19.0 °C bigger than 22? 22 what, °F? K?
This is why I’ve been trying to lead you by the nose to log your values out. I don’t know if you are dealing with numbers or temperatures yet, it is important for sums and comparisons.
ok i understand now. The values are just numbers 19 or 19.0 and then the °C is just added on my sitemap.
The issue isnt with the temperature/setpoint part of the rule that works fine. The portion that isnt working is the dont turn on the heating if the window is open.
2021-05-02 16:06:49.856 [INFO ] [org.openhab.core.model.script.test ] - My rule is running and the window is 0
2021-05-02 16:06:49.859 [INFO ] [org.openhab.core.model.script.test ] - Do if-1 with cur_temp 19.98
2021-05-02 16:06:49.861 [INFO ] [org.openhab.core.model.script.test ] - Do if-1 with target 20.8
2021-05-02 16:06:49.863 [INFO ] [org.openhab.core.model.script.test ] - Cold, now do if-2 with radiator ON
2021-05-02 16:06:49.864 [INFO ] [org.openhab.core.model.script.test ] - and window 0
output when window is open
2021-05-02 16:16:19.244 [INFO ] [org.openhab.core.model.script.test ] - My rule is running and the window is 1
2021-05-02 16:16:19.247 [INFO ] [org.openhab.core.model.script.test ] - Do if-1 with cur_temp 19.98
2021-05-02 16:16:19.248 [INFO ] [org.openhab.core.model.script.test ] - Do if-1 with target 21.8
2021-05-02 16:16:19.250 [INFO ] [org.openhab.core.model.script.test ] - Cold, now do if-2 with radiator ON
2021-05-02 16:16:19.253 [INFO ] [org.openhab.core.model.script.test ] - and window 1
In both circumstances the radiator valve comes on.
In neither case is the message
“Valve was off and window not-closed”
shown. I presume you do not actually see an ON command in your events.log?
The reason being the radiator was ON before we started.
Your rule only turns it OFF again when it gets too hot, it doesn’t take any notice of the window for that.
It only turns it ON when it is too cold AND the window is not-closed by the way. Not sure that is what you meant there.
In my testing the valve has always been off before testing the rule. The valve gets turned on and off via the rule, Im just wanting it to not turn the valve on if the window is open and turn it on if the window is shut.
At the minute the rule sends a command to the valve if the room temperature is lower than the setpoint.
2021-05-02 16:15:59.622 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'Kids_Bedroom_Radiator_Valve' received command ON
It also gets sent a OFF command once the setpoint has been reached. Then because the valve is in the gallradiators group, it then turns on the boiler via another rule.
What im trying to achieve here is not allow the valve to be turned of if the window is open.
by the time the rule runs it thinks it’s ON.
As usual, let’s find out.
Change first line of body to logInfo("test", "My rule is starting and the valve is " + Kids_Bedroom_Radiator_Valve.state.toString)
Ah, okay, I had the sense of it wrong, assuming you didn’t want heating when the window was open. But the window is only coming into play for the ON part at the moment. You want the window controlling the OFF but not the ON?