Problem returning a light to a previous state

I’ve been trying to experiment with using RRD4J to return a light to a previous state. I’ve checked this forum and haven’t really found any clear examples I could follow. I have rrd4j set up as my default persistence in the openhab.cfg. Also have the rrd4j.persist file set up in the persistence directory. Here is the persist file and rule.

Strategies {
    everyMinute : "0 * * * * ?"
    everyHour 	: "0 0 * * * ?"
    everyDay	: "0 0 0 * * ?"
    default = everyChange
}
Items {
    // persist everything when the value is updated, just a default, and restore them from database on startup
    * : strategy = everyChange, restoreOnStartup

	// next we define specific strategies of everyHour for anything in the Temperature group, and and every minute     for Humidity
    //Temperature* : strategy = everyHour
    //Humidity* : strategy = everyMinute

    // alternatively you can add specific items here, such as
    //Bedroom_Humidity,JamesInOffice : strategy = everyMinute
}


 rule "Late Night Visitor at Front Door"
    when
           Item FrontDoor changed from CLOSED to OPEN
    then   if(PorchCoachLights == ON) {
	       sendCommand(PorchCoachLights, 60)
	       Thread::sleep(180000)
	       sendCommand(PorchCoachLights, PorchCoachLights.previousState(AbstractInstant, true))
    }           
    end

Do you have more then one persistence binding? I use several so I specify what I am using:

val double previous_meter = Water_Meter.previousState(true, "db4o").state

I do have the my.openHAB persistence too. I can’t seem to get the right format for the line. In Openhab designer its giving me errors.

Just call

PorchCoachLights.previousState()

Or if you want the prvious state that was different call

PorchCoachLights.previousState(true)

I’m getting the following error message: rrd4j does not allow querys without a begin date unless order is descending
and a single value is requested.

Update: Rich, I found people with the same problem on this site back in Nov & Dec '15. You were helping them, but I don’t think anybody got it fixed. They tried erasing their persistence store.

Before you despair, try using the everyMinute strategy for your PorchCoachLights item (and any other you want tyo get the previous state for). I’ve found rrd4j to be finicky when you don’t use every minute even with calls to prevousState or historicState. If that doesn’t work I would guess you are seeing the same problem they are and recommend trying a different persistence like db4o.

Could you walk we through this and tell me what exactly I have to change? I am kinda of lost, this is the first time I played
around with this persistence stuff. I am using rrd4j because I am running my openhab system on a Raspberry PI 2 on a micro sd card and wanted to keep the size down.

I changed my rrd4j.persist file to include a line for PorchCoachLights and changed my rule, but it’s still giving me the same error message. Do I have to do anything in the OpenHAB.cfg file?

Strategies {
everyMinute : "0 * * * * ?"
everyHour 	: "0 0 * * * ?"
everyDay	: "0 0 0 * * ?"
default = everyChange
}
Items {
// persist everything when the value is updated, just a default, and restore them from database on startup
* : strategy = everyChange, restoreOnStartup

// next we define specific strategies of everyHour for anything in the Temperature group, and and every minute for Humidity
//Temperature* : strategy = everyHour
//Humidity* : strategy = everyMinute

// alternatively you can add specific items here, such as
//Bedroom_Humidity,JamesInOffice : strategy = everyMinute
PorchCoachLights : strategy = everyMinute

}

rule "Late Night Visitor at Front Door"
when
       Item FrontDoor changed from CLOSED to OPEN
then   
       if(PorchCoachLights != OFF) {
       sendCommand(PorchCoachLights, 60)
       Thread::sleep(120000)
       PorchCoachLights.previousState(true, "rrd4j").state
       }           
end

Hi Mike,

i´m not 100% sure why you want to use the RRD4J. I would try this:

import java.util.Map
var Map PorchCoachLightsPreviousState = null

rule “Late Night Visitor at Front Door”
when
Item FrontDoor changed from CLOSED to OPEN
then
if(PorchCoachLights != OFF) {
PorchCoachLightsPreviousState = storeStates(PorchCoachLights)
sendCommand(PorchCoachLights, 60)
Thread::sleep(120000)
restoreStates (PorchCoachLights)
}
end

1 Like

Thorhammer,
Thanks for the help. I entered everything into OpenHAB designer and I’m getting an error on the restoreStates (PorchCoachLights) line. It says: incompatible states-Expected Java.util.map<org.openhab.core.items …

ah, sorry my mistake…

it´s not

restoreStates (PorchCoachLights)

it´s

restoreStates (PorchCoachLightsPreviousState)

CU

1 Like

Thanks Thorhammer! That worked. Do you use persistence for anything?

hi,

cool ;-). I’m using persistence for weather data and for restore states at startup only…for now. At the moment i’ ve no other use case.

Cu