How to activate rules?


I am trying to get rules to do something to no avail. This is my simple rule:

rule "StartRule"
		System started
		logDebug("Test", "My startup rule triggered!")

I created a logger as follows:

# Logger - Test.log = DEBUG, Test

Now I am expecting to find a file called Test.log in the log directory, namely /var/log/openhab2

Unfortunately, nothing happens.

Can anyone point me in the right direction and tell me what I am doing wrong?

You also need to define a log file appender. See here:

1 Like

I would use logInfo to make sure the logging-config is not your problem.

Thanks for your inputs. Added the file appender, and now I get a log file called Test.log as expected. However, my rules are still not triggering. The reason I got into this in the first place, is because I had started writing some rules, and nothing happened. Then I thought to reduce the rules to their most simple form, and still nothing is happening (i.e. no log entry appears). I already tried loginfo, didn’t log anything either.

Do I need to do anything special to “activate” rules in OH2, besides copying them to /etc/openhab2/rules (Ubuntu, repo install) and making sure that there are no permissions problems (openhab, 766)? Btw, I did restart the OH2 service after every rule change.

Do you see any errors at startup?

Do you see a line in the log about your .rules file being loaded at startup or when you modify the file?

There is nothing special that needs to be done to activate rules.

No errors in events.log and none in opehhab.log either. I am running (actually testing) unstable, and just in case any bindings are getting into the way, I deactivated every single one of them - nothing is active anymore. Just the core system with a single rule, as stated above. My Test.log is zero bytes. Just in case I did something wrong in org.ops4j.pax.logging.cfg, here is my config:

# Logger - Test.log = DEBUG, Test

# File appender - Test.log
log4j.appender.Test.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n

I did not change anything else (should I have?). This a repo based install on Ubuntu 16.04. ZWave, OpenSprinkler and the DSC bindings I tested worked just fine. But without rules, I am not going anywhere in terms of automation. Anybody have an idea what the heck is going on? Or am I missing some vital point?

Just in case I missed something, this is the complete dump from my logs (I deleted them and this was created when I restarted the OH2 service):


2017-05-22 21:46:58.851 [ItemChannelLinkAddedEvent ] - Link 'ZWaveNode2ZW100MultiSensor6_SensorRelativeHumidity-zwave:device:f858f2b9:node2:sensor_relhumidity' has been added.
2017-05-22 21:46:58.863 [ItemChannelLinkAddedEvent ] - Link 'ZWaveNode5ZMNHBDFlush2Relays_Switch-zwave:device:f858f2b9:node5:switch_binary1' has been added.
2017-05-22 21:46:58.865 [ItemChannelLinkAddedEvent ] - Link 'ZWaveNode5ZMNHBDFlush2Relays_ElectricMeterWatts-zwave:device:f858f2b9:node5:meter_watts' has been added.
2017-05-22 21:46:58.867 [ItemChannelLinkAddedEvent ] - Link 'OpenSprinkler_Station01-opensprinkler:http:558dbb46:station01' has been added.
2017-05-22 21:46:58.869 [ItemChannelLinkAddedEvent ] - Link 'Keypad_KeypadReadyLED-dscalarm:keypad:4d883bb4:keypad:keypad_ready_led' has been added.
2017-05-22 21:46:58.870 [ItemChannelLinkAddedEvent ] - Link 'ZWaveNode2ZW100MultiSensor6_SensorTemperature-zwave:device:f858f2b9:node2:sensor_temperature' has been added.
2017-05-22 21:46:58.871 [ItemChannelLinkAddedEvent ] - Link 'ZWaveNode2ZW100MultiSensor6_SensorLuminance-zwave:device:f858f2b9:node2:sensor_luminance' has been added.
2017-05-22 21:46:58.873 [ItemChannelLinkAddedEvent ] - Link 'ZWaveNode2ZW100MultiSensor6_SensorMotion-zwave:device:f858f2b9:node2:sensor_binary' has been added.
2017-05-22 21:46:58.874 [ItemChannelLinkAddedEvent ] - Link 'Zone1_ZoneStatus-dscalarm:zone:4d883bb4:zone1:zone_status' has been added.
2017-05-22 21:46:59.020 [ThingAddedEvent           ] - Thing 'dscalarm:keypad:4d883bb4:keypad' has been added.
2017-05-22 21:46:59.036 [ThingAddedEvent           ] - Thing 'zwave:device:f858f2b9:node5' has been added.
2017-05-22 21:46:59.042 [ThingAddedEvent           ] - Thing 'zwave:device:f858f2b9:node2' has been added.
2017-05-22 21:46:59.043 [ThingAddedEvent           ] - Thing 'dscalarm:envisalink:4d883bb4' has been added.
2017-05-22 21:46:59.045 [ThingAddedEvent           ] - Thing 'zwave:serial_zstick:f858f2b9' has been added.
2017-05-22 21:46:59.050 [ThingAddedEvent           ] - Thing 'dscalarm:zone:4d883bb4:zone1' has been added.
2017-05-22 21:46:59.058 [ThingAddedEvent           ] - Thing 'opensprinkler:http:558dbb46' has been added.


 21:46:59.954 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at /start
2017-05-22 21:47:00.515 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
2017-05-22 21:47:00.621 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2017-05-22 21:47:00.700 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2017-05-22 21:47:00.810 [INFO ] [ui.habmin.internal.servlet.HABminApp] - Started HABmin servlet at /habmin

Where are you placing the rule file?

1 Like

As written above:

Btw, the ONLY rule I have in the system now is the following:

(permissions are correct, and tried logInfo too)

What’s the name of the rules file? (does it have the file extension ‘.rules’?

If you make a change to it and save it, do you get a line in your log file along the lines of:

[INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘myrules.rules’

(I write this as I made some blindingly obvious errors with rules when first writing them which I just couldn’t see!)

1 Like

Man, I almost sunk into the ground when I read your post. Sure enough, I had named my rule .rule instead of .rules. My brain probably somehow thought that a folder called “rules” should contain multiple “rule” files, never mind what the documentation says. In summary, my rule is processing now. Many thanks for your help, and very sorry for this basic mistake. And thanks to everyone for their support!