Javascript startup rule doesn't fire

  • openHAB version: 3.4
  • Javascript : openhab-js version 4.3.0

is there something I’m doing wrong I don’t see any think in my log to indicate the below rules fired after restart.

rules.when().system().startLevel(50).then(event => {
	console.log("JS start:startLevel(50) trigger");

}).build("JS rule startLevel50", "test startup rule");

rules.when().system().startLevel(80).then(event => {
	console.log("JS start:startLevel(80) trigger");

}).build("JS rule startLevel80", "test startup rule");

rules.when().system().startupComplete().then(event => {
	console.log("JS start:startupComplete trigger");

}).build("JS rule startupComplete", "test startup rule");

I find it useful to change the logging level of openhab.event.StartlevelEvent to INFO and then you’ll see log entries in events.log when each runlevel event occurs.

Note, if you hav Things that are in an error state, runlevel 80 and 100 may never be reached at all.

No wonder that those rules don’t work on openHAB 3.4 …
Most automation add-ons started-up on a higher start-level and therefore the rules were loaded e.g. on start level 100 so rules with start-level trigger 60 weren’t executed.

This issue was fixed with Trigger immediately when start level already reached by J-N-K · Pull Request #3278 · openhab/openhab-core · GitHub.

There was also the issue that UI rules with start-level trigger and script actions weren’t working because the automation add-ons weren’t available when the rule triggered, this was fixed with Add a ScriptEngineFactory bundle tracker by J-N-K · Pull Request #3275 · openhab/openhab-core · GitHub.
Automation add-ons should now be available on start-level 30.

1 Like

Looks like this is fixed in v4. 0 correct?

Correct, I have just verified that on the latest snapshot (Build #3508) and it is fixed.
Note that startlevel triggers now also trigger when you change a file and the rule is re-added then – they trigger immediately when the start level is already reached.