[SOLVED] Cannot get rules to work, OH2.2, Windows

Hi all,

So I’ve delved into the world of openHAB and I’m loving whats possible, however, I really need to get rules working to make it really worthwhile.

I have setup a simple test rule in order to see if it gets logged but nothing, here is what I’ve added:


Channel “astro:sun:home:rise#event” triggered START
logDebug(“testrule.rules”, “TESTING LOGGING WHEN SUNRISE”)

log:set DEBUG org.eclipse.smarthome.model.script

I can see the astro sunrise START event in the log, but nothing regarding the TEST_SUNRISE debug.

What am i doing wrong? :unamused:


I don’t know if this is helping, but maybe change the logDebug to logInfo and don’t use a dot in “testrule.rules”. So for example:
logInfo(“testrule_rules”, “TESTING LOGGING WHEN SUNRISE”)

@Matt_T maybe try logInfo instead of debug. Or make sure the log also shows Debug loggings. Just some thougths.

Maybe make a rule which changes a switch in the ui so you see the rule getting triggered.

OK, I have changed the rule:


Channel “astro:sun:home:set#event” triggered START
logInfo(“testrule_rules”, “TESTING LOGGING WHEN SUNSET”)
zwave:device:205872c7:node2:switch_binary = ON

I’ve removed the dot, changed the log to Info, and added a switch (ideally this is the scenario I want to happen anyway - light to come on at sunset)


I am not aware that this is how it works.
You have to connect an item to the channel and sendcommand or postupdate to this item.

sendcommand( ItemLinkedToChannel, command)

Or does anyone know if it is possible to direcly access channels in rules? And how?

You cannot. You must send the command to an Item like you demonstrate in your example.

OK, changed the command to: GF_Hallway_Light.sendCommand(ON), following the syntax specified in https://docs.openhab.org/configuration/rules-dsl.html#manipulating-item-states.

The rule still didn’t trigger a log however :frowning:

Am I missing a step here? Like loading the rule file or something? I have simply created the rule file and logging entry, and restarted the openHAB service.

Does any rule trigger?

lets try the simplest setup.


Switch test_sw


rule "Randome Rule"
    Item test_sw received command
    logInfo("Randome Rule", "Triggered Item "+ triggeringItem.name +" changed to " + receivedCommand ) 


sitemap testRules label="Test Rules"
        Frame label="Switch"
          Switch item=test_sw

Does pressing the switch in basic UI trigger the rule?

Nope, no log output after pressing test_sw.

Also, noted the spelling mistake with test_swt and test_sw in above examples.

@Matt_T do you follow the Karaf console when changing the files, Is there an error when you save the rule?

I typed this on the go did not have it running in my setup. Sorry for the typo.
Maybe try a fresh install of openhab, as the astro binding is known to sometimes make some trouble with firering rules but this should have been solved.
But when a simple switch allready does not trigger the rule there seems something to be very strange.

OK it appears I have got somewhere! Simple mistake of the rules file not being the correct extension type, it was saved as a ‘file’, not ‘rules’.

I am seeing log messages now when i save the rules file and a simple time rule has triggered the switch.

Thanks all for the help!

Next problem: It only seems to load the rule if it contains ONLY rule, when, then, end. Anything ese and it returns an error, even a // comment, or an empty return.

Any clues on that? I’m using Notepad++ to edit.

Can you post the full .rules file content. I’m not sure what you are talking about.

 rule "Hall Lamp on"
     Channel "astro:sun:home:set#event" triggered START

Any other text or character in the rules file results in:

23:06:50.434 [WARN ] [del.core.internal.ModelRepositoryImpl] - Configuration model ‘lighting.rules’ is either empty or cannot be parsed correctly!

Seems like Notepad++ could be the culprit, and its not actually a bug/error:

I think this is wrong. It cannot be used like this


create a item in text file (I do not use to create them via habmin) but shoud be the same

Switch ZWAVEitem	{ channel="zwave:device:205872c7:node2:switch_binary" }

and use


Actually, it does work, no need to set up another item.

Rules work perfect now, lamp turns on at sunset and off at 11:30pm! On to the next challenge with persistence and graphing :sunglasses:

Thanks all.