Repository navigation
Count hours and price points from local midnight, not the wall clock - #1309
Merged
Merged
Conversation
On the day DST ends the local hour 02 repeats, and on the day it starts 02 is skipped. Price point and hour of day were taken from the wall clock, so on those days: - the current price point was 4 points (one hour) behind after the change in autumn and ahead in spring, shifting the price shown, the MQTT current price and the hourly cost (#1296) - the repeated hour was never closed: the hour accumulator ran on for two hours and the first one was never checked as a monthly peak (#1299) - today's use/production summed the wrong UTC hours, missing the first hour of a 25 hour day or including one from the day before (#1299) - the ENTSO-E request window for a DST day started an hour late and always covered 24 hours Add LocalDay.h, which gives local midnight and the hours elapsed since it, and use it in PriceService and EnergyAccounting. currentHour now counts elapsed hours, so it reaches 24 on a 25 hour day; on other days it has the same values as before and the realtime data layout is unchanged. The native Timezone stub now applies DST rules like the Arduino Timezone library, and the new native_localday env tests 2026-10-25 and 2027-03-28. Co-Authored-By: Claude Opus 5.5 <[email protected]>
🔧 PR Build ArtifactsVersion: All environments built successfully. Download the zip files:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
On the day DST ends, local 02:00–03:00 happens twice and the day has 25 hours. On the day it starts, 02:00 is skipped and the day has 23 hours. Price point and hour of day were both taken from the wall clock (
tm.Hour), which doesn't count those hours correctly.#1296: prices one hour off on 2026-10-25.
getCurrentPricePointIndex()returned(tm.Hour*60 + tm.Minute) / resolutionin CET. After the change, the wall clock is one hour behind the time elapsed since CET midnight, so the cursor was 4 points (1 hour) short. The reporter'scursor: 56at about 14:00 CET should have been 60. The UI starts the price plot at the cursor, so every price showed one hour late. The same index is used forgetCurrentPrice()(MQTT current price, hourly cost), andgetPriceForRelativeHour()had the same flaw. On the spring day it would run 4 points ahead instead. #1297 only fixed the day and month plot labels in the UI, not this.#1299: hour accounting at fall-back.
EnergyAccounting::update()started a new hour only whenlocal.Hourchanged. Going from 02 to 02 isn't a change, souse/costHourran on for two hours (26.44 kWh in the report), and the first 02 hour was never passed toupdateMax(), so it was never checked as a monthly peak.getUseToday()/getProducedToday()/calcDayCost()found each hour of the day withnow - (local.Hour - i)*3600. That assumeslocal.Hourhours have passed today, so a 25-hour day lost its first hour, and a 23-hour day would include 23:00Z from the day before.ENTSO-E fetch window.
fetchPrices()computed local midnight ast - tm.Hour*3600 - …and the end as+ SECS_PER_DAY. Fetching tomorrow's prices on 2026-10-24 requested 25 October from 23:00Z (should be 22:00Z) and always asked for 24 hours. This only affects devices that use their own ENTSO-E token.Changes
src/LocalDay.h(new, header-only):localMidnightUtc(),nextLocalMidnightUtc()andhoursSinceLocalMidnight(), all based on elapsed time from local midnight.PriceService: current price point index,getPriceForRelativeHour()and the ENTSO-EperiodStart/periodEndnow use these helpers.getPricePoint()/getFixedPrice()already measured from midnight in elapsed time, so they are unchanged.EnergyAccounting:currentHournow counts hours since local midnight, so it reaches 24 on a 25-hour day. Hour rollover, the day totals andcalcDayCost()all use it.EnergyAccountingRealtimeDatais unchanged, so data kept over a reboot or upgrade stays valid.test/stubs/Timezone.h: now applies DST rules the same way the Arduino Timezone library does. Without DST rules it behaves exactly as before; the decoder tests only probe mid-January.native_localdayenv (test/test_local_day/), added to both CI workflows and toCLAUDE.md.Verification
pio test -e native_localday: 9 tests on 2026-10-25 (25 h) and 2027-03-28 (23 h), for CET and EET:pio test -e native,native_configandnative_watchdogall pass. The decoder golden master is unchanged.pio runfor esp8266 (98.5% flash), esp32s2 and esp32: all build.PriceServiceandEnergyAccountingcan't run on native. The call sites were checked by review. Real confirmation comes with the next change on 2027-03-28.Refs #1296, #1299
🤖 Generated with Claude Code