Rules do not trigger after update

  • Platform information:
    Hardware: Raspberry Pi 4 Model B Rev 1.5
    OS: openHABian 5.1.4
    Java Runtime Environment: OpenJDK Runtime Environment Temurin-21.0.11+10 (build 21.0.11+10-LTS)
    openHAB version: openHAB 5.1.4 - Release Build

  • Issue of the topic:
    Every time after I am updating openHAB to a new vesion (today going from 5.1.1 to 5.1.4) some of the rules are not triggering anymore.
    If I go to the rule in MainUI and try to trigger the rule manually (pressing the blue play-triangle) it doesn’t execute either.
    Instead I find the following error in the logs:
    Logger Class
    org.openhab.core.automation.internal.RuleEngineImpl
    Message
    Failed to execute rule ‘ASSTA_Z2M_01_KI_Button_1o_action_single_right’: Failed to execute action: 1(Cannot invoke “com.google.inject.Injector.getInstance(java.lang.Class)” because the return value of “org.openhab.core.model.script.ScriptStandaloneSetup.getInjector()” is null)

    Pressing “Save” in MainUI without any changes to the rule itself is solving the issue. Afterwards the rule is alive again.

    This behavior as described above is valid for a very specific type of rules. I generate these rules with a self coded python script and upload them to openHAB via its REST API. This is working perfect so far without any complications or warnings. After the upload they look like any other rule in MainUI and work well. Here one example:

    configuration: {}
    triggers:
    
    id: “2”
    configuration:
    event: on
    thingUID: mqtt:topic:AnMaHab2_Mosquitto:Z2M_00_GA_Button
    channelUID: mqtt:topic:AnMaHab2_Mosquitto:Z2M_00_GA_Button:action
    type: core.ChannelEventTrigger
    conditions: 
    
    actions:
    
    inputs: {}
    id: “1”
    configuration:
    type: application/vnd.openhab.dsl.rule
    script: TSM_00_HE_ESP32R4_Elektro_97_Relay4.sendCommand(ON)
    type: script.ScriptAction
    

    Please help me in finding out the cause of this issue. Thank you.

When openHAB updates the cache is cleared.

When the cache is cleared openHAB needs to redownload and reinstall all the add-ons and other bundles.

While it is starting up, it doesn’t wait for all the bundles to be installed to continue. If the timing works out such that all the needed bundles are not available by start level 40 then your rules may be triggered when the software required to actually run them are not available and ready.

Unless and until this can be fixed by the maintainers somehow the best practice for performing an upgrade is:

  1. upgrade OH
  2. let OH start for that first time and ignore the errors; wait long enough for everything to settle and all the bundles had a chnce to be installed
  3. restart OH; if there are any errors now that means something is wrong and needs to be addressed.

This seems overly complex and round-a-bout given that there are no fewer than two officially supported ways to write rules in Python (jython and GraalVM Python) and one very popular and well supported third party way (HABApp).

Thanks for your fast response.

No, I guess the issue is not related to the startup process and insufficient time to get ready.
After the first startup of openHAB following a version update, the rules are visible in MainUI and have their IDLE-sign. Even after waiting long time, let say an hour, the rules do not execute if I press the manual play-button. They kind of sleep.
Instead, I get the above mentioned error message in the logs:
Failed to execute rule ‘ASSTA_Z2M_01_KI_Button_1o_action_single_right’: Failed to execute action: 1(Cannot invoke “com.google.inject.Injector.getInstance(java.lang.Class)” because the return value of “org.openhab.core.model.script.ScriptStandaloneSetup.getInjector()” is null)

Manually saving all concerned rules makes them executable again.

Regarding python rules:
I guess, here we have a misunderstanding. Sorry for being unclear.
Of course I am using the official Python scripting add-on for openHAB python rules.
The way I generate the rules concerned by above described misbehavior is as follows:
I have written a python program called ASSTA (ASSignment TAble) independent from openHAB which automatically generates rules for openHAB.
Why am I doing this? I have many ZigBee wall buttons and other remote controls in my house which control certain functions of openHAB, mainy lights and roller shutters.
Assigning buttons to functions inside openHAB is rather troublesome. I have a central spread sheet where the assignment of buttons (triggers) to item control is defined. ASSTA is reading that table, generates related openHAB rules and injects the rules to my openHAB instance via the openHAB API. In total I have about 80 rules generated this way.

None of that is an indication that the packages needed to actually run the rules is avaialble.

Which is one of the known error messages when the rule tries to run and the engine was not available when the rule first loaded.

That’s because saving the rules causes them to be reloaded. And this time all the bundles needed are available to be injected into the rules.

You could do the same from within a Python rule (or JS, or jRuby). I know of some users who do all their OH config through rules: creating Items, Things, even sitemaps.