Persistence triggering rules on restore

Hi,

Is there anyway I can stop a rule from triggering when an items state is restored by persistence on startup.

Basically I have some switches i use for presence along with an a datetime item to track when the person left the house. The problem is that when it restores, it sets the switch to OFF triggering the rule to update the time the person left.

items

Group:Switch:OR(ON, OFF)	P_gPresence			"Presence"		<present>
Switch						P_Chris				"Chris"			<boy_1>		(P_gPresence)	{autoupdate="false"}
Switch						P_Chris_Mobile
DateTime					P_Chris_Away		"Away [%1$td/%1$tm %1$tH:%1$tM]"	<clock>

rule

rule "Chris Presence Changed"
when
    Item P_Chris_Mobile changed
then
    if(P_Chris_Mobile.state == ON)
	{
		if(PresenceTimerChris!=null)
		{
			PresenceTimerChris.cancel
            PresenceTimerChris = null
        }
        
        postUpdate(P_Chris, ON)
    }
        
    if(P_Chris_Mobile.state == OFF)
    {
    	if(PresenceTimerChris == null || PresenceTimerChris.hasTerminated)
    	{
	        PresenceTimerChris = createTimer(now.plusMinutes(5))
		        [|
		        	postUpdate(P_Chris, OFF)
		        	postUpdate(P_Chris_Away, new DateTimeType())
		        	PresenceTimerChris = null
		        ]
	    }
	    else
	    {
	        PresenceTimerChris.reschedule(now.plusMinutes(5))
	    }
    }
end

Many thanks
Chris

Hey,
maybe you should change the trigger to:

Item P_Chris_Mobile changed from ON to OFF or
Item P_Chris_Mobile changed from OFF to ON

Greetings,
Fabian

1 Like

Good call, i didn’t think of that. Thank you.