Hi all
I migrated most of my rules. Particularly in one of the energy calculations, there’s a difference now.
I use the power meter value of the beginning of the year together with the current value and calculate the estimated consumption by the end of the current year.
The database was migrated, so all values are the same. But comparing OH2 with OH3, the calculated values are slightly off.
Here are the conversions I’ve used:
oh2: val day = now.getDayOfWeek
oh3: val day = now.getDayOfWeek.getValue
oh2: val hour = now.getHourOfDay
oh3: val hour = now.getHour
oh2: val currentMonth = now.getMonthOfYear
oh3: val currentMonth = now.getMonthValue
oh2: .historicState(new DateTime(now.getYear,1,1,0,0,0,0)).state as Number
oh3: .historicState(DateTimeType.valueOf(now.getYear+"-01-01").getZonedDateTime).state as Number
oh2: .historicState(now.withTimeAtStartOfDay).state as Number
oh3: .historicState(now.with(LocalTime.of(0,0,0,0))).state as Number
oh2: val beginningOfYearEpoch = now.withDayOfYear(1).withMillisOfDay(0).millis
oh3: val beginningOfYearEpoch = now.withDayOfYear(1).with(LocalTime.of(0,0,0,0)).toInstant.toEpochMilli
oh2: val endOfYearEpoch = now.withMonthOfYear(12).withDayOfMonth(31).withHourOfDay(23).withMinuteOfHour(59).millis
oh3: val endOfYearEpoch = now.withMonth(12).withDayOfMonth(31).withHour(23).withMinute(59).toInstant.toEpochMilli
oh2: now.millis
oh3: now.toInstant.toEpochMilli
My guess is, that beginningOfYearEpoch is wrong, maybe something with timezones? So I end up getting the value of 31.12.2020 23:00 instead of 01.01.2020 00:00.
Can someone spot the difference ?
Thanks a lot