I’m having an issue all of sudden with startup order causing RULES not to run and I think I have identified why.
Here’s the startup order log
2023-11-21 08:55:40.323 [INFO ] [enhab.core.model.core.internal.ModelRepositoryImpl] - Loading model 'default.sitemap'
2023-11-21 08:55:42.481 [INFO ] [enhab.core.model.core.internal.ModelRepositoryImpl] - Loading model 'default.things'
2023-11-21 08:56:06.482 [INFO ] [enhab.core.model.core.internal.ModelRepositoryImpl] - Loading model 'rrd4j.persist'
2023-11-21 08:56:06.709 [INFO ] [enhab.core.model.core.internal.ModelRepositoryImpl] - Loading model 'default.rules'
2023-11-21 09:03:09.828 [INFO ] [enhab.core.model.core.internal.ModelRepositoryImpl] - Loading model 'default.items'
2023-11-21 09:03:45.786 [WARN ] [oshi.software.os.linux.LinuxFileSystem ] - Failed to get information to use statvfs. path: /media/pi/6361-64621, Error code: 13
2023-11-21 09:14:33.850 [ERROR] [module.script.internal.handler.ScriptActionHandler] - Script execution of rule with UID 'default-321' failed: The name 'systemStarted' cannot be resolved to an item or type; line 33813, column 72, length 13 in default
2023-11-21 09:14:33.856 [ERROR] [module.script.internal.handler.ScriptActionHandler] - Script execution of rule with UID 'default-1' failed: The name 'Thread' cannot be resolved to an item or type; line 300, column 3, length 6 in default
2023-11-21 09:14:33.858 [INFO ] [rg.openhab.core.automation.internal.RuleEngineImpl] - Rule engine started.
When it was working, .items was loading before .rules and now it’s not. This was caused by me removing some items in the .item file.
I’ve played with the priority with in the services.cfg but this has had NO impact loading items prior to rules.
Is there a trick to prioritize .items to load prior to other files?
FYI, if I modified the .rules file and resave it after rule engine has started, OH will process the rules file. I have also cleared the cache and tmp files w/o any difference in startup.
There has not been the ability to control the order that config files are loaded since OH 1.8. There is no ability for you to change this. Since then the startup of OH has always been an asynchronous affair and sometimes the timing doesn’t work out.
In OH 3 and OH 4 there was introduced “system runlevels”. Items get loaded before runlevel 30. Rules get loaded at 40, the rule engine starts at 50, Things are initialed at 80.
In practice restoreOnStartup is often still occurring when runlevel 40 is hit.
But your error isn’t caused by Items being loaded after the rules. It’s being caused by Items receiving events that triggers rules before the rule engine has started.
It’s complaining about systemStarted and Thread. You should not have an Item with either of these names. These are reserved words, not Items.
Usually you see this error in cases where the rules start triggering before the rules engine is ready. And you can see that in the logs. The errors occur before “Rule Engine started.”
Often this occurs when there was an update or when you clear the cache because it takes some extended amount of time to download the add-ons and OH doesn’t wait for that before it continues with the startup process. Clearing the cache in this case is definitely going to exacerbate the problem.
I don’t know if there is an issue open for this or not. I’ve worked around it using Delay Start [184.108.40.206;220.127.116.11] but I only have a couple of rules that have a lot of Items which update frequently and frequently trigger rules to run between run levels 40 and 50.
If this happens on every boot, I recommend filing an issue. In the mean time you should be able to use the rule template above to block execution of rules triggered by Item events