Help me wrap my head around persistence's cron format

So my goal is to change my default persistence strategy from every change to every change, or every five minutes if nothing has changed.

Looked at the wiki ( https://github.com/openhab/openhab/wiki/Persistence ), and the cron format it references ( http://www.quartz-scheduler.org/documentation/quartz-2.1.x/tutorials/crontrigger ), but am not really making headway.

My proposed mysql.persistence file looks like this:

Strategies {
    every5 : "* 0/5 * * * ? *"    

    default = everyChange,every5,restoreOnStartup 
}

Items {
    * : strategy = every5,everyChange,restoreOnStartup
}

But when I put that in, instead of logging every five minutes, persistence stores a value for everything every second!

…so what am I doing wrong here? Seems so simple yet I’m so far from the intended result!

Thanks in advance!

Instead of

every5 : "* 0/5 * * * ? *"

try

every5 : "* 0/5 * * * ?"

OH cron consists of only 6 parameters …

Thanks, but no effect; still logging persistence data every second for every device.

Actually, hang on. Further inspection reveals this isn’t logging persistence data for every device, but only some. I think this may be another manifestation of bug #4046.

SO… I think this should be tabled until that bug is fixed, then revisited if still happening. Thanks anyway!

did you try that one:

“0 0/5 * * * ?”

i think that “* 0/5 * * * ?” will trigger every second of 5 minutes. so 60 time when it reach 5 minutes. nothing for minute 1-2-3-4.

1 Like

@samverner777 postet the right cron expression! :grinning:

Well, progress, sort-of. samverner777 was right on the money; replacing the first * with a zero solved the problem of logging every second. So my mysql.persistence is now:

Strategies {
    every5 : "0 0/5 * * * ?"    
    default = everyChange,every5,restoreOnStartup 
}

Items {
    * : strategy = everyChange,every5,restoreOnStartup
}

The problem I’m having now is that persistence is not being consistent. Some things (mainly things that normally throw reports all the time, such as my Home Energy Monitors) are storing state every time they change or five minutes, whichever is shorter.

But things that haven’t changed state or thrown a report (such as light switches) aren’t getting any persistence updates at all. The intent is for every five minutes to write “yup, that switch is still off” into persistence, but that’s not happening. Them not getting any entries at all baffles me; shouldn’t they be falling under “default” or the * rule, and as such log every5+everychange?

Turns out the problem isn’t my persistence config, but that habmin (1) isn’t showing me all the persistence values. If I go and query the mysql database outside of openhab, I see persistence entries for individual items every five minutes (or more often if they change on their own), as intended and expected.

Sorry for the fire drill folks, and thanks again to @samverner777!