Rule not being executed

Hello,

After couple months of putting my Openhab project on hold, I am starting again. I bought couple of smart switches and also motion sensor. I can control them, all good.

Now I am trying to create a very basic rule. If motion detected in Kitchen, turn on light. But for whatever reason, OH does not seem to even try to execute the rule, looks like it is not triggered. But according to the logs, the motion is detected.

Here are the rule and logs:

Rule “Motion Detected”
when
Item Kitchen_Motion changed from OFF to ON
then
logInfo(“Motion Detected in Kitchen”)
Kitchen_Ceiling_Dimmer.sendCommand(ON)
end

2019-10-31 21:32:05.874 [vent.ItemStateChangedEvent] - zwave_serial_zstick_d5988ecb_serial_sof changed from 429 to 430

2019-10-31 21:32:05.902 [vent.ItemStateChangedEvent] - Kitchen_Temperature changed from 69 to 68.7

2019-10-31 21:32:06.031 [vent.ItemStateChangedEvent] - zwave_serial_zstick_d5988ecb_serial_sof changed from 430 to 431

2019-10-31 21:32:06.841 [vent.ItemStateChangedEvent] - zwave_serial_zstick_d5988ecb_serial_sof changed from 431 to 432

2019-10-31 21:32:06.906 [vent.ItemStateChangedEvent] - zwave_serial_zstick_d5988ecb_serial_sof changed from 432 to 433

2019-10-31 21:32:07.029 [vent.ItemStateChangedEvent] - zwave_serial_zstick_d5988ecb_serial_sof changed from 433 to 434

2019-10-31 21:32:07.064 [vent.ItemStateChangedEvent] - zwave_serial_zstick_d5988ecb_serial_sof changed from 434 to 435

2019-10-31 21:32:10.824 [vent.ItemStateChangedEvent] - zwave_serial_zstick_d5988ecb_serial_sof changed from 435 to 436

2019-10-31 21:32:11.144 [vent.ItemStateChangedEvent] - zwave_serial_zstick_d5988ecb_serial_sof changed from 436 to 437

2019-10-31 21:32:11.155 [vent.ItemStateChangedEvent] - Kitchen_Motion changed from OFF to ON

Any idea on what am I doing wrong?

Check in openhab.log for “rules loaded” message after your rule file editing.

What type of Item is this, switch or string?

logInfo needs two parameters try:

logInfo("Motion", “Motion Detected in Kitchen”)

1 Like

Hello Rossko,

It is a switch:

Switch Kitchen_Motion “Kitchen Motion Sensor” (gHome, gFirstFloor) {channel=“zwave:device:d5988ecb:node11:alarm_motion”}

Hello Alexia,
I thought what I had was good, but I tried yours, in vain.
I added this logInfo so I could check if the rule was executed, I was thinking that maybe my command was not sent.
Still no luck, it does not seem to execute or go through the rule.

So this seems the first thing to check now…just go back to the basics…do you see the quoted above in the log after editing the rule file? Is the rule file named correctly (.rules) ? Are owner and permissions set for the openhab user?

Rule “Motion Detected”
when
Item Kitchen_Motion changed from OFF to ON
then
logInfo(“Motion Detected in Kitchen”)
Kitchen_Ceiling_Dimmer.sendCommand(ON)
end

Try this rule instead, if it works then we can explain why afterwards.

Rule “Motion Detected”
when
Item Kitchen_Motion changed
then
logInfo(“Kitchen Motion Sensor Status: {}”, Kitchen_Motion.state)
if(Kitchen_Motion.state == ON) {
	Kitchen_Ceiling_Dimmer.SendCommand(100)
}
end

still nothing, it does not seem to go into the rule

2019-11-01 09:06:25.385 [vent.ItemStateChangedEvent] - Kitchen_Motion changed from ON to OFF

2019-11-01 09:28:17.467 [vent.ItemStateChangedEvent] - zwave_serial_zstick_d5988ecb_serial_sof changed from 993 to 994

2019-11-01 09:28:17.806 [vent.ItemStateChangedEvent] - zwave_serial_zstick_d5988ecb_serial_sof changed from 994 to 995

2019-11-01 09:28:17.820 [vent.ItemStateChangedEvent] - Kitchen_Motion changed from OFF to ON

2019-11-01 09:28:46.652 [vent.ItemStateChangedEvent] - zwave_serial_zstick_d5988ecb_serial_sof changed from 995 to 996

2019-11-01 09:28:47.003 [vent.ItemStateChangedEvent] - zwave_serial_zstick_d5988ecb_serial_sof changed from 996 to 997

2019-11-01 09:28:47.017 [vent.ItemStateChangedEvent] - Kitchen_Motion changed from ON to OFF

The logInfo() in the suggested rule is still faulty.

Whats in your openhab.log file?

I’ve also spotted a syntax error from me.

Change

Kitchen_Ceiling_Dimmer.SendCommand(100)

To

Kitchen_Ceiling_Dimmer.sendCommand(100)

openhab.logs do not have much other than
2019-11-01 08:19:53.419 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘Kitchen.rules’
2019-11-01 08:19:53.424 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘Kitchen.rules’ is either empty or cannot be parsed correctly!
2019-11-01 08:19:53.538 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘Kitchen.rules’
2019-11-01 08:19:53.544 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘Kitchen.rules’ is either empty or cannot be parsed correctly!
2019-11-01 08:19:54.616 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘Kitchen.rules’
2019-11-01 08:19:54.639 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘Kitchen.rules’ is either empty or cannot be parsed correctly!
2019-11-01 08:54:37.814 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘Kitchen.rules’
2019-11-01 08:54:37.820 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘Kitchen.rules’ is either empty or cannot be parsed correctly!
2019-11-01 08:54:37.948 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘Kitchen.rules’
2019-11-01 08:54:37.954 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘Kitchen.rules’ is either empty or cannot be parsed correctly!
2019-11-01 08:54:39.019 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘Kitchen.rules’
2019-11-01 08:54:39.036 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘Kitchen.rules’ is either empty or cannot be parsed correctly!

But based on another thread I saw, I should not worry about that

Why wouldn’t you worry? It is telling you that it is ignoring your rule because it has errors. So, it will not run.

In the event logs, I have the following:
2019-11-01 09:57:04.449 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘Kitchen.rules’

2019-11-01 09:57:04.455 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘Kitchen.rules’ is either empty or cannot be parsed correctly!

2019-11-01 09:57:04.592 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘Kitchen.rules’

2019-11-01 09:57:04.597 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘Kitchen.rules’ is either empty or cannot be parsed correctly!

2019-11-01 09:57:05.686 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘Kitchen.rules’

2019-11-01 09:57:05.710 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘Kitchen.rules’ is either empty or cannot be parsed correctly!

And I was reading this: Configuration model 'somefile.rules' is either empty or cannot be parsed correctly!

But maybe I should investigate further on that then

I don’t know that it matters, but this should be “rule”. Most things in Rules DSL are case sensitive.

This requires two arguments, a name for the logger and the log statement.

logInfo("Motion Detected", "Motion Detected in Kitchen”)

Is the Item for sure changing from OFF to ON? The Rule only triggers on a change of the Item’s state. If the Item doesn’t go back to OFF the Rule will never trigger.

That thread only applies when you see that WARN followed by another Loading model statement. When editing on a samba share, there are two events when you save a file, one before the file is about to be saved and one when it is done saving the file. OH picks up both events and when it tries to read the file from the first event, the file is empty. But then OH can successfully read the file on the second event.

You don’t have that second event showing the file is loaded so there is definitely something syntactically wrong about your file.

You should use VSCode with the openHAB Extension which will highlight errors as you type.

At this point the biggest candidate is probably the upper case on “Rule” which should be lower case “rule”.

OMG!!! you nailed it!!! I feel stupid too :smiley: It was the capital letter on the “rule”

Now the rule is being executed

2019-11-01 18:14:04.818 [vent.ItemStateChangedEvent] - Kitchen_Motion changed from OFF to ON

2019-11-01 18:14:04.992 [ome.event.ItemCommandEvent] - Item ‘Kitchen_Ceiling_Dimmer’ received command 100

2019-11-01 18:14:05.017 [nt.ItemStatePredictedEvent] - Kitchen_Ceiling_Dimmer predicted to become 100

2019-11-01 18:14:05.039 [vent.ItemStateChangedEvent] - Kitchen_Ceiling_Dimmer changed from 89 to 100

Thank you so much!!!