Repository navigation
Conversation
minute_data decided whether a drop in an incrementing sensor was the daily reset by the record's own clock, which Home Assistant stamps in UTC. Ahead of UTC (CET: local midnight = 23:00 UTC) a reset from below 1 kWh then looked like a small dip and was flattened to the previous day's total, so the new day's readings counted only once they passed it, and the flattened value carried on into the next day. A daily export counter lost 0.67 kWh of an evening export this way. Judge "near midnight" on the local clock of `now` instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
springfall2008
left a comment
There was a problem hiding this comment.
Automated comment from the triage bot.
Verdict: 🟡 Amber - Recommend addressing the feedback, then approval
One sub-test is ineffective; the fix itself is correct. Reviewed at head ed237ce (1 inline finding, 0 in the body).
The change is the right root-cause fix: HA stamps history in UTC, a daily counter resets at local midnight, and near_midnight is now judged on now's own zone (now.tzinfo, which update_time() sets to local_tz). This is exactly the "zone-aware midnight window in minute_data" item that issue #6083 has been waiting on, and it agrees with gecloud's EMS near-midnight check, which already uses local now_utc_exact. last_updated_time always comes from str2time(), so it is tz-aware and astimezone() cannot raise; the naive-now path falls back to the old behaviour as the description says. Sub-test 1 is genuinely red without the change; sub-test 3 is not (see the inline note).
… more zones Review follow-up: - A drop counts as a reset near midnight on the local clock or on UTC, so a counter that resets on UTC midnight (an inverter clock without DST, e.g. UK summer time at 01:00 local) still works as it did before. Worked out only for a small drop. - The test's dip case passed with or without the fix. It is replaced by a glitch to 0 at midday, which fails if the window is too wide. Adds Europe/London in summer time (reset at local and at UTC midnight) and America/New_York, with pytz zones as Predbat passes them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What this fixes
Wherever local midnight isn't 00:00 UTC, a daily
*_todaycounter that ends a day below 1 kWh loses energy the next day. That includes every UK user during British Summer Time (local midnight = 23:00 UTC). Every daily counter read throughminute_data(..., clean_increment=True)is affected (export_today,import_today,pv_today,load_today, iBoost and car charging energy, the ML load model's and Solcast's history), so on a dark day it hits PV and on most days export.Why:
minute_data()withsmoothingandclean_incrementtreats a drop as the counter's daily reset only if the drop is at least 1 kWh or the record is "near midnight" (Remove Minimum Drop for "Incrementing" Data near Midnight #3012).last_updated_time.time(). Home Assistant stamps history in UTC, so in CET the reset at 00:00:03 local arrives as 23:00:03 and doesn't count as near midnight.last_state, it also carries into the following day.Example from a GoodWe
export_todaysensor in Europe/Warsaw (daily totals, Home Assistant vsCurrent data so far todayin the Predbat log at 23:55):This is the separate
minute_data()reset item noted (untested) at the end of #6083; the other items there are not part of this PR.On 3 Dec the first 0.67 kWh of an evening export (1 Dec's total, carried through 2 Dec) was lost. The days after a total of at least 1 kWh (28 Nov, 1 Dec) were fine.
What changes
now's time zone, the local zone Predbat passes asnow_utc) or on UTC, as before. Counters that reset on UTC midnight (an inverter clock without DST) keep working. The check is only worked out for a drop, so the common path costs nothing extra.clean_incrementing_reverse, for UTC users too.Tests
minute_data_local_midnight(tests/test_minute_data_local_midnight.py):./run_all --quickpasses.🤖 Generated with Claude Code