[SOLVED] Several rules are triggered more than once

I am running openhab2 an a raspberry pi with openhabian.
My problem is that several rules are triggered more than once because the tigger fired multiple times.

I deleted all my rules beside a single one using a startup trigger:

    rule "openHabInit"
    when
    	System started
    then
    	logInfo("startup.rules", "Startup-Timer started...")
    	createTimer(now.plusSeconds(30), [|
    		logInfo("startup.rules", "Startup-Timer expired ... initialise presets")		           sendBroadcastNotification("exec whitelist workaround")
    		executeCommandLine("chmod -v 755 /etc/openhab2/misc/exec.whitelist")
    	])
    end

At raspberry pi startup I get the following entries in openhab.log:

2020-05-21 17:16:05.527 [INFO ] [o.internal.handler.AstroThingHandler] - Scheduled Positional job astro:sun:local every 300 seconds
2020-05-21 17:16:05.977 [INFO ] [o.internal.handler.AstroThingHandler] - Scheduled Positional job astro:sun:local every 300 seconds
2020-05-21 17:16:09.178 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to 'openhabianpi' with clientid 8d786094-7f45-45c5-a16e-120ac8e02b4a
2020-05-21 17:16:12.444 [INFO ] [smarthome.model.script.startup.rules] - Startup-Timer started...
2020-05-21 17:16:13.593 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2020-05-21 17:16:13.667 [INFO ] [io.openhabcloud.internal.CloudClient] - Connected to the openHAB Cloud service (UUID = f8726efb-3e32-474e-a2fc-0b505c554ff6, base URL = http://localhost:8080)
2020-05-21 17:16:13.839 [INFO ] [ebuilder.internal.HomeBuilderServlet] - Started Home Builder at /homebuilder
2020-05-21 17:16:14.094 [INFO ] [openhab.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2020-05-21 17:16:19.750 [INFO ] [smarthome.model.script.startup.rules] - Startup-Timer started...
2020-05-21 17:16:42.476 [INFO ] [smarthome.model.script.startup.rules] - Startup-Timer expired ... initialise presets
2020-05-21 17:16:42.514 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine 'chmod -v 755 /etc/openhab2/misc/exec.whitelist'
2020-05-21 17:16:49.760 [INFO ] [smarthome.model.script.startup.rules] - Startup-Timer expired ... initialise presets
2020-05-21 17:16:49.820 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine 'chmod -v 755 /etc/openhab2/misc/exec.whitelist'

As you can see the startup trigger fires twice resulting in two timers…

After system startup, the ‘System started’ trigger will fire at least twice for rules in the old rule engine. It will also fire after an Item is created or removed. It will also fire after a Thing is created, removed, or modified. This has been discussed in the forum and there are issues in GitHub. However, it will never be fixed, since the old rule engine has already been removed in OH 3.0. The new rule engine with scripted automation does not have this issue.

1 Like

as a workaround you can try:

var systemStarted = new Boolean(false)

rule "openHabInit"
when
    System started
then
    if (systemStarted) return;
    systemStarted = true

    logInfo("startup.rules", "Startup-Timer started...")
    createTimer(now.plusSeconds(30), [|
        logInfo("startup.rules", "Startup-Timer expired ... initialise presets")		           sendBroadcastNotification("exec whitelist workaround")
        executeCommandLine("chmod -v 755 /etc/openhab2/misc/exec.whitelist")
    ])
end

this should cause that the rule will be executed just once

1 Like

I also thought about such a workaround, too. But I was interested about the root cause.
Nevertheless I think I have more scenarios where a trigger is firing multiple times. But those cases are not so clear.