Skip to content

Feat/use forecasting endpoint hems#190

Merged
nhoening merged 33 commits intomainfrom
feat/use-forecasting-endpoint-hems
Mar 31, 2026
Merged

Feat/use forecasting endpoint hems#190
nhoening merged 33 commits intomainfrom
feat/use-forecasting-endpoint-hems

Conversation

@BelhsanHmida
Copy link
Copy Markdown
Contributor

@BelhsanHmida BelhsanHmida commented Mar 9, 2026

Description

This PR updates the HEMS script to trigger forecasts using the forecasting endpoint /sensors/{id}/forecasts/trigger instead of running forecasts through the CLI.

How to test

  1. Run the HEMS script with the updated implementation.
  2. Verify that forecasts are successfully triggered via the /sensors/{id}/forecasts/trigger endpoint.
  3. Compare the generated forecasts with those obtained when running the forecasts using the CLI.
  4. Confirm that the overall HEMS results remain the same as before.

The forecasts and final HEMS outputs should match the results produced when using the CLI-based workflow.

closes #160

Copilot AI and others added 8 commits February 23, 2026 19:20
Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
…ecast

Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
… copilot agent instructions

Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
@BelhsanHmida BelhsanHmida self-assigned this Mar 9, 2026
@nhoening nhoening changed the base branch from main to copilot/support-forecasting-endpoints March 9, 2026 09:45
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…de status

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Base automatically changed from copilot/support-forecasting-endpoints to main March 19, 2026 08:08
@nhoening
Copy link
Copy Markdown
Contributor

@BelhsanHmida please pick this up again.

And one thought: we should check if we run the HEMS example against a FM server of at least v0.31, and otherwise raise an error message.

…s function

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…sion requirements

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
@BelhsanHmida
Copy link
Copy Markdown
Contributor Author

BelhsanHmida commented Mar 24, 2026

@BelhsanHmida please pick this up again.

And one thought: we should check if we run the HEMS example against a FM server of at least v0.31, and otherwise raise an error message.

Added that check. The HEMS example now verifies the connected FlexMeasures server is at least v0.31.0 before doing any setup work, and it raises a clear InsufficientServerVersionError with a HEMS-specific message if the server is too old. I also factored the logic into a reusable ensure_minimum_server_version(...) helper on the client and added tests for it.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
@BelhsanHmida
Copy link
Copy Markdown
Contributor Author

This PR now produces the same results as the CLI-based flow, so the forecasting API integration in the HEMS script is ready. We can now run it using the forecasting queue. Also, running multiple forecasting workers will speed up the forecasting part.

Results:
Screenshot from 2026-03-24 15-34-22
asset-27977-My Home 2--api-regressors-1

@BelhsanHmida BelhsanHmida marked this pull request as ready for review March 24, 2026 14:37
@BelhsanHmida BelhsanHmida requested a review from nhoening March 24, 2026 14:38
Copy link
Copy Markdown
Contributor

@nhoening nhoening left a comment

Choose a reason for hiding this comment

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

Nice!

I have three minor improvements.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…setup forecasting|scheduling queue

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
@BelhsanHmida BelhsanHmida requested a review from nhoening March 25, 2026 08:34
Copy link
Copy Markdown
Contributor

@nhoening nhoening left a comment

Choose a reason for hiding this comment

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

Good iteration, but I got the feeling you have not tested the error handling for forecasting jobs.

BelhsanHmida and others added 5 commits March 25, 2026 10:22
Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com>
Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com>
Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com>
Copy link
Copy Markdown
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 updates the HEMS tutorial workflow to use the FlexMeasures forecasting API endpoint (/sensors/{id}/forecasts/trigger) instead of relying on the FlexMeasures CLI, and adds supporting client logic/tests to improve version gating and error surfacing.

Changes:

  • Add ensure_minimum_server_version helper to the client and use it in the HEMS setup script.
  • Update HEMS forecasting example to trigger forecasts via the API and poll until completion.
  • Improve API error surfacing for responses containing a message, with accompanying tests.

Reviewed changes

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

Show a summary per file
File Description
src/flexmeasures_client/client.py Adds ensure_minimum_server_version and refactors request-version checking to reuse it.
src/flexmeasures_client/response_handling.py Surfaces API message fields as ValueErrors for non-2xx responses.
examples/HEMS/forecasting.py Replaces CLI-based forecasting with trigger_forecast + get_forecast polling.
examples/HEMS/HEMS_setup.py Enforces minimum server version required by the HEMS example.
docs/HEMS.rst Updates tutorial documentation to reflect API-based forecasting and worker queue setup.
tests/client/test_init.py Adds tests for ensure_minimum_server_version.
tests/client/test_forecast.py Adds coverage for forecast job failure responses including API message.

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

@FlexMeasures FlexMeasures deleted a comment from Copilot AI Mar 28, 2026
BelhsanHmida and others added 4 commits March 30, 2026 23:26
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@nhoening nhoening left a comment

Choose a reason for hiding this comment

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

Thanks!

Signed-off-by: Nicolas Höning <iam@nicolashoening.de>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
@nhoening nhoening merged commit 7866f1b into main Mar 31, 2026
4 of 10 checks passed
@nhoening nhoening deleted the feat/use-forecasting-endpoint-hems branch March 31, 2026 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants