Skip to content

[WiP] Homeassistant sensor as consumption forecast#214

Merged
MaStr merged 10 commits intomainfrom
homeassistant-load
Nov 3, 2025
Merged

[WiP] Homeassistant sensor as consumption forecast#214
MaStr merged 10 commits intomainfrom
homeassistant-load

Conversation

@MaStr
Copy link
Owner

@MaStr MaStr commented Oct 30, 2025

Use HA sensors for absolute Wh, which is used for displaying the energy graph, for calculating an consumption forecast.

I can't verify that for my self, because I am on the iobroker train. :)

@MaStr MaStr self-assigned this Oct 30, 2025
@MaStr MaStr added enhancement New feature or request ConfigChange Needs to be reviewed for HA Addon labels Oct 30, 2025
@MaStr MaStr requested a review from Copilot November 3, 2025 17:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds HomeAssistant API-based consumption forecasting as an alternative to the existing CSV-based approach. It enables users to fetch historical consumption data from HomeAssistant via WebSocket API and generate weighted forecasts based on configurable historical periods.

  • Implements a new ForecastConsumptionHomeAssistant class that fetches hourly consumption statistics from HomeAssistant using WebSocket API
  • Adds comprehensive test suite covering initialization, data fetching, caching, and forecast generation
  • Updates configuration factory to support homeassistant-api type with backwards-compatible changes

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/batcontrol/forecastconsumption/forecast_homeassistant.py New module implementing HomeAssistant-based consumption forecasting with WebSocket API integration
src/batcontrol/forecastconsumption/consumption.py Updated factory to support HomeAssistant API forecasting type alongside CSV
tests/batcontrol/forecastconsumption/test_homeassistant.py Comprehensive test suite for HomeAssistant forecaster with 15+ test cases
tests/batcontrol/forecastconsumption/init.py Package initialization for tests
scripts/test_homeassistant_forecast.py Test/demo script for manual verification of HomeAssistant integration
config/batcontrol_config_dummy.yaml Configuration examples for both CSV and HomeAssistant API options
pyproject.toml Added websockets dependency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

json.dumps({"type": "auth_ok"}),
# 3. statistics response
json.dumps({
"id": 1,#
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove stray '#' character at the end of the line.

Suggested change
"id": 1,#
"id": 1,

Copilot uses AI. Check for mistakes.
self,
start_time: datetime.datetime,
end_time: datetime.datetime
) -> float:
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra whitespace between '->' and 'float' in type annotation.

Suggested change
) -> float:
) -> float:

Copilot uses AI. Check for mistakes.
@MaStr MaStr merged commit 2d6d009 into main Nov 3, 2025
10 checks passed
@MaStr MaStr deleted the homeassistant-load branch November 3, 2025 18:26
@MaStr MaStr linked an issue Nov 4, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ConfigChange Needs to be reviewed for HA Addon enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consumption forecast via homeassistant sensor

2 participants