Pad HA price arrays with null to clear stale future-price sensors (#1188)#1222
Open
gskjold wants to merge 1 commit into
Open
Pad HA price arrays with null to clear stale future-price sensors (#1188)#1222gskjold wants to merge 1 commit into
gskjold wants to merge 1 commit into
Conversation
) Home Assistant price sensors (prices.import[N]) are created once and never removed, so the count only grows to the high-water mark (~34 future hours once tomorrow's prices are published). After midnight the price array shrinks back to the points remaining until next midnight, leaving the trailing sensors indexing past the end of the array. Jinja raises an IndexError on out-of-range list access, so HA fails to render those templates and freezes each sensor on its last value -- the "last point before midnight reused" reported in #1188. Pad the import/export JSON arrays with null up to priceImportInit / priceExportInit (the discovery high-water mark) so every existing sensor's index resolves. Out-of-data hours now render `null | is_defined` -> None, showing as unknown in HA instead of a stale repeated price. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🔧 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.
Fixes #1188
Problem
Home Assistant payload type reports wrong future prices: after midnight, the per-hour price sensors freeze on the last known value and repeat it for the rest of the (now expired) window — what the reporter saw as "the last point before midnight reused" for ~22 hours.
Root cause
The
/pricesJSON itself is correct — it only carries the real future points. The issue is the HA discovery sensors:publishPriceSensors()creates one sensor per future hour (prices.import[N]), and the count only ever grows (priceImportInit/priceExportInitare high-water marks). Once tomorrow's prices are published around 13:00, ~34 sensors exist permanently.IndexErroron out-of-range list access, so the value template fails to render and HA keeps the sensor's previous state — the stale repeated price.Fix
Pad the
import/exportarrays inpublishPrices()withnullup to the discovery high-water mark, so every existing sensor's index resolves. Out-of-data hours rendernull | is_defined→None, showing as unknown in HA instead of a stale value. The raw JSON is also more honest for non-HA consumers (trailingnulls rather than a silently shrinking array).Pure HomeAssistant-handler change; no decoder impact.
Verification
pio run -e esp32devbuilds clean.BufferSize.pos--) still hold since padding always leaves a trailing,.🤖 Generated with Claude Code