I thought it would be easyer if all is in one rule. I try one rule for each state.
Edit:
But what do i do if in rule “Received Command 1” (the automatic rule with outside temperature) the outside temperature changed?
The cron gives me the ability to check this.
Have you looked in openhab.log? I bet you will see an error saying something about not being able to call operator > on null or something like that. You are missing the .state on your last else if.
I highly recommend VSCode for editing Rules. It catches errors like this.
Cron triggered Rules for something like this is somewhat of an anti-pattern. OH is an event driven system so Rules should be written to respond to those events. In this case you have two events that may change your heating, temp_WZ changing or wTemperature changing. So trigger your Rule based on those changes instead of running it every 15 seconds wasting resources doing nothing.
rule "Heizen Wohnzimmer"
when
Item temp_WZ changed or
Item wTemperature changed
then
...
As for the body, definitely add some logging as yves suggests.
first line of the Rule to see that it is being triggered
in each if statement
last line of the Rule to see that it is exiting
It’s kind of a matter of style, but I prefer to side on fewer Rules with centralized logic over lots of different Rules.
rule "Heizen Wohnzimmer"
when
Item temp_WZ changed or
Item wTemperature changed
then
// 1. determine if we need to run the Rule at all
if(temp_WZ.state == 1 && wTemperature.state == 10) return;
// 2. Calculate what needs to be done
var newTemp = 14 // covers temp_WZ.state == 2 and temp_WZ.state == 1 && wTemperature.state > 10
if(temp_WZ.state == 3) newTemp = 21
else if(temp_WZ.state == 1 && wTemperature.state < 10) newTemp = 22
// 3. Do it
logInfo("heating", "Changing target temp to " + newTemp)
eg_wz_hz_sp.sendCommand(newTemp)
wz_hz_fritz_sp.sendCommand(newTemp)
end
It’s kind of a matter of style, but I prefer to side on fewer Rules with centralized logic over lots of >different Rules.
I basically ment, not use cron to do this. As like you said, this looks like an anti-pattern.
If temp_wz state ist 1 and Temperatur equals 10 then nothing Happens?
In your rule, this happens also.
You only have an action
when temp_wz state ist 1 and Temperatur > 10
when temp_wz state ist 1 and Temperatur < 10
nothing happens when temp_wz state ist 1 and Temperatur equal 10
hence the return
What happened in step two?
What is with state number 2?
newTemp is set to 14 and at the end
eg_wz_hz_sp.sendCommand(newTemp)
wz_hz_fritz_sp.sendCommand(newTemp)
this is why I prefer one rule for one action. independant, simplier and easier to read.
Ok thanks. I now ended up with three rules for each state.
rule "Heizen Automatisch"
when
Item temp_WZ changed or
Item wTemperature changed
then
if(temp_WZ.state == 1){
if(wTemperature.state < 11){
eg_wz_hz_sp.sendCommand(22)
wz_hz_fritz_sp.sendCommand(22)
}
else {
eg_wz_hz_sp.sendCommand(15)
wz_hz_fritz_sp.sendCommand(15)
}
}
end
rule "Heizen Komfort"
when
Item temp_WZ received command 3 or
Item eg_wz_hz_sp changed or
Item wz_hz_fritz_sp changed
then
if(temp_WZ.state == 3){
eg_wz_hz_sp.sendCommand(21)
wz_hz_fritz_sp.sendCommand(21)
}
end
rule "Heizen Manuell"
when
Item temp_WZ received command 2
then
eg_wz_hz_sp.sendCommand(14)
wz_hz_fritz_sp.sendCommand(14)
end
Now I can play with the item temp_WZ (Change it to string for better Google Home / IFTTT Integration).
All in all i want to have 4 or 5 modes. Automatic mode, Night mode, Comfort mode, manuell mode.
In Automatic openHAB does all the heating Settings alone. In manuell mode i want to manually Change the temperature with no interfearing. In Comfort mode I want openHAB to hold one Temperature ( in this case 21).
My Item temp_WZ is now a String-Item. With this I am able to give Google Home the command “Set Livingroom to Comfort” and my Comfort-Rule gets started.
Is it better to do this in a seperate tranformation file?
Now is the only Problem to get this function to the Google Home App. But thats an other story.
yes I saw that when I originally saw your question, and then later I forgot it.
That is one of the many reasons why I like to have all info in my rules.
In general I don’t like to use magic numbers in my code. I prefer constants that explain what the number means…