The situation now: I have a KNX-Bus-System with Windows PC. The PC controll the Units.
Befor I had the Software “EisBär 1.8.0”, but since several years no updates launched and a lot of features are missing. Now my wife is not at home, so I used the time to install openHab and programm all my used features.
In openHab I installed the KNX and the Astro Binding only.
In openHab I installed the KNX and the Astro Binding only. Not changed something else.
The Things-File have 200 KNX-Things.
The Item-File have about 450 Items.
I have 81 Rules with 1500 code lines in 4 Files.
Is openHab running, it uesd 500MB RAM and the CPU-Usage is lower than 10%.
Now the problem:
If I change a Value of an Item, the Item state changed to late.
The Value changed from ON to OFF
The rule startet (with “Item Test received command”)
I make a Log Entry (with "logInfo(“Test”,“Test: " + Test.state)”)
In the Log is written “Test: ON”
09:36:27.499 [INFO ] [pse.smarthome.model.script.Test] - Test: ON
09:36:27.551 [INFO ] [pse.smarthome.model.script.Test] - Test 1: OFF
09:36:27.531 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Test' received command OFF
The Code is:
rule "Test"
when
Item Test received command
then
logInfo("Test","Test: " + Test.state)
if (Test.state == ON) {
logInfo("Test","Test 1 " + Test.state)
}
else {
logInfo("Test","Test 0 " + Test.state)
}
end
3 interessting Details:
During the IF-query, the status is ON. So in the rule openHab select the first branch. But during execute the Log-command, the state has now the right Value OFF.
The timestamp show, that the rule is start before the value of Test.state is changed.
In the Log, the timestamp “xxx.531” ist behind “xxx.551”.
This not not so every time. In 20% of execudes, the Value changed to late. Than the rules starts before the right value is available on item.state.
Now the question: why? If the PC to slow? Is that to much items? (I hae only 2 rooms finished!). What can I do?
Who can help me? in 5 days my wife come back and she would like that the lights go on if she push the switch,
I have read in an other forum that it can help to deactivate the LSP. I tried it but no help. Same before.
Bin mir nicht ganz sicher, aber ich glaube du brauchst ein “received update” statt “received command”. Wenn ich mich nicht täusche wird “received update” getriggered wenn der state aktualisiert wurde.
das ist nicht ganz richtig. “received command” reagiert auf .sendCommand (welches ich verwende) und nicht auf “.postUpdate”. “received update” reagiert auf beides. Das Problem ist ja auch nicht, dass es nicht aufgerufen wird, sondern dass der geänderte Wert zu spät zur Verfügung steht.
Das ist ein und das selbe Problem, da hat Markus schon recht. openHAB informiert dich bei “received command” schon bevor intern der Wert richtig verarbeitet worden ist, also bevor das Item Test den State korrekt gesetzt bekommen hat. Und das kann dann zu jeder Zeit innerhalb der Rule passieren.
The default behaviour of openHAB is to autoupdate an item after it has received a command.
The sequence goes like this:
Item receives command
OH posts item update on the event bus
Item is updated
So the item’s state is update AFTER the command it received. Sometimes it can take a while (up to 20ms in my case).
So in your rule, when you check for the state of the item immediately after the command is received, the state of the item hasn’t updated yet.
You could add a little delay in the rule, Thread::sleep(30) OR you could change the rule trigger to received update or changed depending on what you want to do.
That’s not what the OP wants to do, he wants to check the state of the item before doing something.
BUT, if the receivedCommand implicit variable is good enough and the OP assumes that the the items state WILL change then by all mean, use it.