Hi all,
at the moment I am getting a bit lost with the new OH3 DateTime conversion and I have no clue how I need to solve this. Hope someone sees my mistake.
which worked totally fine. With the new OH3 I am forced to change this to joda time zonedDateTime, but I have no clue how this works. I have read many examples but all request a datetime input, which I do not have I think.
As latest I tried the following:
val joda_LastOpen = new DateTime((PowerMeter_Meter3_totalkWh.lastUpdate as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
You can calculate a Duration from the ZDTs like this:
val start = new DateTime((PowerMeter_Meter3_totalkWh.lastUpdate as DateTimeType).zonedDateTime
val end = PowerMeter_Meter3_totalkWh.previousState(true,"influxdb").timestamp
if (Duration.between(start, end).toMillis() > 0) {
consumption3 = actualconsumption3 - previousconsumption3
} else {
consumption3 = 0
}
You probably also need to add an import for the Duration:
Thank you @tsmit for your quick and concrete help. My rules work again.
I have read the date time conversion manual for OH3 but it was difficult to understand. If this is the only way in OH3 to analyze, if a switch is short or long pressed, than OH3 is not easy for end users - at least for time based rules.