When "System started" rule

When did this stop working ?

“System started”

My rule never run, it use to work in older version of openhab.
I currently run openhab 3.1 release

rule "Reset timers and flags at startup"
when
    System started
then
    logInfo("bootup", "System startet, regle genstartet.")
    //Hvis SystemKLAR er null, så er det første start. (skal kun køres ved første start)

Thanks Mads

i think it’s since 3.0.0, it’s not yet working in 3.1.0 either. Looking forward to 3.2.0

Depends on what you mean by “not working”. OH 3 introduced the concept of run levels. There are a number of stages that OH goes through during a startup from 00 to 100 (fully started). This solved a number of problems in OH 2 related to when rules start running before Items or Things are loaded for example and it give us much more control over the system.

However, that change also changed the behavior of System started triggers. These triggers now actually implement what they say. They trigger a rule when the system has started, i.e. when OH has started (technically when OH reaches run level 60. Since that event only occurs once when OH first starts up that means your rule won’t trigger when you save the .rules file after that point.

So it’s not a bug, it’s working as designed.

There is an issue open to add a “Rule Loaded” trigger (which only really makes sense in text based rules) but I’ve not followed the status of that.

In the mean time, you can manually run the rule in MainUI after you’ve changed the file and saved it. The rule will run when OH is restarted otherwise, just not when you’ve changed the file. And the System started trigger will never again trigger the rule in that circumstance.

2 Likes

Hi

Ok, so its just working differently then is to do :wink:

I would like to use something that works as the system started use to do

For example if I manually stop and start openhab or if I reboot my rpi4 then I would like to have my rule triggered at startup.

Any suggestions :slight_smile:

Ohh and at the moment I only use text based configuration

Thanks Mads

That’s literally the only time that a “System started” rule will trigger. This should work already and if that is not working you need to file an issue.

It’s only the case where you edit the .rules file and save it that will not cause the rule to trigger.

And whether or not you use text configs, you can still see and manually run your rules in MainUI. You don’t have to write a rule in the UI to run it in the UI.

1 Like

Hi

I’m not able to trigger the rule with stop/start or reboot.

I do remember that it use trigger when just changing rules, what a pain.

Is there a change I should do in mainUI or is it just broken some how?

Thanks Mads

If the rule is not triggering when openHAB starts up then it’s a bug and an issue needs to be filed. How to file an Issue

1 Like

Does your xxx.rules file load? There will be a message in your openhab.log.
It needs to be in the right folder.

HI

This log is after stop and reboot

2021-12-09 15:53:55.964 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Time zone set to 'Europe/Copenhagen'.
2021-12-09 15:53:56.032 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Location set to '00.5519418606257,0.673461914062502'.
2021-12-09 15:53:56.035 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Locale set to 'da_DK'.
2021-12-09 15:53:56.038 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Measurement system set to 'SI'.
2021-12-09 15:54:08.120 [WARN ] [org.openhab.core.net.NetUtil        ] - Invalid address '192.168.0.101/24', will use first interface instead.
2021-12-09 15:54:08.124 [WARN ] [org.openhab.core.net.NetUtil        ] - Found multiple local interfaces - ignoring 192.168.0.101
2021-12-09 15:54:11.070 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'telefoner.items'
2021-12-09 15:54:12.578 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'timer.items'
2021-12-09 15:54:12.805 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'chromecast.items'
2021-12-09 15:54:12.885 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'xiaomi.items'
2021-12-09 15:54:13.100 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'presence.items'
2021-12-09 15:54:13.136 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'go-eCharger.items'
2021-12-09 15:54:13.547 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'milight.items'
2021-12-09 15:54:13.605 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'doorcontacts.items'
2021-12-09 15:54:13.671 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'sysinfo.items'
2021-12-09 15:54:13.742 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'bosch-indego.items'
2021-12-09 15:54:13.798 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'sonofftasmota.items'
2021-12-09 15:54:14.087 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mb-connect.items'
2021-12-09 15:54:14.315 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'demo.items'
2021-12-09 15:54:14.327 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'groups.items'
2021-12-09 15:54:15.136 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mylandroidbind.items'
2021-12-09 15:54:15.557 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'zigbee2mqtt.items'
2021-12-09 15:54:17.464 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'homemade.items'
2021-12-09 15:54:18.186 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'rrd4j.persist'
2021-12-09 15:54:18.341 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mapdb.persist'
2021-12-09 15:54:19.106 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'Olafsvej23.sitemap'
2021-12-09 15:54:19.823 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mb_connect.sitemap'
2021-12-09 15:54:19.871 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'goeCharger.sitemap'
2021-12-09 15:54:20.493 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'zigbee2mqtt.things'
2021-12-09 15:54:21.251 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'go-eCharger.things'
2021-12-09 15:54:21.339 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'sonofftasmota.things'
2021-12-09 15:54:21.396 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'astro.things'
2021-12-09 15:54:21.415 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'homemadeMQTT.things'
2021-12-09 15:54:21.451 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'chromecast.things'
2021-12-09 15:54:21.475 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'exec.things'
2021-12-09 15:54:21.498 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mail.things'
2021-12-09 15:54:21.525 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'xiaomi.things'
2021-12-09 15:54:21.542 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'network.things'
2021-12-09 15:54:27.966 [INFO ] [.core.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2021-12-09 15:54:42.617 [INFO ] [org.openhab.ui.internal.UIService   ] - Started UI on port 8080
2021-12-09 15:54:42.904 [INFO ] [e.automation.internal.RuleEngineImpl] - Rule engine started.
2021-12-09 15:55:03.877 [WARN ] [org.openhab.core.net.NetUtil        ] - Invalid address '192.168.0.101/24', will use first interface instead.
2021-12-09 15:55:03.885 [WARN ] [org.openhab.core.net.NetUtil        ] - Found multiple local interfaces - ignoring 192.168.0.101
2021-12-09 15:55:05.087 [INFO ] [ternal.dhcp.DHCPPacketListenerServer] - DHCP request packet listener online
2021-12-09 15:55:05.470 [WARN ] [.core.thing.binding.BaseThingHandler] - Handler MiIoVacuumHandler of thing miio:vacuum:wally tried updating channel actions#segment although the handler was already disposed.
2021-12-09 15:55:07.691 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to 'localhost' with clientid 0
2021-12-09 15:55:07.700 [WARN ] [org.openhab.core.net.NetUtil        ] - Invalid address '192.168.0.101/24', will use first interface instead.
2021-12-09 15:55:07.718 [WARN ] [org.openhab.core.net.NetUtil        ] - Found multiple local interfaces - ignoring 192.168.0.101
2021-12-09 15:55:07.739 [WARN ] [.MqttBrokerConnectionServiceInstance] - MqttBroker connection configuration faulty: host : You need to provide a hostname/IP!
2021-12-09 15:55:07.844 [WARN ] [org.openhab.core.net.NetUtil        ] - Invalid address '192.168.0.101/24', will use first interface instead.
2021-12-09 15:55:07.847 [WARN ] [org.openhab.core.net.NetUtil        ] - Found multiple local interfaces - ignoring 192.168.0.101
2021-12-09 15:55:07.915 [WARN ] [org.openhab.core.net.NetUtil        ] - Invalid address '192.168.0.101/24', will use first interface instead.
2021-12-09 15:55:07.918 [WARN ] [org.openhab.core.net.NetUtil        ] - Found multiple local interfaces - ignoring 192.168.0.101
2021-12-09 15:55:08.070 [WARN ] [org.openhab.core.net.NetUtil        ] - Invalid address '192.168.0.101/24', will use first interface instead.
2021-12-09 15:55:08.087 [WARN ] [org.openhab.core.net.NetUtil        ] - Found multiple local interfaces - ignoring 192.168.0.101
2021-12-09 15:55:09.834 [INFO ] [io.openhabcloud.internal.CloudClient] - Connected to the openHAB Cloud service (UUID = 0, base URL = http://localhost:8080)
2021-12-09 15:55:16.358 [INFO ] [g.discovery.internal.PersistentInbox] - Added new thing 'miio:vacuum:174DC3F3' to inbox.
2021-12-09 15:55:20.075 [INFO ] [ab.ui.habpanel.internal.HABPanelTile] - Started HABPanel at /habpanel
2021-12-09 15:55:26.183 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'googleheatmode.rules'
2021-12-09 15:55:34.859 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mainpowercalc.rules'
2021-12-09 15:55:43.264 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'lys.rules'
2021-12-09 15:56:02.901 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'milight.rules'
2021-12-09 15:56:04.808 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'badvaerelse.rules'
2021-12-09 15:56:09.355 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'presence.rules'
2021-12-09 15:56:12.185 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'lidlstringRGB.rules'
2021-12-09 15:56:20.933 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'doorcontacts.rules'
2021-12-09 15:56:27.211 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'wc.rules'
2021-12-09 15:56:30.182 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'sonofftasmota.rules'
2021-12-09 15:56:38.035 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'fidogate.rules'
2021-12-09 15:56:41.972 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'vaske-torre.rules'
2021-12-09 15:56:48.711 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'klokke.rules'
2021-12-09 15:56:54.013 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'Ferie.rules'
2021-12-09 15:56:59.570 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'Udsugning.rules'
2021-12-09 15:57:01.203 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'go-eCharger.rules'
2021-12-09 15:57:09.918 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'testfuktioner.rules'
2021-12-09 15:57:12.391 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'systemstarted.rules'
2021-12-09 15:57:41.729 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mb-refresh_token.rules'
2021-12-09 15:57:42.762 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'ringeklokke.rules'
2021-12-09 15:57:46.045 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'garage.rules'
2021-12-09 15:57:49.151 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'vacuum.rules'
2021-12-09 15:57:52.898 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'telefoner.rules'
2021-12-09 15:58:43.728 [INFO ] [core.model.script.Torretumbler.rules] - Tørretumbler startet
2021-12-09 15:58:53.858 [INFO ] [core.model.script.vaskemaskine.rules] - Vaskemaskine timer køre
2021-12-09 16:00:00.227 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'mainpowercalc-3' failed: cannot invoke method public abstract org.openhab.core.types.State org.openhab.core.persistence.HistoricItem.getState() on null in mainpowercalc
2021-12-09 16:07:30.632 [INFO ] [ore.model.script.SonoffTasmota.rules] - Pir wc aktiveret
2021-12-09 16:08:38.028 [INFO ] [core.model.script.Torretumbler.rules] - Tørretumbler timer køre
2021-12-09 16:09:53.987 [INFO ] [core.model.script.vaskemaskine.rules] - Vaskemaskine stoppet
2021-12-09 16:13:38.105 [INFO ] [core.model.script.Torretumbler.rules] - Tørretumbler stoppet

Thanks Mads

That’s nice. Are any of those the file in question? I see some other rules logging messages, are they start up rules?

Hi

Sorry, the rule is named systemstarted.rules

No i dont see the logging I have made in the rule

They are from vaske-torre.rules and lys.rules

Thanks Mads

Well, it loads the rules file and does not complain about syntax.
There have been issues with filenames, but systemstarted.rules seems reasonable.

It is however just possible that is clashing with a reserved word.
Make a new file, say startup.rules, and type in your test rule. Don’t copy-paste - sometimes people get hidden control characters in their files, which can also cause hard to find problems, so eliminate that possibility too.

Also make sure the rule name
rule "Reset timers and flags at startup"
is unique within your system - I’m sure it would be.

Hi

I will try to make a new rule file.

This is my own file, it has been working earlier in openhab 2.5 :slight_smile:

Thanks Mads

Don’t care, totally new rules management in OH3

Hi

This is how the same rule looks from MainUI rule “reader”

The start level is only 20, which is way to early, it should be 60 or so

// Triggers:
// - When the system has reached start level 20

// context: systemstarted-1
logInfo("bootup", "System startet, regle genstartet.")
//Hvis SystemKLAR er null, så er det første start. (skal kun køres ved første start)

Thanks Mads

HI

Ok, i think that in openhab 3.1 release, the “System started” trigger in DSL rules in broken, because.

This DSL rule
image

Ended up look like this in MainUI “rule reader”

image

When looking at startup levels, its my understanding that rules below level 50 will not be executed because the rule engine is not running ?

So unless there’s away to change “System started” trigger in DSL rules to a higher startup level its broken.

Thanks Mads

Maybe. Maybe they get queued. Maybe the start levels isn’t properly implemented in OH3.1 at all, and any/all ‘levels’ actually get triggered later.

The Big Question you haven’t answered … does that test rule work?

Hi

Sorry, No the test rule does not work.

Thanks Mads

it’s not necessary still repeat same questions,
We’ve been discussing it since OH3 and I’m pretty sure ticket was filled in back then.

System started trigger simply does not work in 3.1. And whatever that runlevel 20 is, it’s not triggering that trigger at all, neither for me and for many others. Neither from UI rule definiton (for into)

Personally I don’t care so much about this trigger, better to have different approach, but yes, in some cases it might be handy.

1 Like

There’s a whole bunch of reasons any given rule might not do what is expected; always worth identifying actual causes.
Fairly extensive exploration at -