Use of IF statement outside of rule

I’m having an issue when I restart my OH instance. I have a rule that runs on start to populate some items that my rules use. For 15-30 seconds at start my rules may fire before those items are populated. This is causing some issues for several things. I have a fix, but I’m not sure of the implications and would like to see if someone with a better understanding of the OH code can answer this. I have a switch item that I call “openHAB_Init” which is set as ON at the end of the item population. Is it possible for me to put something like “if ( openHAB_Init.state == ON) {” at the top of every other rules file (and close it appropriately with a } at the bottom) to avoid any other rules executing before those variables are initialized? I’m worried that things like crons will not be setup properly at start if I have this in place. Thoughts?

No, but you can do that inside each relevant rule. You don’t have to worry have the cron if the check is made inside the rule.

That’s unfortunate. There are A LOT of rules that this will have to apply to. Hence the hope of just scooping all rules inside of one rules file under that construct.

Well, “safe” programming anyway means to check for null or other unexpected state before trying to use it.

Eiether way, I’d suggest to enable the ‘delay rules load’ option in openHABian (or implement that if you can’t use openHABian) plus persistence on all relevant items. That’ll ensure rules only work with items in proper, initialized state.