fix: MQTT forecast topics were 4x too low at 15-min resolution - #407
Merged
Conversation
/FCST/production, /FCST/consumption and /FCST/net_consumption were documented as being in W, but the published value was always the raw Wh-per-interval array. That is numerically identical to average power at 60-minute resolution, but only 1/4 of it at 15-minute resolution, making 15-min forecasts look 4x too low to anything reading the topic as Watts (e.g. comparing against a provider's own portal). Keep 'value' as Wh per interval (consistent regardless of interval length) and add a derived 'power_w' field with the average power in W, so consumers get an unambiguous number without needing to know time_resolution_minutes themselves. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a unit mismatch in MQTT forecast topics at 15-minute resolution by keeping forecast value as Wh-per-interval (independent of interval length) and adding an explicit power_w (average Watts) field for energy-based forecasts, aligning both implementation and published API expectations.
Changes:
- Update
/FCST/production,/FCST/consumption, and/FCST/net_consumptionpublishing to keepvalueas Wh per interval and addpower_w(average W). - Add
_energy_to_power()and extend_create_forecast(..., include_power=True)to optionally includepower_w. - Add regression tests for 15-min vs 60-min behavior and update MQTT API documentation/examples accordingly.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/batcontrol/mqtt_api.py |
Changes forecast publishing semantics and payload structure (value in Wh/interval + optional power_w). |
tests/batcontrol/test_mqtt_api.py |
Adds regression tests ensuring correct scaling and that prices remain unchanged (no power_w). |
docs/integrations/mqtt-api.md |
Updates MQTT topic docs and example payload for the new forecast payload format. |
Comments suppressed due to low confidence (1)
docs/integrations/mqtt-api.md:233
- This section also references
general.time_resolution_minutes, but the setting istime_resolution_minutesat the top level of the config. Align the docs with the actual config key name.
- `time_end` - Unix timestamp for end of the interval (15 or 60 minutes later,
depending on `general.time_resolution_minutes`)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
docs/integrations/mqtt-api.md:225
- In the JSON example, the second entry's time_end is off by 1 second. _create_forecast() sets time_end to time_start + interval_seconds (e.g., 900s for 15-min), so 1696436100 should end at 1696437000, not 1696436999.
{
"time_start": 1696436100,
"value": 800.0,
"power_w": 3200.0,
"time_end": 1696436999
}
docs/integrations/mqtt-api.md:234
- This section references
general.time_resolution_minutes, but the config key istime_resolution_minutesat the top level (and the same page already usestime_resolution_minutesabove). Keeping the key consistent avoids confusing users.
- `time_start` - Unix timestamp for start of the interval
- `time_end` - Unix timestamp for end of the interval (15 or 60 minutes later,
depending on `general.time_resolution_minutes`)
- `value` - Forecasted value for that interval: Wh for production/consumption/net_consumption,
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.
Summary
/FCST/production,/FCST/consumptionand/FCST/net_consumptionare documented as being in W, but published the raw Wh-per-interval array unchanged. That's numerically identical to average power at 60-minute resolution, but only 1/4 of it at 15-minute resolution — so 15-min forecasts looked 4x too low to anything reading the topic as Watts (e.g. comparing against Solcast's own portal).valuenow stays consistently Wh per interval regardless oftime_resolution_minutes, and each entry additionally carries apower_wfield (average power in W), so both an energy- and a power-oriented consumer get an unambiguous number./FCST/pricesis unaffected (nopower_w, doesn't apply).docs/integrations/mqtt-api.md(topic list + example payload) to match.config/telegraf.sample.confneeds no change: itsjson_v2parser auto-detects all keys in eachdataobject (onlytime_endis excluded), sopower_wis picked up automatically; thepivotprocessor only touches thevaluefield, leavingpower_was its own field.Test plan
./run_tests.sh— 799 passeduv run pylint src/batcontrol/mqtt_api.py— 9.57/10 (no new warnings)tests/batcontrol/test_mqtt_api.py::TestForecastPublishingcover:valuestays raw Wh at 15 and 60 min,power_wscales correctly (4x at 15 min, 1x at 60 min), andpricesnever gets apower_wfield.🤖 Generated with Claude Code