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");
	console.log(event);

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

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

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

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

}).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.

Has this fixed regressed since the last patch openHAB 4.3.1 (Release Build) was applied?
because I’m seeing same symptom now?
eg the below script doesn’t output anything in log

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

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

created bug ticket : JSScripting startupComplete event doesn't fire · Issue #4533 · openhab/openhab-core · GitHub

note the startup level 50 works


rules.when().system().startLevel(50).then(event => {
	console.log("test JS start:startLevel(50) trigger");
	//console.log(event);
}).build("JS rule startLevel50", "test startLevel(50) rule");

I noticed a UI built script that should run on startup level 100 doesn’t run. But I haven’t done any digging yet…

I can confirm that the trigger works fine on my system with 4.3.1.

Can you check your openHAB start level?
Go to the about page of Main UI as admin and check the technical information.

It is not the trigger that is broken, but rather your systems @mtrax @ErikDB not reaching start level 100.

where is this?

not sure if this is the place but the API call for systeminfo as below:
why is it stuck on 70???

{
“systemInfo”: {
“configFolder”: “/etc/openhab”,
“userdataFolder”: “/var/lib/openhab”,
“logFolder”: “/var/log/openhab”,
“javaVersion”: “17.0.13”,
“javaVendor”: “Ubuntu”,
“osName”: “Linux”,
“osVersion”: “6.8.0-51-generic”,
“osArchitecture”: “amd64”,
“availableProcessors”: 4,
“freeMemory”: 90968840,
“totalMemory”: 377487360,
“uptime”: 4052,
“startLevel”: 70
}
}

Some Things have not initialised properly.

Can you please close the issue you created too quickly?

ok found the Tesla Addon was not initializing had to reinstall addon to complete
once I done this I see startup scripts firing…

Question if any addon fails to start this blocks ALL startup scripts?

If you configure start level 100 for your start level trigger, yes.
If you configure start level 70, no.

This is why we have different levels. By having run level 100 it means the system has fully and successfully come online and operational. This may be important and you don’t want certain rules to run until all Things are online.

If you don’t care if all your Things have come online you have run level 70.

To be honest, I don’t know the difference between rls 40 and 50. I wouldn’t think any rules would be able to run until 50 anyway. I’ve always meant to ask about that.

You can’t get to run level 40 without successfully passing the earlier run levels so those can be ignored as outside the scope here. This is where Items are loaded and restoreOnStartup runs.

1 Like

I figured that was a possibility too. But why hasn’t it reached 100 then?

Wrt to rules SL 40 means that rules are loaded and SL 50 that the rule engine has successfully started.
So SL triggers are only useful for SL 50 and above.

one or more of your Things is in an error state, neither ONLINE nor DISABLED.

So there is really no reason to offer rl 40 in the UI then, right?

I think so, but I might be missing something.
Probably we should ask the core maintainer.

1 Like