Rules not working

That generally points to using a variable which has not been initialized before. But without the whole rule, it’s hard to say :slight_smile:

How can i show you the whole rule?

Take the whole text from the rule editor window and post it here - surrounded by three backticks (`), so it looks something like this in the preview window:

your code goes here

Alternatively, click on the 5th icon from the right in the editor box to create a rule codefence, and replace the text with your rule text.

Sorry, but i am a openhab-greenhorn. I create the rule via paper-ui in the section “RULES”. There ist no Text-File.
Via HABmin there i cant find the rule.
What can i do?
Via samba there is also no file i the rules directory.

I’m kind of surprised - in my paperui, there is no section RULES - what version of openhab are you on?

I use openHAB 2 with the binding “Rule Engine (Experimental)”

After restart i get the log:

17:15:23.299 [INFO ] [smarthome.event.RuleStatusInfoEvent ] - rule_1 updated: NOT_INITIALIZED
17:15:23.365 [INFO ] [smarthome.event.RuleStatusInfoEvent ] - rule_1 updated: NOT_INITIALIZED (HANDLER_INITIALIZING_ERROR): Missing handler ‘timer.TimeOfDayTrigger’ for module ‘1’

17:15:24.209 [INFO ] [smarthome.event.RuleStatusInfoEvent ] - rule_1 updated: NOT_INITIALIZED (HANDLER_INITIALIZING_ERROR): Missing handler ‘timer.TimeOfDayTrigger’ for module ‘1’

I’m sorry @kallecux, i haven’t experimented with the Rule Engine Binding yet, i’m a textfile guy :slight_smile:

For all its worth, I remember reading that the description of this rule engine being at an “experimental” state has to be taken seriously. In other words, it is known to behave strangely. Personally, I stick to text files too and have never tried it, in large part due to this warning. It is hard enough to learn a new system, starting with the features that are still in an experiments state may make it harder.

@lipp_markus: you are right, but i thought that this binding is in a status that i can use the basic functions and the programmers needs feedback from the users who tested it. i will try to create rules per textfile.

Please give give me a hint and tell me the best way to create and manage the rules (habmin, eclipse (?))

Thanks!

@kallecux you engaged with one of the best home automation systems as it lets you do virtually everything, the downside being you have to define everything. I have tried to put together a few pointers that had been helpful to me:

definitely re, re-read and read again the documentation, the good people here put just a few hours ago a new tutorial online that as a section on rules: http://docs.openhab.org/tutorials/beginner/rules.html but read the rest too, it is really great.

I have no experience with habmin (actually I got confused when I tried to use it), others love it, and I understand there are is some unique and great support in habmin for all those who use zwave (which I do not)

Eclipse or Designer is a good tool, currently I would say stick with 0.8 releases, the 0.9.0 snapshots are broken in some aspects and will indicate A LOT of syntax errors where there are none. Overall, Designer is my favorite tool for dealing with items, rules, confg, thing and other files (http://docs.openhab.org/installation/designer.html follow the links in there in case you need to know how to set up samba shares). You can always use any text editor too, which I do on the raspberry to make fixes

This may be the most important section in the forum for you on rules: https://community.openhab.org/c/setup-configuration-and-use/tutorials-examples. In particular, you may want to look at everything that starts with “design pattern” , this post here: Common Rules errors and their solutions and of course anything else that will suit your needs.

There is not a lot of choice but to read a lot, at least I have not found any yet; I understand that the rules language is XTEND which in itself lends most of its structures from java (all of OH2 is programmed in Java), so if you have an understanding of those it will help and in parts be essential.

Hope that helps giving you a start

Good morning lipp_markus,

thank you for this information. i will give my best :slight_smile:
Have a good day.

Karl Heinz

I have the same issue with the rules engine.
Rule_1 switches on a light based on an astro event and works perfectly.
Rule_5 is supposed to switch the same light off at 23:00, and returns the error:

_23:00:39.660 [INFO ] [smarthome.event.RuleStatusInfoEvent ] - rule_5 updated: RUNNING_
_23:00:39.660 [ERROR] [.automation.core.internal.RuleEngine] - Fail to execute rule '[rule_5, null]': java.lang.NullPointerException_
_23:00:39.661 [INFO ] [smarthome.event.RuleStatusInfoEvent ] - rule_5 updated: IDLE_

Here’s what the rule editor has created in the file automation_rules.json:

rule_5": {
    "class": "org.eclipse.smarthome.automation.Rule",
    "value": {
      "triggers": [
        {
          "id": "1",
          "label": "it is a fixed time of day",
          "description": "Triggers at a specified time",
          "configuration": {
            "properties": {
              "time": "16:10"
            }
          },
          "type": "timer.TimeOfDayTrigger"
        }
      ],
      "conditions": [],
      "actions": [
        {
          "id": "2",
          "label": "send a command",
          "description": "Sends a command to a specified item.",
          "configuration": {
            "properties": {
              "itemName": "ZWaveNode1045609OnOffRelaySwitch_Switch",
              "command": "OFF"
            }
          },
          "type": "core.ItemCommandAction"
        }
      ],
      "configuration": {
        "properties": {}
      },
      "configDescriptions": [],
      "uid": "rule_5",
      "name": "Test",
      "tags": []
    }
  }

And here's the rule that works (same zwave device):

"rule_1": {
    "class": "org.eclipse.smarthome.automation.Rule",
    "value": {
      "triggers": [
        {
          "id": "1",
          "label": "a trigger channel fires",
          "description": "React on events from a trigger channel of a thing.",
          "configuration": {
            "properties": {
              "channelUID": "astro:sun:159d16e7fa8:nauticDusk#event"
            }
          },
          "type": "core.ChannelEventTrigger"
        }
      ],
      "conditions": [],
      "actions": [
        {
          "id": "2",
          "label": "send a command",
          "description": "Sends a command to a specified item.",
          "configuration": {
            "properties": {
              "itemName": "ZWaveNode1045609OnOffRelaySwitch_Switch",
              "command": "ON"
            }
          },
          "type": "core.ItemCommandAction"
        }
      ],
      "configuration": {
        "properties": {}
      },
      "configDescriptions": [],
      "uid": "rule_1",
      "tags": [],
      "description": "Outside lights dusk on"
    }
  }

I would appreciate any feedback.

Thanks for your report! I was able to reproduce it and have created a fix for it: https://github.com/eclipse/smarthome/pull/2938

Yes, this “Paper UI Rule Engine” is indeed still in its beginning, thus marked as experimental. Nonetheless, I encourage you to use it, provide feedback and help making it better day by day!

Kai, thanks for the quick fix! Will continue to test the rules engine, which I think is an excellent toll for those who want to see fast results.

Kind regards

Kai Mahnke

@Kai Great that this is solved.
I had the same error message with the Experimental Rule Engin: [ERROR] [.automation.core.internal.RuleEngine] - Fail to execute rule ‘[rule_1, null]’: java.lang.NullPointerException

I am using OH2, the Stable Build, not the Snapshot Release. Is there a way to get the fix installed in the Stable Build install? If so, how can i do this? Or where can i find a description how to implement the fix?

@Kai_Mahnke Thanks, please feel free to directly report bugs at https://github.com/eclipse/smarthome/issues, if you come across further problems.

@deltabert I can check whether I could include this fix in an 2.0.1 add-ons patch release - this would mean that you only need to deinstall and re-install the rule engine through the Paper UI to get the update. But we are still in clarification of how and when we will best provide 2.0.x patches.

@Kai Thank you for your reply. I will wait for further info on the patch.
An other question i have regards an Scheduler for use in the rules. I read somewhere that this is on a to-do list. Have you any idea when such a function will be available?
B.t.w. Thanks for this great project!

@Kai could you please give some estimate when rules’ issue “when rule fire twice or more times” will be fixed?

@Kai is there any documentation on how to use the javascript API in the new rules engine? I had originally used energy monitor template as a guide but it looks like the API has changed as that rule no longer parses correctly.

“Scheduler” is a bit fuzzy. I know that @kgoderis is interested to introduce CalDAV integration to the rule engine, so that calenders can be used for scheduled actions. Wrt a “timetable” widget or anything like this within UIs themselves, I am not aware of any activities.

No, I cannot even recall a concrete bug report on this. And bugs are fixed once someone provides a PR with a fix - so it highly depends on the community.

[quote=“danielwalters86”] is there any documentation on how to use the javascript API in the new rules engine?
[/quote]

No, unfortunately not yet. This might also slightly change once the jsr233 stuff is merged, for which we are getting closer. Docs and examples will then follow.