it’s everytime the same, a lot of hits on search, but all different to my issue!
I’m using KNX Binding for my heating system. A switch on the sitemap starts the heating for about 60 min. After that the heating rule turns the knx-actor off (runs well) but the switch on the sitemap is still “ON”
Sounds like a piece of cake, but i’m still without the right idea!
Would trying the format postUpdate(item, value) make any difference? I know there is a little difference in how the snippet is interpreted, but to be honest don’t really understand the nuances…
that sounds good! Actually I did not declare the variable!
Know the question, is it necessary to declare it as global or is local fine?
Where is the right place for a variable to be defined as local or global??
The rule as written/posted you can do either. In fact, you could just drop it entirely:
createTimer(now.plus ...
You never refer to it again. However, if there is an else you haven’t posted above which cancels the timer if the state is OFF, then you need to declare it as a global. All rule local variables go away once the rule finishes exiting which means timerWohnzimmer will cease to exist.
To declare a variable as local just put the val or var line between the then and end of the rule. But be aware you must declare it before you can use it so in this case it would have to go above the timerWohnzimmer = line.
To declare a variable as global the val and var need to be above the first rule in the file.
when
Item Wohnzimmer_Heizung received command
then
if (Wohnzimmer_Heizung.state == ON)
This fragment is concerning, because you might be trying to see what the command was that triggered the rule. You would use receivedCommand instead of Wohnzimmer_Heizung.state to find this out.
Heizung_Wohnzimmer.postUpdate(OFF)
If the intention is to turn off the heater, then sendCommand(OFF) is what you should do instead of merely updating the state of the switch item. The rule only does anything if it was sent the ON command, so you won’t create an endless loop.
In other words, you only need to react to receiving switch commands, and the switch state is actually not needed in the rule at all.
The complete rule below should work:
rule "manuelle Wonzimmer-Heizung"
when
Item Wohnzimmer_Heizung received command
then
if (receivedCommand == ON) {
Heizung_Wohnzimmer_Stellgroesse.sendCommand(100)
logInfo("Heizung", "WEB: Wohnzimmer = 100% für 2 min")
createTimer(now.plusMinutes(2)) [| Heizung_Wohnzimmer.sendCommand(OFF) ]
} else if (receivedCommand == OFF) {
Heizung_Wohnzimmer_Stellgroesse.sendCommand(0)
logInfo("Heizung", "WEB: Wohnzimmer Auto = 0%")
}
end
okay, I tried your changes…
the rule works as fine as before… the heating stopped before as well, but as before, the website item (switch) doesn’t change the state back to off!
Hmmm… Is it that the UI is wrong, or that the switch item’s state is really not OFF after sending the OFF command from the timer? You can check with the REST API:
Because, my rdd4j chart shows me the heating is OFF and the knx heating actor (hardware) is in fact OFF!!!
In other word, the reality is that the heating is OFF, the rdd4j-chart shows the same, the LOG shows a successful turn OFF, but the REST API is thinking about ON???
So, in order to be clear, the timer did run, it did send the OFF command to the switch, but both the UI and the REST API thereafter both show that the switch’s state is still ON? Unless something is preventing the autoupdate logic from changing the state of the switch to match the command, it seems like a weird bug.
You would move the existing org.openhab.binding.knx-1.8.3.jar file out of your /usr/share/openhab/addons directory, and download the linked .jar file to your /usr/share/openhab/addons directory. For example:
cd /usr/share/openhab/addons
sudo mv org.openhab.binding.knx-1.8.3.jar /tmp
wget https://openhab.ci.cloudbees.com/job/openHAB1-Addons/lastSuccessfulBuild/artifact/bundles/binding/org.openhab.binding.knx/target/org.openhab.binding.knx-1.9.0-SNAPSHOT.jar
Thanks for the advice, it looks like the snapshot was deployed successfully.
But the issue is still the same!
By the way, when I switch on/off the lights, the UI of openHab shows the right state!!!
So far I recognized it is just a problem the the heating-switch!
Could there be an error in the knx parameters of the group addresses??
I just tried the following rule on openHAB 1.8.3 (no KNX binding in this install) and it worked exactly as hoped.
rule MyTestRule
when
Item MyTestSwitch received command
then
if (receivedCommand == ON) {
logInfo("Test", "switch item turned on; turn it off in 2 minutes")
createTimer(now.plusMinutes(2)) [| MyTestSwitch.sendCommand(OFF) ]
} else if (receivedCommand == OFF) {
logInfo("Test", "switch item turned off")
}
end
The UI and switch state changed to OFF when expected, and the log entries were appended:
2016-11-01 12:17:32.851 [INFO ] [org.openhab.model.script.Test ] - switch item turned on; turn it off in 2 minutes
2016-11-01 12:19:32.930 [INFO ] [org.openhab.model.script.Test ] - switch item turned off
I would be very interested to learn if the difference between success and failure was in any way related to the KNX binding. (Uninstall the KNX binding bundle and try again.)
I’m editing your code step by step to add the key knx-feature!
I’ll come back in a few minutes!
by the way the “End” was not missing!
Edit: right now it is running well!!! KNX-is doing the right thing, heating turns ON and OFF and UI showing the right state!
I’ll check now further… differences