Cannot get a simple rule to trigger

Openhab 1.8.3. Debian Linux wheezy with Oracle Java 1.8 on armhf.

I have two switches and I am able to toggle these on and off via the UI: I have side lamps plugged in and can see this works. However my test rule does not work.

I have tried minor changes but nothing works for me.

rule “test”

when Item Hallway_Switch changed then
sendCommand(Family_Room_Switch, OFF)
end

The relevant definitions from my items file:
Switch Family_Room_Switch “Side lamp” (GF_Family, Side_Lamps) {zwave=“2”}
Switch Hallway_Switch “Side lamp” (GF_Hallway, Side_Lamps) {zwave=“3”}

Later I want to put these onto a timer rule but I thought I’d get a simple rule working first. No such luck yet.

I have also tried using the “:command=switch_binary” switch in the z-wave binding setting but that made no difference.

Any ideas?

Dave

Try “received command” instead of “changed” in your trigger.

if that doesn’t work, I think also use

when Item Hallway_Switch.state changed then

I think by not specifying the state, the rule doesn’t know what change to watch for.

The from state and to state are optional with changed. If omitted the rule will trigger for any change.

Thanks.

I tried “received command” and “when Item Hallway_Switch.state changed then” but none of those worked. The Family_Room_Switch changes came from me, none from the rule.

Would the rule trigger show up in the Event log? Small sample of that appears as I attempted to make the rule trigger,

2016-07-17 15:00:44 - Hallway_Switch state updated to ON
2016-07-17 15:00:45 - Hallway_Switch received command OFF
2016-07-17 15:00:45 - Hallway_Switch state updated to OFF
2016-07-17 15:00:52 - Hallway_Switch received command ON
2016-07-17 15:00:52 - Hallway_Switch state updated to ON
2016-07-17 15:00:53 - Hallway_Switch received command OFF
2016-07-17 15:00:53 - Hallway_Switch state updated to OFF
2016-07-17 15:02:40 - Family_Room_Switch state updated to ON
2016-07-17 15:02:41 - Hallway_Switch state updated to OFF
2016-07-17 15:02:41 - Hallway_Switch state updated to OFF
2016-07-17 15:02:41 - Hallway_Switch state updated to ON
2016-07-17 15:02:41 - Hallway_Switch state updated to OFF
2016-07-17 15:02:41 - Hallway_Switch state updated to ON
2016-07-17 15:02:41 - Hallway_Switch state updated to OFF
2016-07-17 15:02:53 - Family_Room_Switch received command OFF
2016-07-17 15:02:53 - Family_Room_Switch state updated to OFF
2016-07-17 15:02:55 - Family_Room_Switch received command ON
2016-07-17 15:02:55 - Family_Room_Switch state updated to ON
2016-07-17 15:02:58 - Hallway_Switch received command ON
2016-07-17 15:02:58 - Hallway_Switch state updated to ON
2016-07-17 15:02:59 - Hallway_Switch state updated to ON

I am starting openhab with the debug version and browsed the log for errors but instead I found a single warning which looked interesting.

23:17:48.822 [WARN ] [cpr.DefaultAnnotationProcessor:178 ] - Unable to detect annotations. Application may fail to deploy.23:17:53.163 [WARN ] [sphere.cpr.AtmosphereFramework:941 ] - No BroadcasterCache configured. Broadcasted message between client reconnection will be LOST. It is recommended to configure the org.atmosphere.cache.UUIDBroadcasterCache

I am wondering if there’s something I’ve missed about rules: is it necessary to “include” them somehow? All I am doing is saving them in the rules folder with suffix “.rule”. I am starting openhab as root, currently, so I can’t see that permissions are an issue: all the “.rule” files have permissions 644.

This is all you have to do, provided it is in the correct directory. The correct directory depends on how you installed OH.

If it is the correct directory, you should see a message in openhab.log saying the rules file has been reloaded a few seconds after the file has been saved.

The correct filename ends in .rules

1 Like

A small error but it cost me a lot of time.

All seems to be working now. Thanks!