Hi, I have been running openhab:2.5.1-amd64-debian as a docker on my QNAP NAS for a long time with no issues whatsoever. I have many rules defined with delicate relationship and lots of checks and logs to make sure everything works as I want it. All of my rules are manually defined on individual files under DSL language and some rule files (but not all) might have 2-3 rules defined in them at the most.
I held myself off from upgrading for the last year or so, mainly because i didn’t have the time to make sure all of the rules were imported correctly and that they work as intended. Note that by the nature of running under a docker, I can just simply create a new docker with the desired version and still be able to run the my “stable” version 2.5.1!
So, I decided to finally cut the cord the migrate to the newest version, openhab:3.0.2-debian (still as a docker). As recommended, during the upgrade I changed some of my rules to use Zonetime (instead of Joda time) as well as updating the implicit variable “triggeringItemName” per the guidelines. IT was a breeze. After all of that, VS Code checks all rules, all good… the files are loaded into openhab and no complains on the logs!.
What I started noticing is that some of the rules were not running when certain triggers happened. To be more specific, I was able to determine that whenever an Item changes state (due to another rule, via BasicUI or via the Binding Sync) if there is a rule that was dependent on such item triggering, the rule did not start. I even placed a logging command at the very first line fo the rule to make sure it was not my rule logic that was flushing the rule… but my logs were clean. Simply the rule did not run.
However, whenever a channel change was sent, or a cron trigger was defined or even when the system started… all of those triggers were recognized by my rules and ran perfectly fine… it was only when and item state is changed.
As part of my debugging I tried updating the rule and see if i was doing anything wrong… and noticed that if I updated the rule file, say by added an empty line at the end of the rule, save it and let openhab reload it… then guess what? the rule started working!!! … at first I though, well maybe there is a format issue with my file and it got fixed now… but upon a docker re-start… the same behavior will occur and the rules will not trigger.
I did do a lot of searches in the forum and found a few threads were rules were not triggered correctly, but nothing related to OH 3.x and in the same way that i am experiencing… these thread seems to be similar, but I don’t think is the same:
and here:
Below are a few simple examples (real rule on my system) that are not working. The first is a simple rule that executes after a timer has expired. The timer is controlled via the EXPIRE binding and I can see in the logs when the timer turns off… but the rule fails to run.
rule "Master Bathroom 20M: When timer expires, Turn Off Fan/Heater"
when
Item Master_Bathroom_Timer_20M changed from ON to OFF
then
logInfo("TEST","THE TIMER RULE DID RUN.")
var rule_name = "MyRules.Bathroom.20MTimer"
if( Master_Bathroom_Heater.state == ON ) {
Master_Bathroom_Heater.sendCommand(OFF)
logInfo(rule_name, "Timer is up! Turning Master Bathroom Heater OFF")
}
if( Master_Bathroom_Fan.state == ON ) {
Master_Bathroom_Fan.sendCommand(OFF)
logInfo(rule_name, "Timer is up! Turning Master Bathroom Fan OFF")
}
end
Another examples is using the ASTRO binding to execute a rule when the Sun Phase changes:
rule "Define when Sun is up or down"
when
Item Sun_Phase changed or
System started
then // Simple rule, no need for 1-2-3 approach nor logging
logInfo("TEST","THE SUN UP RULE DID RUN.")
switch Sun_Phase.state {
case "CIVIL_DUSK", case "NAUTIC_DUSK", case "ASTRO_DUSK", case "CIVIL_DAWN",
case "NAUTIC_DAWN", case "ASTRO_DAWN", case "NIGHT": {
if( Sundown.state != ON ) { Sundown.sendCommand(ON) }
}
case "SUN_RISE", case "DAYLIGHT", case "SUN_SET": {
if( Sundown.state != OFF ) { Sundown.sendCommand(OFF) }
}
default: { }
}
end
In both instances the item is getting changed (I see it in the logs) but the rule fails to run. As I said above, if I modify the file, say add an empty line… it loads and it is recognized and it works as intended, but upon restart the same behavior occurs.
At this point I have reverted back to version 2.5.1 (one of the benefit of running under a docker) with everything working as intended… and I have stopped the 3.0.1 instance. I am not sure if the issue is with my rules or something on the docker install or something else… I will like to get to the bottom of this, and fix it… so any help or ideas are greatly appreciated.
Thanks.