UNINITIALIZED - HANDLER_INITIALIZING_ERROR in Next-Gen Rules

  • Platform information:

    • Java Runtime Environment: openjdk version “1.8.0_232”
    • openHAB version: 2.5.0
  • Issue of the topic:

I have created rules using the Next-Gen Rules UI that should switch on and off my circulation pump at certain times depending on whether it’s a weekday or weekend/holiday. Unfortunately, these rules show an error message in the UI: “UNINITIALIZED - HANDLER_INITIALIZING_ERROR”

Screenshot from 2020-01-02 14-30-43

Unfortunately, I can’t find any details in my openhab.log. This is the rule configuration:

Any idea on how to debug the issue is highly appreciated!

Thanks,
Florian

Does your Pump thing/item become initialized and controllable without the rule?

I do not use Next-Gen Rules but here is an example of a rule that you can modify to suit your needs (excluding the holidays, would need to play a bit to add that part).

rule "Outside ON at sunrise"
when
        Channel astro:sun:local:set#event triggered START
then
        var Number day = now.getDayOfWeek
        if ((day == 1) || (day == 2) || (day == 3) || (day == 4) || (day == 5)) {
        if (TIME_WORKWEEK == ON) {
           logInfo("ELEC", "buitenverlichting aan")
           VERL_Parking.sendCommand(ON)
           }
		   else {
		   	VERL_Parking.sendCommand(OFF)
		   }
		}
end

This uses the Astro binding to trigger the rule at sunset so you can change the trigger to a cron time or use a different astro event. Also need to add a timer for how long you want the pump to run. This rule is not complete, just to get you started and if you need help that’s what we’re here for.:wink:

Rule using a timer for motion example:

var Timer myTimer = null
rule "Motion OFF"
when
    Item Motion changed from OFF
then
    if (myTimer === null) {
        if  (Motion.state == ON) {
            myTimer = createTimer(now.plusSeconds(60), [ |
                if (Motion.state == ON){
                //do stuff
                }
            ])   
        }
    }
end

rule "BACK FROM ON"
when
    Item Motion changed from ON
then
    myTimer.cancel
    myTimer = null
end

You can change the time now.plusSeconds to now.plusHours or Minuets to fit your situation. Again this is an example to get you started once you have your pump item initialized.

Thanks for the examples, maybe I actually need to build the rules using config files instead of the UI.

The pump thing/item is a simple Tasmota switch via MQTT and works perfectly fine in other rules I defined via the UI, so I’d rather say it’s not the root cause here. But I might be mistaken.

The Next Gen Rules is experimental and I have not done much with it as I prefer to write my own rules.

If you search the forum there are many examples of rules to use as a starting point. You may even find one that fits your exact need.:wink:

I should probably write a single post I can link back to. There is some terminology here that I think confuses a lot of users.

NGRE refers to all of “Scripted Automation” including:

  • formerly called JSR223 Rules (i.e. Rules you can write in Jython, JavaScript, or Groovy, more languages to come)
  • Rules created through PaperUI/REST API
  • The UI in PaperUI

Of the three, only PaperUI is experimental. The rest are rock solid and mature. They’ve been around for years and are unlikely to receive many if any breaking changes going forward. PaperUI though is barely usable and that is the only reason for the “experimental” in the name.

But whether you write your Rules using Jython and the Helper Libraries, add a Rule using the REST API using JSON, import a Rule from some other source, or define a Rule using PaperUI, they are all running on the NGRE.

There is nothing about NGRE that means you can’t write your own Rules. Given that Python will become the default Rules language in OH 3 it would not be a bad idea to start exploring Python Rules in the coming months. And there is nothing about PaperUI created Rules that means you can’t write your own Rules. You can create Script Actions which are every bit as complex as anything you’ve written in Rules DSL or that you’ve written in Jython, JavaScript, or Groovy. The only differences are:

  • you use a UI or the REST API to build up the Rules
  • you don’t have to actually see/write code to do simple stuff like “update this Item when that event occurs”
  • there is support for “but only if…” which is a way to skip the Rule under certain conditions; in Rules DSL this would be an if/return; statement(s) at the start of the Rule
  • the source is stored in JSONDB which solves the whole rules start executing before Items are loaded problem, it’s way faster to load too

@Floh, unfortunately, PaperUI is kind of broken right now and I think the time triggers in particular are broken. But I am not sure that what I remember being broken would let you get as far as actually creating the triggers. So you’ve made it farther than I would expect.

First log into the Karaf console and issue the command log:set DEBUG org.openhab.core.automation. Try editing the Rule and save it and look at the logs to see if you can get any more information about the error. I’m surprised there is nothing at all in the logs as the status is clearly an error.

Also look in events.log. The NGRE generates a number of events that might appear in events.log that might be informative.

Go to the REST API Docs, scroll down to Rules and query for this Rule (the “a1e…” is the UID of the Rule that you will enter into the form). Post the JSON result here (please use code fences).

1 Like

Thanks for the detailed explanation! I narrowed it down to the following error message in the events.log:

a1e15e08-5d3a-4212-abf1-bccde107cfba updated: UNINITIALIZED (HANDLER_INITIALIZING_ERROR): Getting handler ‘ephemeris.WeekdayCondition’ for module ‘3’ failed: Config parameter ‘offset’ is missing in the configuration of module ‘3’.

Actually I haven’t set an offset value (thinking it will default to zero), but even after explicitly setting the offset value to 0 (or 1) doesn’t help. Here’s the rule config:

{
   "status":{
      "status":"UNINITIALIZED",
      "statusDetail":"HANDLER_INITIALIZING_ERROR",
      "description":"Getting handler \u0027ephemeris.WeekdayCondition\u0027 for module \u00273\u0027 failed: Config parameter \u0027offset\u0027 is missing in the configuration of module \u00273\u0027.\n"
   },
   "triggers":[
      {
         "id":"1",
         "label":"Morgens 6 Uhr",
         "description":"Triggers at a specified time",
         "configuration":{
            "time":"06:00"
         },
         "type":"timer.TimeOfDayTrigger"
      },
      {
         "id":"2",
         "label":"Abends 18 Uhr",
         "description":"Triggers at a specified time",
         "configuration":{
            "time":"18:00"
         },
         "type":"timer.TimeOfDayTrigger"
      }
   ],
   "conditions":[
      {
         "inputs":{

         },
         "id":"3",
         "label":"It is a weekday",
         "description":"Checks if the current day is not on the weekend.",
         "configuration":{
            "offset":0
         },
         "type":"ephemeris.WeekdayCondition"
      },
      {
         "inputs":{

         },
         "id":"4",
         "label":"Abwesenheit AUS",
         "description":"Compares the item state with the given value",
         "configuration":{
            "itemName":"holiday_mode",
            "state":"OFF",
            "operator":"\u003d"
         },
         "type":"core.ItemStateCondition"
      }
   ],
   "actions":[
      {
         "inputs":{

         },
         "id":"5",
         "label":"Pumpe AN",
         "description":"Sends a command to a specified item.",
         "configuration":{
            "itemName":"pump",
            "command":"ON"
         },
         "type":"core.ItemCommandAction"
      }
   ],
   "configuration":{

   },
   "configDescriptions":[

   ],
   "uid":"a1e15e08-5d3a-4212-abf1-bccde107cfba",
   "name":"Pumpe Wochentags AN",
   "tags":[

   ],
   "visibility":"VISIBLE"
}

For the time being I’ve created the following rules on a file basis:

rule "Circulation Pump ON (Weekends/Holidays)"
when
        Time cron "0 30 7 1/1 * ? *" or // 7:30
        Time cron "0 0 12 1/1 * ? *" or // 12:00
        Time cron "0 30 18 1/1 * ? *" // 18:30
then
        if((Ephemeris.isWeekend || Ephemeris.isBankHoliday) && holiday_mode.state == "OFF") {
                pump.sendCommand(ON)
                createTimer(now.plusHours(2), [ |
                        pump.sendCommand(OFF)
                        logInfo("notifications", "Circulation Pump (Weekend/Holiday) OFF.")
                ])
                logInfo("notifications", "Circulation Pump (Weekend/Holiday) ON.")
        }
end

rule "Circulation Pump ON (Weekdays)"
when
        Time cron "0 0 6 1/1 * ? *" or // 6:00
        Time cron "0 0 18 1/1 * ? *" // 18:00
then
        if((!Ephemeris.isWeekend && !Ephemeris.isBankHoliday) && holiday_mode.state == "OFF") {
                pump.sendCommand(ON)
                createTimer(now.plusHours(2), [ |
                        pump.sendCommand(OFF)
                        logInfo("notifications", "Circulation Pump (Weekday) OFF.")
                ])
                logInfo("notifications", "Circulation Pump (Weekday) ON.")
        }
end

This however is untested for now and might be wrong though…

It seems ephemeris has a glitch in the configuration. Search the forum for ephemeris.cfg for other reports of this. I’ve seen strange NGRE behavior (like rules not loading or triggering) until the configuration for ephemeris is cleaned up.

Bingo! Not only do we have an error, I actually know what it means. :smiley:

As Scott suggests, you need to get the Ephemeris configuration straightened out before the Rule will work. Look at the various posts he links to for details. Different approaches to fixing that have worked for different people. Once you have a proper weekend-dayset defined I think the Rule will work.

Hmm, I’ve created an ephemeris.cfg in $OH_CONF/services/ with the following content and restarted OH, but the error persists:

country=de
region=hh
dayset-workday=[MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY]
dayset-weekend=[SATURDAY,SUNDAY]

My /var/lib/openhab2/config/org/openhab/ephemeris.config does also look correct:

:org.apache.felix.configadmin.revision:=L"3"
city="Hamburg"
country="de"
dayset-school=( \
  "MONDAY", \
  "TUESDAY", \
  "WEDNESDAY", \
  "THURSDAY", \
  "FRIDAY", \
)
dayset-weekend=( \
  "SATURDAY", \
  "SUNDAY", \
)
dayset-workday=( \
  "MONDAY", \
  "TUESDAY", \
  "WEDNESDAY", \
  "THURSDAY", \
  "FRIDAY", \
)
region="hh"
service.pid="org.openhab.ephemeris"

Or am I missing anything here?

Have you tried using the openhabian-config tool and change the setting to have the rules load after OH is started?

This does nothing for NGRE rules.

1 Like

Wasn’t sure and good to know, thanks @5iver.

1 Like

The only functional difference I see is my first line says L"2" instead of L"3". Maybe that is relevant.

I have L"35" ???

Maybe it’s not relevant than. I’ve no idea what that line means.