Persist state with own timestamp

  • Platform information:
    • Hardware: Intel
    • OS: Debian
    • Java Runtime Environment: openjdk version “17.0.11” 2024-04-16
      OpenJDK Runtime Environment (build 17.0.11+9-Debian-1deb11u1)
      OpenJDK 64-Bit Server VM (build 17.0.11+9-Debian-1deb11u1, mixed mode, sharing)
    • openHAB version:4.1.3
    • Persistence: jdbc-mariadb

I would like to persist a state with a certain timestamp as mentioned here: Docs - Persistence

<item>.persist(ZonedDateTime, State) - Persists a past or future state for the Item

.items:

Number:Currency             TotalCosts_per_Day
Number:Currency             LiveAccumulatedCost

.rules:

rule "Test"
when
    Time cron "0 0/1 * * ? *" // Debug
then
    val ZonedDateTime timestamp = now().minusDays(1).withHour(23).withMinute(59).withSecond(59)
    TotalCosts_per_Day.persist(timestamp, LiveAccumulatedCost.state)
end

This gives me the following Error:

Could not invoke method: org.openhab.core.persistence.extensions.PersistenceExtensions.persist(org.openhab.core.items.Item,java.lang.String) on instance: null

What am I doing wrong?

That feature was added in openHAB 4.2. Return units in persistence extension commands and support future persisted states by mherwege · Pull Request #3736 · openhab/openhab-core · GitHub

You should look at the docs that matches your openHAB version:
https://v41.openhab.org/docs/configuration/persistence.html

Thanks a lot!