Daily item saved once per day but persistance after restart

I have a item which I’m accumulating during the day , and I write this to my JDBC database once every midnight, which works fine mostly… except when I have to restart OpenHab.
how do only write once per day but restore current value at startup?

// daily energy reset note persistant writes just before midnight
rules.when().cron("0 0 0 * * ?").then(event => {	
	console.log("Energy JS Daily: " + Energy_Mains_Daily.state )
}).build("Energy Consumption daily", "update energy usage today");

You don’t, at least not using just the one Item or just the one database.

You either need to have a separate Item which you save on every change with restoreOnStartup and then a rule that runs at midnight to update the other Item with the day’s total or you need to use an alternative database on that Item (e.g. MapDB) which saves the value on everyChange with restoreOnStartup and the JDBC persistence configured to only save the value of that Item at midnight.