Get historic state with Mariadb

Hello there,
how i get the historic state with Mariadb?
in OH2 i did it like this:

Gmc_holz_verbrauch_2019.sendCommand(Gmc_holz_verbrauch.historicState(parse("2019-06-30")).state.toString)

but in OH3 no function
How I have to change this code?

Thank you very much.

There are lots of ways to do this. First of all, pretty much all of your date time questions can be answered at ZonedDateTime (Java SE 11 & JDK 11 ).

If you don’t want to mess with the timezone stuff the easiest is probably:

now.withYear(2019).withMonth(6).withDayOfMonth(30).withHour(0).withMinute(0).withSecond(0)

Unfortunately I don’t think ZonedDateTime will support something like

ZonedDateTime.parse("2019-06-30") 

but you can try it.

With this: `

ZonedDateTime.parse("2019-06-30") 

I got this

Script execution of rule with UID 'system-1' failed: Text '2019-06-30' could not be parsed at index 10 in system

With this

now.withYear(2019).withMonth(6).withDayOfMonth(30).withHour(0).withMinute(0).withSecond(0)

I got this:

2021-02-25 07:27:36.611 [WARN ] [nce.extensions.PersistenceExtensions] - There is no queryable persistence service registered with the id 'mariadb'

2021-02-25 07:27:36.613 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'system-1' failed: cannot invoke method public abstract org.openhab.core.types.State org.openhab.core.persistence.HistoricItem.getState() on null in system

That warn tells that mariadb is not known to the REST API. If you have installed I’d try to uninstall and install again.

I have done it. And I have made the config new: But no solution. The state of the items goes into the DB.
I don’t get the historic state.

Are you using jdbc service?

Yes

Well, the message is plain enough.
I guess your default persistence service is set to ‘mariadb’, perhaps an inheritance of upgrade from OH2?
You can correct that, or override it in your rule
...historicState( (time stuff), "jdbc") ...

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.