Historic Value of an item

I tried to recieve the last historic state of an item frommy database.

here is my code

var local_time_yesterday = LocalDate.now().atStartOfDay().minusMinutes(1)
            logInfo("loggerName", local_time_yesterday.toString())
            logInfo("loggerName", Z_way_number_WallPlug2_totalpower.historicState(local_time_yesterday).state.toString())

last database entry.

021-02-01 23:59:52 60.27

error is

2021-02-03 05:23:33.002 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'energy-1' failed: An error occurred during the script execution: Could not invoke method: org.openhab.core.persistence.extensions.PersistenceExtensions.historicState(org.openhab.core.items.Item,java.time.ZonedDateTime) on instance: null in energy

How do i do this within OH3?

Because of the switch to Java 11, OH3 persistence services use ZonedDateTime now.

I think you can get midnight-1 with

val whatever = now.with(LocalTime.MIDNIGHT.minusMinutes(1))

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