Getting Maximum, Minium and Average Values - Persistance jdbc:mysql

OH 3.3 on RaspberryPi

I am trying to display the minimum, maximum and average values for an item that is persisted using jdbc:mysql.

From what I can read the following should work…
logInfo("Test","Maximum Battery Voltage Since 5 years " + BYD_Voltage.maximumSince(

This results in …
Maximum Battery Voltage Since 5 years org.openhab.core.persistence.extensions.PersistenceExtensions$1@f3dbdc

I have tried adding the persistance service …
logInfo("Test","Maximum Battery Voltage Since 5 years " + BYD_Voltage.maximumSince(,"jdbc")
This has the same output.

I also tried
logInfo("Test","Maximum Battery Voltage " + BYD_Voltage.previousState())
This returns …
Maximum Battery Voltage null

Is this even possible with jdbc:mysql ?
What am i getting wrong?

Many thanks

Do you have data that actually goes back five years? Many of the persistence engines have trouble working with times where there is no data.

That implies that perhaps your database doesn’t have any data at all. Have you configured mysql as your default? You are not specifying which persistence engine to use in these calls so it’s going to use the default as configured in MainUI. If you’ve confirmed that MySQL is in fact saving data double check that it’s the default.

Thanks for your help @rlkoshak,

The default persistance is MapDB - so yes, I will have to specify the service (I’m not 100% sure i have the correct format for doing that??).

I have changed the command to

logInfo("Test","Maximum Battery Voltage Since 1 years " + BYD_Voltage.maximumSince(,"jdbc:mysql")
logInfo("Test","Maximum Battery Voltage  " + BYD_Voltage.previousState(),"jdbc:mysql")

to reduce the 5 years of data to 1 year (I do have ,more one year of data in the database).

The output is the same …

2022-07-08 09:48:24.539 [INFO ] [org.openhab.core.model.script.Test  ] - Maximum Battery Voltage Since 1 years org.openhab.core.persistence.extensions.PersistenceExtensions$1@1105db2

2022-07-08 09:48:24.543 [INFO ] [org.openhab.core.model.script.Test  ] - Maximum Battery Voltage  null

The defination for the item is

Number BYD_Voltage		"BYD Battery Voltage [%.2fv]" 								<voltage>	 		(gSQLpersist_every10Min,gBatVolts)

jdbc.persist looks like …

Strategies {
everyMinute : “0 0/1 * 1/1 * ? *”
everyHour : “0 0 * * * ?”
everyDay : “0 0 0 * * ?”
every10Min : “0 0/10 * 1/1 * ? *”
default = everyChange

Items {
gSQLpersist_everyChange*: strategy = everyChange
gSQLpersist_everyMinute*: strategy = everyMinute
gSQLpersist_every10Min*: strategy = every10Min
gSQLpersist_everyHour*: strategy = everyHour
gSQLpersist_everyDay*: strategy = everyDay

Your parens are in the wrong place. The name of the DB is an argument to maximumSince.


Awsome! Thanks @rlkoshk (and “Doh” that I missed that),

	logInfo("Test","Maximum Battery Voltage Since 1 years " + BYD_Voltage.maximumSince(,"jdbc"))

results in

2022-07-08 12:35:46.744 [INFO ] [org.openhab.core.model.script.Test  ] - Maximum Battery Voltage Since 1 years JdbcItem [name=BYD_Voltage, state=56.65999984741211, timestamp=2021-11-28T19:40+10:00[Australia/Brisbane]]

Remember that maximumSince and other persistence calls will return a HistoricState which carries both the state and a timestamp for when that state was saved to the database.