Delay Rule loading after Startup in OH2?

Unfortunately, this still seems to be an issue…

…where rules get loaded before everything gets initialized. There is no such configuration as in OH1 to delay the loading. Here is a related topic and the solution I had used:

Since then, I have modified the script (you’ll need to create the prestart directory):

#!/bin/sh
mv `\ls -1 /opt/openhab2/conf/rules/*.rules | grep -v Startup.rules` /opt/openhab2/conf/rules/prestart
echo
echo Launching the openHAB runtime...

DIRNAME=`dirname "$0"`
exec "${DIRNAME}/runtime/bin/karaf" "${@}"

And added a Startup.rules file with:

rule "Alert: System started"
when
    System started
then
    Thread::sleep(30000)
    executeCommandLine("/bin/sh@@-c@@mv /opt/openhab2/conf/rules/prestart/*.rules /opt/openhab2/conf/rules",10000)
    logInfo("Rules", "Startup: Rules restored")
end
1 Like