[SOLVED] Rule stopped working on sat after i rebooted everything

I have had the same motion sensor rule in place for 8 or 9 months now. Saturday I had an issue with my esxi host and had to reboot everything.

have been having an issue with this rule. For some odd reason it’s ignoring my condition
if(numOn > 0)

seems like once it hits there, even though numOn = 0 it still goes right in. The Override doesn’t work either, it just turns them on off. So even when it shouldn’t (middle of the night) it still turns on. Not sure what happened. Anyone see anything glaring?

rule "Bedroom Motion Sensor"
        Item BedroomMotionSensor changed
        var Number hour = now.getHourOfDay
        var triggeredTime = BedroomMotionSensor.lastUpdate()
        var LightLevel = MasterBedRoomLightLevel.state as DecimalType
        if(MasterBedroom_MotionSensorOverride.state == ON)
           override = true
           logError("Bedroom","Override is ACTIVE!")
           override = false
           logError("Bedroom","No Override")
                //****************** IGNORES THIS *************
                var Number numOn = gLivingRoomLights.members.filter(s | s.state == ON).size
                // check to see if any lights are on in the living room.
                logError("Bedroom","Bedroom Count"+numOn.toString)
                // the above line writes "Bedroom Count0" to the log, so it's reporting 0
                if(numOn > 0)
                        //check for override
                                //living room lights are still on
                        if((BedroomMotionSensor.state==ON) && ( LightLevel > 69))
                                        logError("Bedroom","Bedroom Motion Detected - ON")

                                        logError("Bedroom","No Motion, turn the lights off")


The first thing to check when problems occur after a reboot is to make sure all the Items the Rule depends upon have a not NULL state, or your Rule manages that case. When Items are first loaded, unless you are using restoreOnStartup, the Items get initialized to NULL.

Are you sure you are interpreting your logs correctly? The Rule is getting the numOn from gLivingRoomLights but your logError says “Bedroom Count”. Seems like a disconnect there. Is the Group wrong or is the log wrong?

So it’s supposed to check the livingroom lights. I just have the text wrong for the logs. My persistence is mysql, restoreonstartup. So I haven’t seen any nulls. But I will add some additional logging to show the state of the other things i am checking against to make sure. It’s just weird if that numOn is 0 it should skip all the rest of the if statement.

and the log shows it’s 0. SO it’s almost like my comparison is wrong and numOn isn’t actually 0.

Is this Rule running more than once close together? Maybe it is skipping the if on one run then hitting it really close thereafter.

It seems unlikely that the > has suddenly become broken so there must be something about the way the Rule is running where numOn is indeed > 0 at some point.

What happens if you use:

if(gLivingRoomLights.members.filter[ s | s.state == ON ].size > 0)

Ok. I have added in another logging piece.

I had the living room lights on and covered up the light sensor so it would simulate night time with the living room lights on.

Livingroom Light Count: 2 MotionSensor State: ON Light Level: 69

None of my item values i am checking against are NULL so that’s good. Lights turned on as expected. I turned off the living room lights. Triggered motionsensor.

Livingroom Light Count: 0 MotionSensor State: ON Light Level: 74

hmmmm. ok lights still turned on. numOn = 0
this line should have skipped it

if(numOn > 0)

Now to try changing that count logic. Hmmmm. Lights still turned on. I don’t see the rules running more than once as the log doesn’t show my log messages doubling up or anything.

I am going to try with the Override switch. Nope, that didn’t change anything either…

However. I did just see something that is strange. Now im REALLY confused.

2018-08-23 17:57:18.308 [vent.ItemStateChangedEvent] - BedroomMotionSensor changed from OFF to ON
2018-08-23 17:57:18.581 [vent.ItemStateChangedEvent] - BedroomMotionSensor_LastUpdate changed from 2018-08-23T17:41:32.599-0400 to 2018-08-23T17:57:18.577-0400

==> /var/log/openhab2/openhab.log <==
2018-08-23 17:57:18.582 [INFO ] [lipse.smarthome.model.script.Bedroom] - Last Triggered 2018-08-23T17:57:18.000-04:00
2018-08-23 17:57:18.585 [ERROR] [lipse.smarthome.model.script.Bedroom] - No Override
2018-08-23 17:57:18.587 [ERROR] [lipse.smarthome.model.script.Bedroom] - Livingroom Light Count: 2 MotionSensor State: ON Light Level: 74
2018-08-23 17:57:18.590 [ERROR] [lipse.smarthome.model.script.Bedroom] - Bedroom Motion Detected - ON

==> /var/log/openhab2/events.log <==
2018-08-23 17:57:18.590 [ome.event.ItemCommandEvent] - Item 'BedRoomLightLeft' received command ON
2018-08-23 17:57:18.592 [ome.event.ItemCommandEvent] - Item 'BedRoomLightRight' received command ON

==> /var/log/openhab2/openhab.log <==
2018-08-23 17:57:18.593 [DEBUG] [inding.mqtt.internal.MqttItemBinding] - Publishing command ON to mygateway1-in/25/1/1/0/2
2018-08-23 17:57:18.593 [DEBUG] [inding.mqtt.internal.MqttItemBinding] - Publishing command ON to mygateway1-in/25/2/1/0/2

==> /var/log/openhab2/events.log <==
2018-08-23 17:57:18.596 [vent.ItemStateChangedEvent] - BedRoomLightLeft changed from OFF to ON
2018-08-23 17:57:18.597 [GroupItemStateChangedEvent] - gBedroomLights changed from OFF to ON through BedRoomLightLeft
2018-08-23 17:57:18.597 [vent.ItemStateChangedEvent] - BedRoomLightRight changed from OFF to ON

ok, that shows that when it is supposed to turn on that it publishes the command to mqtt to turn on. Then you can see the item state change.

However, here is the log from when it’s NOT supposed to turn on but still does.

2018-08-23 18:14:38.915 [vent.ItemStateChangedEvent] - BedroomMotionSensor changed from OFF to ON
2018-08-23 18:14:38.917 [vent.ItemStateChangedEvent] - BedroomMotionSensor_LastUpdate changed from 2018-08-23T18:10:33.284-0400 to 2018-08-23T18:14:38.912-0400

==> /var/log/openhab2/openhab.log <==
2018-08-23 18:14:38.919 [INFO ] [lipse.smarthome.model.script.Bedroom] - Last Triggered 2018-08-23T18:14:38.000-04:00

2018-08-23 18:14:38.923 [ERROR] [lipse.smarthome.model.script.Bedroom] - Override is ACTIVE!
2018-08-23 18:14:38.925 [ERROR] [lipse.smarthome.model.script.Bedroom] - Livingroom Light Count: 0 MotionSensor State: ON Light Level: 74

There is no publish to mqtt saying to turn on… but they still turn on… almost like my motion sensor and my relays have some how bound together and ignore what openhab says all together…

ugggg my head.

So it’s quite possible openhab is following the rule at this point. but something else isn’t. which is REALLY odd since my mqtt node doesn’t show anything telling it to turn on either.

Now im just plain lost.

Thanks for the help anyway Rich :slight_smile:

Ok. so it’s getting weirder.

Openhab is sending the messages. Not sure how, but it is. I setup monitoring just on the mqtt nodes in question and even though openhab doesn’t show anything in the events log when it’s doing it. It is infact sending something to mqtt.

Soo, is there a chance since my openhab system was hard shut down (not gracefully) that there is something cached? I know there is cache somewhere and temp files, is there something i can look for or clear?


I found it!!! and… im an idiot.

Ok. just so no one thinks there is gremlin that’s gonna run amuck in your house. My specific issue, as you saw in the very first post was that my esxi environment went offline and I had to reboot everything…


one of those things that got rebooted (but should not have) was my old vm that was running openhab 1.8. It had roughly the same rule. except it had a slightly older rule with different conditions.

Im an idiot.

Those errors are the hardest to find and we have all been there. Glad you figured it out.

1 Like

thanks for trying to help me :slight_smile:

Time to get rid of that old vm. Keep your old code just in case. It always happens when you want to implement some code and remember that you did it years before.

definitely. I think this weekend i will smoke test and full power it down and not just have openhab stopped to see if anything else is out there I need.