[SOLVED] How to check if state changed in the last day

I have a number of battery driven sensors where I have noted, that even if they monitor battery% - at some point they tend to die without a fair warning (i.e. battery less than 30%).

I have an “alive” datetime-stamping of all recieved data from the sensors like this;

rule "maindoor doorsensor alive"
		Item maindoor_Sensor received update or
		Item maindoor_PowerAlarm received update or
		Item maindoor_TamperAlarm received update or
		Item maindoor_Temperature received update or
		Item maindoor_Battery received update
		postUpdate(maindoor_LastAlive, new DateTimeType())

I would like to make a daily cron-job to verify that the (in the case above) maindoor_LastAlive was updated within the last 24 hours. This way I could set up an action to warn me through twitter, mail etc. - that one of the sensors went “offline”.

Any good tips how to do that in a rule ? (tried searching, but came out empty)

If you try that DP and run into trouble let me know. It is one that needs a major rewrite.

As I am using persistance, I decided to go for this:

rule "Check sensor alives"
   		Time cron "0 0 0/6 1/1 * ? *" 		// Every 6 hours (generated with http://www.cronmaker.com/ 
		logInfo("SENSOR", "Start sensor 24h alive checks")

		var DateTime dateTime
		var SimpleDateFormat df = new SimpleDateFormat( "YYYY-MM-dd HH:mm:ss" )
		var String Timestamp = df.format( new Date() )
		dateTime = new DateTime((maindoor_LastAlive.state as DateTimeType).calendar.timeInMillis)
		if (dateTime.plusMinutes(1440).isBefore(now)) {    // Check if alive message was received within the last 24 hours
//			... do something

This seems to work fine for my purpose. Could perhaps be done more elegantly…?

Switch maindoor_Timer (Doortimers) { expire="24h,command=OFF" }
Group:Switch gMainDoor

Switch maindoor_Sensor (gMainDoor) ...
Switch maindoor_PowerAlarm (gMainDoor) ...
rule "maindoor doorsensor alive"
    Member of gMainDoor received update
    maindoor_LastAlive.postUpdate(new DateTimeType())

rule "Door sensor has not reported in 24 hours"
    Item maindoor_Timer received command OFF
    //do something

With some clever naming you can make the above Rule work for all of your sensors. See the link from Vincent for details.