Need some help with my first rule

Sorry about this fairly basic question. I have been reading TFM but finding it all a bit overwhelming for a first dive in - especially for a non-developer.

I have an Aeotec Multi-sensor 6 and a Fibaro dimmer 2. I believe I have included these correctly. I can control the dimmer from PaperUI or HABmin. The sensor is showing activity in the logs like this;

2018-03-11 23:47:33.354 [vent.ItemStateChangedEvent] - zwave_device_46feb3ec_node11_sensor_binary changed from OFF to ON

I want to create a very simple test rule just to show myself that I am starting to understand what is going on. I want the rule to be that activating the motion sensor turns the light off. The basic rule syntax seems fairly straightforward but where I am struggling the most is with naming the devices in the rules. I know I do not yet have a viable rule as I get the following error in the logs when I save the file;

2018-03-12 00:03:46.190 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'test_motion.rules'

2018-03-12 00:03:46.206 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'test_motion.rules' is either empty or cannot be parsed correctly!

2018-03-12 00:03:46.319 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'test_motion.rules' has errors, therefore ignoring it: [3,67]: no viable alternative at input 'ON'

Here is my rule so far;

rule "Test motion sensor in spare room"
when
    Thing "zwave:device:46feb3ec:node11:sensor_binary" changed to ON
then
    "zwave:device:46feb3ec:node3:switch_dimmer".sendCommand(0)
end

Can someone explain what my misunderstandings are so far?

rule "Test motion sensor in spare room"
when
    Thing zwave_device_46feb3ec_node11_sensor_binary changed to ON
then
    zwave_device_46feb3ec_node3_switch_dimmer.sendCommand(0)
end

I don’t know your item name for “then”.

zwave_device_46feb3ec_node3_switch_dimmer

is a example.

Your misunterstanding is declaring your Thing as String.

This is your when part: Thing "zwave:device:46feb3ec:node11:sensor_binary" changed to ON.
It should be zwave:device:46feb3ec:node11:sensor_binary (without qoutes) as @hr3 already mentioned.

In additon it would way easier to abstract your Thing Channel into items which could receive Commands via <ITEM_NAME>.sendCommand(ON).

OK, thanks. This is helping me make some progress.

I had tried to skip creating items until I got my head around some basic rules but it looks like that wasn’t the best way to go.

I have created items for both of these things like so;

Dimmer SpareRoom_Dimmer "Spare Room Dimmer" <light> {channel="zwave:device:46feb3ec:node3:switch_dimmer"}

Contact SpareRoom_Motion_Sensor "Spare Room Motion Sensor" <motiondetector> {channel="zwave:device:46feb3ec:node11:sensor_binary"}

and then updated my rule to this;

rule "Test motion sensor in spare room"
  when
    Item SpareRoom_Motion_Sensor changed to ON
  then
    SpareRoom_Dimmer.sendCommand(0)
end

In the logs I now get;

2018-03-13 23:20:31.204 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'test_motion.rules'

2018-03-13 23:20:31.211 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'test_motion.rules' is either empty or cannot be parsed correctly!

2018-03-13 23:20:31.353 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'test_motion.rules'

which looks better, but not yet ideal. The rule certainly doesn’t seem to work.

I feel like my current implementation is correct, but obviously something is still lacking in my understanding. Can anyone help?

Try this to test and see what’s happen.

Dimmer SpareRoom_Dimmer "Spare Room Dimmer[%.1f]" <light> {channel="zwave:device:46feb3ec:node3:switch_dimmer"}
Contact SpareRoom_Motion_Sensor "Spare Room Motion Sensor[%s]" <motiondetector> {channel="zwave:device:46feb3ec:node11:sensor_binary"}
rule "Test motion sensor in spare room"
when
    Item SpareRoom_Motion_Sensor changed to CLOSED
then
    logInfo("_rule_","SpareRoom_Motion_Sensor")
    SpareRoom_Dimmer.sendCommand(0)
end

A contact can only have the state OPEN or CLOSED.

You can ignore

Configuration model ‘test_motion.rules’ is either empty or cannot be parsed correctly!

Does the dimmer works, if you change the item-value manualy?

Thanks for that.

I get the same Configuration model 'test_motion.rules' is either empty or cannot be parsed correctly! error which you say I can ignore.

I can see the motion sensor being triggered in the log

2018-03-14 15:09:15.446 [vent.ItemStateChangedEvent] - zwave_serial_zstick_46feb3ec_serial_sof changed from 83882 to 83883

2018-03-14 15:09:15.466 [vent.ItemStateChangedEvent] - zwave_device_46feb3ec_node11_alarm_motion changed from OFF to ON

2018-03-14 15:09:15.582 [vent.ItemStateChangedEvent] - zwave_serial_zstick_46feb3ec_serial_sof changed from 83883 to 83884

2018-03-14 15:09:15.602 [vent.ItemStateChangedEvent] - zwave_device_46feb3ec_node11_alarm_tamper changed from OFF to ON

2018-03-14 15:09:17.741 [vent.ItemStateChangedEvent] - zwave_serial_zstick_46feb3ec_serial_sof changed from 83884 to 83885

2018-03-14 15:09:17.755 [vent.ItemStateChangedEvent] - zwave_device_46feb3ec_node11_sensor_binary changed from OFF to ON

but I don’t see anything about the item itself changing state. (Should I?)

I also don’t see any output from the loginfo command you added.

I’m not sure what you mean by changing the item value manually, but if I create a sitemap with the dimmer item I can control the dimmer in BasicUI.

The fact that you don’t see the logging implies the rule isn’t firing.

I’d also say that your motion sensor has an ON and OFF value rather than a OPEN or CLOSED value. Contact is more for window or door sensors. In fact, your log shows it is receiving ON or OFF, so you should probably use a switch then instead of a contact?

You could also try the rule as:

rule "Test motion sensor in spare room"
when
        Item SpareRoom_Motion_Sensor changed
then
       logInfo("_rule_","SpareRoom_Motion_Sensor")  
      // You have to see the above in the log, otherwise it means the 
      // rule was never triggered with the described condition.
       if (SpareRoom_Motion_Sensor.state == ON)
       {
               SpareRoom_Dimmer.sendCommand(0)
       }       
end

@boconnor may i ask on which system (windows/linux) you’re running your openHab and which editor you’re using.
I had thge same behavior when i was initially using notepad in windows for the job, not the best idea.
you can use the “Eclipse smarthome designer” (https://www.eclipse.org/smarthome/documentation/community/downloads.html) or the “openHAB VS Code Extension” (https://docs.openhab.org/configuration/editors.html#openhab-vscode) for editing roles, items, 


@Matt77

Please note that the Designer has been deprecated is not part of the release anymore.

Yes

Than the rule doesn’t run.

For searching the problem you can define the items in a sitemap and changing the switch manually.

We know only that part of your configuration you have posted. Your z-wave definition und your items don’t match. If is’t a item you can use for example

    Item zwave_device_46feb3ec_node11_sensor_binary changed to ON

Just to check,
Did you save you items in a *.items file?

You have already created the items through the paper UI.
Remove the SpareRoom_Motion_Sensor from you items file.
and try:

rule "Test motion sensor in spare room"
when
        Item zwave_device_46feb3ec_node11_sensor_binary changed
then
       logInfo("_rule_","SpareRoom_Motion_Sensor")  
      // You have to see the above in the log, otherwise it means the 
      // rule was never triggered with the described condition.
       if (SpareRoom_Motion_Sensor.state == ON)
       {
               SpareRoom_Dimmer.sendCommand(0)
       }       
end

removed

removed

@vzorglub

It looks like a item-file.

Yes but are they saved in a *.items file like spareroom.items for example

Thanks everyone for so many helpful replies.
Changing the item from a contact to a switch solved it. Thanks @SkyyStorm. It is great to finally see my system spring to life, even if it’s just a toy example.

This gives me a working demonstration to further develop from. Hopefully I’ll be able to be independent for a little while at least now. I’m sure I’ll be back though.

1 Like

@hr3

Does this really work. If I use it I get an error in log.

I want to get a rule triggered if the thing gets an update but this rule is never triggered. Only difference is, that I use the thing not the item.

when
  Thing zwave_device_15a7a49f3a6_node3 received update
then
...
2018-03-14 10:08:23.011 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'einstellungen.rules' has errors, therefore ign
oring it: [20,3]: no viable alternative at input 'zwave_device_15a7a49f3a6_node3'

This one will work, but never triggered:

when
  Thing 'zwave_device_15a7a49f3a6_node3' received update
then
...

even if a log message indicates this:

2018-03-14 10:06:42.146 [me.event.ThingUpdatedEvent] - Thing 'zwave:device:15a7a49f3a6:node3' has been updated.

The triggers for rules are things channels and items not the things themselves, I don’t think that’s possible.
Define an item for a channel of the thing and use the item to trigger the rule.

@hr3
Thanks for teh reply. Can you guide me what I should do:

Should I do this? Without any channel? Because I cannot use a channel because this channel is not triggered only the thing itself. and if yes w hich item type should I user?

Contact DummyForTrigger "DummyForTrigger"	{channel="zwave:device:15a7a49f3a6:node3" }

This one which triggers the event of the channel when it happen, is not useful because if the door is not open for a long time no update.

Contact DummyForTrigger "DummyForTrigger" {channel="zwave:device:15a7a49f3a6:node3:sensor_door" }

The second one