[SOLVED] Restore last value stored in Influxdb on Startup

After reading the forum, I do not know if I am doing well.

I have this rules which work pretty fine, I get values properly.

rule "Gas Counter"
when
Item sonoff06 changed to ON
then
GasHoy.postUpdate((GasHoy.state as Number) + 0.01)
GasTot.postUpdate((GasTot.state as Number) + 0.01)
end

Set to 0 at midnight the counter. It works fine.

rule "Gas Counter Today set to 0"
when Time cron "0 31 12 1/1 * ? *"
then
GasHoy.postUpdate(0.0)
end

Restore values on startup. I do not know if this is well implemented.

rule "RESTART"
when System started
then
GasTot.sendCommand(GasTot.previousState.state)
GasHoy.sendCommand(GasHoy.previousState.state)
end

The thing is that I do not know if on startup the values will be restore properly. I guess I should test them.

My persistence is

   GasTot      : strategy = everyMinute, everyDay, restoreOnStartup
   GasHoy      : strategy = everyMinute, everyDay, restoreOnStartup

How I can get the last value stores in the InfluxdB? on startup or even when I restart the rules or items. I have to initialised the Items with a value, and with NULL everything works wrong.

Thanks.

You might find this thread useful :slight_smile: (linked post and above)

You do not need the “RESTART” thread.
The persistence service will do that by itself with the restoreOnStartup option.

However, InfluxDB is not the best persistence service to restoreOnStartup.

I recommend that you also install the mapDB persistence service and configure it this way:

// mapdb persistence

Strategies {
	default = everyChange
}
Items {
	GasTot, GasHoy : strategy = everyChange, restoreOnStartup
}

Mapdb only stores the last value so the database doesn’t grow in size.
And is very efficient for that purpose:

See:

1 Like

Aha, Now I understand why I got this message. I do not have mapdb installed. I will give it a try.

2018-12-14 12:47:38.710 [WARN ] [nce.extensions.PersistenceExtensions] - There is no queryable persistence service registered with the id 'mapdb'