Because Items are processed and managed by lots of different parts of OH.
In this case events on Items are processed by the Event Bus. When an Item receives and update or changes or receives a command then this event gets published to the event bus. The Rule gets triggered based on these published events. But Rules need to parse and load the Items separately from the Event Bus because it needs to use Items in a different way. Consequently, the Event Bus has loaded all the Items but the Rules Engine has not. The event occurs and the Rules engine has loaded enough to know it needs to kick off this Rule but not enough yet to know that the Item exists.
Thanks for the explanation. It’s everything but obvious for the user.
I wonder, if this could be improved by syncing the two processing threads before rules get executed?
There is an open issue (maybe two because there are a bunch of related issues here). All I know is there is no simple solution for it.
I feared this would be the case…
Any news in this case?
“cannot be resolved to an item or type”
This is a known an permanent bug with Rules DSL. The only solution is to implement something outside of OH itself to move the .rules files out of the rules folder, wait long enough for OH to finish starting up, and then move them back. There is an option in openhabian-config to configure this if that is what you are running. If not, it’s just a few commands added to the openhab2.service file. Look in the openHABian repo for their example.
Note there are fifty other ways to provoke this error message, apart from the files load timing issue.
Don’t just assume this is your issue without proper investigation.
Rich, I’ve a solution in place in my current openhabian installation, but I would like to migrate to docker … any idea how to manage this issue in a container?
You will need to create a script that you mount into the container. See https://github.com/openhab-scripters/openhab-helper-libraries/pull/215 for an example way to do this sort of container initialization script. This should work to move the .rules files out. But I’m not sure how you would move them back after OH starts up.