Rule assistance- Door open

I’m running OH2 on my RPi3. I have a few Ecolink Intelligent Technology z-wave door sensors.

I have a rule that checks to see if the patio door ‘last tripped’ changed and then sends me a notification.

rule "Side Patio Door Opened"
when
 	Item SidePatioLastUpdate received update
 	
 then
	
	logInfo("Side patio open", SidePatioStatus.state.toString)	
	pushover("Side patio Door activity")
	
end

My issue with the rule is that when the Pi restarts, the rule will trigger even when the door hasn’t opened in several days because it updates the ‘last tripped’ from NULL upon reboot:

LOG:

2018-09-24 08:33:55.932 [vent.ItemStateChangedEvent] - SouthPatioDoorLastTrip changed from NULL to 2018-09-22T13:27:32.000-0400

Is there a way to eliminate the false positive notifications with a better rule?

Try using: Item SidePatioLastUpdate changed to OPEN (or whatever the value it reports)

One option I could think of is to only perform the notification when the previousState is not NULL:

rule "Side Patio Door Opened"
when
 	Item SidePatioLastUpdate received update
 	
 then
	
	logInfo("Side patio open", SidePatioStatus.state.toString)
	
	if(SidePatioLastUpdate.previousState.state !== NULL){
		pushover("Side patio Door activity")	
	}
	
end
3 Likes

I get this error now, but at least I’m not getting notified on the reboot!

2018-09-24 08:59:52.593 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Side Patio Door Opened': cannot invoke method public abstract org.eclipse.smarthome.core.types.State org.eclipse.smarthome.core.persistence.HistoricItem.getState() on null

Does this error happen only during reboot? If so, it’s a known bug that occurs when Rules start running before all the Items are loaded.

No, I get the same error when I open the door now (and I don’t get the push notification).

Try with

if(SidePatioLastUpdate.state != NULL){ pushover(“Side patio Door activity”) }

Uh, not able to test now, so just guessing here. Maybe you can try without .state:

if(SidePatioLastUpdate.previousState!== NULL){
		pushover("Side patio Door activity")	
	}

Edit: idea behind this, is that the entire .previousState property might be NULL, but at this point I am not sure whether that works.

YAY! Thank you all for your help! I got it to work correctly by using below:

rule "Side Patio Door Opened"
when
 	Item SidePatioStatus changed to OPEN
 	
 then
	
	logInfo("Side patio open", SidePatioStatus.state.toString)
	pushover("Side patio Door OPEN")	
			
end

I don’t get the notifications on the reboot and I do get the notifications when I open the door!

NULL is typically not saved to the database so I don’t think this approach would work because previousState will always not be NULL.

Do you have persistence set up on this Item? If not previousState will return null, not be confused with NULL.

previousState returns a HistoricItem so the .state is required.