Debugging rules

I’m very new to openhab2 and I have troubles writing my rules. I edit the rule file manually, test run and check in the events.log and openhab.log what’s happening. However it seems as if a rule has a syntax error, it just isn’t executed at all. No error in the logs. So how do I debug my rules in a better way then trial and error?

Use Designer. It checks the syntax as you type.

There are a few things it will highlight as errors that are not, mainly calls to Actions, using the Channel rule triggers, and referencing Items defined through PaperUI or Habmin. But beyond that it is invaluable to discover syntax errors. Even if you don’t edit your rules in Designer, you should load them into Designer when you encounter errors as a first debugging step.

Ok, will test the designer, thanks for the help!

By desiginer, do you mean the tool in habmin then? It seems super buggy.
Can sometimes not save, can definitely not delete any rules. I really don’t
know what to do. I’m so close on giving up on openhab AGAIN, don’t want to,
but I think everything is very unstable and not ready to use. All I want to
do is to write my rules and get the syntax verified, is that too much to
ask? :’(


No. That is what Designer is for.

Aha, my mistake! Thanks! :slight_smile:

First of all, thanks for you previous help! The designer works pretty good, but I have a problem I can’t get to the bottom with. My rules seem to work and the designer doesn’t complain at all over my syntax. But when I save the rules file, I get the following in the log:

18:36:26.718 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'default.rules'
18:36:26.719 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'default.rules' is either empty or cannot be parsed correctly!
18:36:26.725 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'default.rules'

I’ve tried commenting out everything in the file, still the same log entries every time I save the file. Not sure what to do…

I’ve been out of pocket for awhile. Sorry for the tardy reply.

This can point to a stray special character somewhere or the like. I’d recommend copying and pasting one rule at a time into a new file and see if that fixes the problem.

It’s ok, I solved it by clearing up all userdata and start over…

In addition to what’s been said I’m using a lot of log_info statements to see what my rules are doing. That way it’s also possible to track local variables in rules that are not visible in the INFO log.


var Number nMyNumber
nMyNumber = someCalculation
logInfo("--myRule--", "nMyNumber= " + nMyNumber)

Hi @mattias_mansson,

the use of the designer is strongly recommended - as it will help with syntax & also perform some type checks. Unfortunately I’m not aware of a rules debugger. As the log-file (depending on your log level) might be quite crowded &I do not want to setup a separate logger for rule trouble shooting I use println statements to console (like in the old days) to see inside:

rule TimeToAlarm
    Time cron "0 0/1 * * * ?" // Jede Minute
    if ((weckerEinAus.state) == ON) {
      println("wecker.rules - TimeToAlarm: Wecker == ON")

with kind regards,

I have a slightly different problem.

I have a rule file that used to run but now doesn’t do anything and doesn’t throw any errors. The file shows no syntax errors in Designer, nor in the highlights in Nano.

I have just reinstalled OpenHABian to the latest version following an SD Card problem and now this rule file doesn’t run. I have another file that has also stopped working but that one throws the error:

An error occurred during the script execution: Could not invoke method: org.eclipse.smarthom
e.model.script.actions.BusEvent.sendCommand(org.eclipse.smarthome.core.items.Item,java.lang.String) on instance: null"

Again no changes to items or rules between installations and the rest of the rules that use the same items are working fine. The items work but the rules don’t run.

I have had the problem where a syntax error with one rule in a file disables all the rules in that file but as the file didn’t change, I’m struggling to know where to start with getting these rules to work again.

VSCode? Designer has long since been end of life and never really worked well with OH 2. Nano doesn’t really do syntax checking.

Do you have any syntax errors reported in openhab.log?

Did you upgrade and now the Rules don’t work?

What do these Rules trigger on?

That particular error usually indicates that what ever you are trying to send as a command isn’t of the correct type for that Item.