Hi,
I need a little bit help writing a rule for switch off heating and turn it an again if window is closed or open.
My try dosn’t work:
/**CONTACT */
rule "BAD EG Fenster offen"
when Item EG_B_CONTACT changed
then
val EG_B_TEMP = EG_B_ST.value as DecimalType
if(EG_B_CONTACT.state == OPEN) {
sendCommand(EG_B_Heat_SW, OFF)
}
if(EG_B_CONTACT.state == CLOSED) {
sendCommand(EG_B_ST, EG_B_TEMP)
}
end
My Idea is to set the heater to the last value before window was opened. Can anyone give me a hint?
EG_B_ST is an Homematic automatic valve ST is “SetTemperature”
Load the rules in Designer to check for syntax errors
Post any relevant logs, in particular errors in the logs.
In this case I suspect you are seeing an error saying it can’t parse your .rules file because it has no idea what the heck EG_B_ST.value is. To get the “value” of an Item you use .state.
From a logical perspective the rule doesn’t make sense either. EG_B_TEMP gets set to the current state of EG_B_ST. then if the EG_B_CONTACT is CLOSED your send this same number right back to EG_B_ST. You never actually save the previous value anywhere.
There are two ways you can do this.
First you can move EG_B_TEMP to be a global and populate it when the contact state is OPEN:
var EG_B_TEMP = -1
rule "BAD EG Fenster offen"
when
Item EG_B_CONTACT changed
then
if(EG_B_CONTACT.state == OPEN) {
EG_B_TEMP = EG_B_ST.value as Number
EG_B_Heat.sendCommand(OFF)
}
if(EG_B_CONTACT.state == CLOSED) {
EG_B_ST.sendCommand(EG_B_TEMP)
}
end
Note: I made some additional changes that makes the code more reliable.
The second way involves persistence which would result in shorter code but I don’t think it will handle the case where someone changes the target temp while the window is open very well.
Hi Rich, thanks for your reply. I will try to adapt the rule the next few days.
What I missed or not found is a kind of reference or documentation for programming rules. Http://docs.openhab.org/configuration/rules-dsl.html here are only a few examples listed.