Hi,
I have been playing with the persistence (RRD4J) I would like to log the time that a switch is turned on for. I have a .perisist file with the following:
If I remember right, you can’t do this with rr4d. This persistent type is just capable to persist number items. String or DateTime items will have to made persistent via another persistent type.
In case of the DateTime items, this kind of surprising to me as these types are also kind of numbers (number of milliseconds)
This is true you can not log things that are not number values in rrd4j.
Furthermore you can not plot stuff that has not been logged at the minute interval.
So you can convert the logical state to numbers (true is 1 and false is 0) in a number item using a rule. But then you still have to log at a minute interval to be able to plot.
The way rrd4j logs is (as I read the documentation) that it takes all the values that are posted to it in that minute interval an averages them before storing the averaged value.
So say you have a sensor (fx a movement sensor) you want to log the activity using a number an have set up the rules and the logging them you would be logging a signal that is a number equal to the fraction of “on time” per minute.
What is in my humble opinion missing from openhab is an event based rrd type database that simply logs every change and allows for plotting but has the benefit of easy setup of rrd4j (this is however beyond my programming skill level although I have contemplated it many times)
That being said it is very hard to produce nice plots of something that only has two states. I have created a python script that would scan the event log file of openhab for a week and allow the user to select what is plotted. Very rarely did it yield something “nice”
But I think of we want to be able to search for patterns in behaviour them we have to be able to do event based logging that is easy to set up. And be able to log logical items without setting up rules and number items for each logged item.
OK enough of a rant from me I hope it helped just a little bit.
rule "Switch time ascending"
when
Time cron "0 * * * * ?"
then
if( DemoSwitch.state == ON ) {
var DateTime m = new DateTime(DemoSwitch.lastUpdate )
var diff = now.millis - m.millis;
DemoSwitch_On_Asc.postUpdate( diff );
logInfo("Track Ascending Duration", "demoSwitch changed last after " + diff )
}
else {
DemoSwitch_On_Asc.postUpdate( 0 );
}
end
rule "Switch On time total"
when
Item DemoSwitch received command
then
if( receivedCommand==OFF ) {
var DateTime m = new DateTime(DemoSwitch.lastUpdate )
var diff = now.millis - m.millis;
DemoSwitch_On_Duration.postUpdate( diff );
logInfo("Track On Duration", "demoSwitch on duration was " + diff )
}
else {
logInfo("Track On Duration", "demoSwitch is now on " )
}
end
The “DemoSwitch_On_As” number will lead to an ascending graph, the longer a switch stays on, starting/hovering over zero when the switch is off. The DemoSwitch_On_Duration will track the duration a switch was on.