Skip to content

More boiler starts in planning period - #1082

Open
corneel27 wants to merge 28 commits into
mainfrom
more-boiler-starts-in-planning-period
Open

corneel27 wants to merge 28 commits into
mainfrom
more-boiler-starts-in-planning-period

Conversation

@corneel27

Copy link
Copy Markdown
Owner

This is a complete rewrite of the boiler part of DAO.
It takes into account the horizon extension and allows more than one reheat action in the planning period.

@corneel27
corneel27 marked this pull request as draft November 24, 2026 09:19
@corneel27

Copy link
Copy Markdown
Owner Author

@JoostBaltissen
My changes result in failing checks.
The first fail produces an error with this command:
python', '-m', 'dao.prog.da_debug', 'scenario-run', 'battery-flat-no-incentive', '--threads', '1', '--log', '--report', '--json'
Now I try to reproduce this error local in my develop-laptop with this command:
python -m dao.prog.da_debug scenario-run battery-flat-no-incentive --threads 1 --log --report --json

But now a get an error message that I don't understand.
This is the logging:

No secrets file found, secret resolution will fail
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/cees/day-ahead-6/dao/prog/da_debug.py", line 4733, in <module>
    sys.exit(main())
             ~~~~^^
  File "/home/cees/day-ahead-6/dao/prog/da_debug.py", line 4717, in main
    return handler(args, data_dir)
  File "/home/cees/day-ahead-6/dao/prog/da_debug.py", line 4358, in cmd_scenario_run
    r = run_scenario(sc, threads=args.threads, keep_png=args.png, report_dir=report_dir)
  File "/home/cees/day-ahead-6/dao/prog/scenarios/runner.py", line 283, in run_scenario
    tier_a_checks = run_tier_a(rc)
  File "/home/cees/day-ahead-6/dao/prog/scenarios/expectations.py", line 304, in run_tier_a
    return [inv.check(rc) for inv in TIER_A_INVARIANTS]
            ~~~~~~~~~^^^^
  File "/home/cees/day-ahead-6/dao/prog/scenarios/expectations.py", line 119, in check
    if disc > 0.5 and charge.get((b, u), 0.0) > 0.5
       ^^^^^^^^^^
TypeError: '>' not supported between instances of 'NoneType' and 'float'

Can you help me with some tips?

@JoostBaltissen

Copy link
Copy Markdown
Collaborator

The traceback is a bug in the scenario harness: when a solve finds no solution, it crashes instead of reporting it. I'll fix that.
The actual result underneath is a Tier A solved fail. This means the model or solver is broken.
I will try to reproduce this.

@corneel27

Copy link
Copy Markdown
Owner Author

Shall I sent you a snapshot. Helps that?

@JoostBaltissen

JoostBaltissen commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

I fixed the test runner, #1083. Now we are able to see the log.

Boiler direct opwarmen staat uit
Boiler actuele temperatuur 45.0 °C
Boiler setpoint 50.0 °C
Boiler hysterese 2.0 K
Boiler cooling rate 0.4 K/uur
Boiler stookgrens 44 °C
Het programma heeft geen speelruimte tussen heating allowed below 44 en de boiler ondergrens 48.0(= setpoint 50.0 - hysterese 2.0
De waarde voor heating_allowed_below is verhoogd naar 45
Boiler wordt wel opgewarmd door de warmtepomp
Boiler warmtecapaciteit : 0.246 kWh/K
Boiler cop : 2.900
Boiler vermogen : 1.500 kW

MIP has 6396 rows; 8910 cols; 27144 nonzeros; 2819 integer variables (2816 binary)
Coefficient ranges:
Matrix [6e-04, 1e+01]
Cost [1e+00, 1e+00]
Bound [4e-01, 2e+03]
RHS [6e-02, 1e+02]
Column 4899 bounds [48, 45] have excessive infeasibility = -3
Column 4900 bounds [48, 45] have excessive infeasibility = -3
Column 4901 bounds [48, 45] have excessive infeasibility = -3
Column 4902 bounds [48, 45] have excessive infeasibility = -3
Column 4903 bounds [48, 45] have excessive infeasibility = -3
Column 4904 bounds [48, 45] have excessive infeasibility = -3
Column 4905 bounds [48, 45] have excessive infeasibility = -3
Column 4906 bounds [48, 45] have excessive infeasibility = -3
Column 4907 bounds [48, 45] have excessive infeasibility = -3
Column 4908 bounds [48, 45] have excessive infeasibility = -3
Model has 97 significant inconsistent bound(s): infeasible
Rekentijd: 0.00 sec
Model status: OptimizationStatus.INFEASIBLE
Geen oplossing voor: minimize cost, kijk naar je instellingen.

I don't directly know what the Columns are, but the values 48 and 45 suggest lowerbound and actual temp. Maybe the warning "geen speelruimte" also gives it away.

This scenario has no boiler config specified, therefore the values come from options_example.json.
Values that should come from HA are specified in base_states.json.
It could be that those values are wrong, but I don't think that a set temperature of 50C and an actual temperature of 45C is weird. That is just a boiler that needs heating.
Something to consider, should basic Tier A test scenarios include a complex feature like a boiler. I think it should be seperated. That will make debugging easier.

@corneel27

corneel27 commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner Author

@JoostBaltissen
I added "config_patch": {"boiler.boiler_present": false} to battery.json -> boiler will not be planned.
But I get the same errorin the workflow.
On my local machine after the command:
python -m dao.prog.da_debug scenario-run battery-flat-no-incentive --threads 1 --log --report --json
I get this json-result:

No secrets file found, secret resolution will fail
{
  "passed": 0,
  "report_paths": {
    "csv": "/home/cees/day-ahead-6/dao/data/scenario_reports/scenario_report_20261124_224600.csv",
    "md": "/home/cees/day-ahead-6/dao/data/scenario_reports/scenario_report_20261124_224600.md"
  },
  "results": [
    {
      "checks": [
        {
          "detail": "",
          "name": "solved",
          "ok": true
        },
        {
          "detail": "",
          "name": "no_simultaneous_charge_discharge",
          "ok": true
        },
        {
          "detail": "",
          "name": "sos2_adjacent",
          "ok": true
        },
        {
          "detail": "",
          "name": "var_bounds_respected",
          "ok": true
        },
        {
          "detail": "",
          "name": "soc_within_limits",
          "ok": true
        },
        {
          "detail": "",
          "name": "ev_single_real_stage_per_interval",
          "ok": true
        },
        {
          "detail": "",
          "name": "ev_charge_non_negative",
          "ok": true
        },
        {
          "detail": "",
          "name": "planned_machines_reported",
          "ok": true
        },
        {
          "detail": "",
          "name": "overrides_were_read",
          "ok": true
        },
        {
          "detail": "FAIL: old=2.291358 new=2.112000 delta=-0.179358 (tolerance 0.005000)",
          "name": "objective_within_baseline",
          "ok": false
        },
        {
          "detail": "",
          "name": "battery_flat_during",
          "ok": true
        }
      ],
      "failures": [
        "[Tier C] objective_within_baseline: FAIL: old=2.291358 new=2.112000 delta=-0.179358 (tolerance 0.005000)"
      ],
      "gap": null,
      "id": "battery-flat-no-incentive",
      "log_path": "/home/cees/day-ahead-6/dao/data/scenario_reports/battery-flat-no-incentive.log",
      "nodes": null,
      "objective": 2.112,
      "png_path": null,
      "setup_checks": [
        {
          "detail": "",
          "name": "overrides_were_read",
          "ok": true
        }
      ],
      "status": "FAIL",
      "threads": 1,
      "wall_time_sec": 0.37
    }
  ],
  "total": 1
}

Is that expected?
I now see that it calculates well, but the objective is changed.
Probably because now boiler_present=false.
Can I change the expected "objective" value and where is that stated?

Edit
Found it: scenarios/baselines.

@corneel27

Copy link
Copy Markdown
Owner Author

@JoostBaltissen wrote:

This scenario has no boiler config specified, therefore the values come from options_example.json.
Values that should come from HA are specified in base_states.json.
It could be that those values are wrong, but I don't think that a set temperature of 50C and an actual temperature of 45C is weird. That is just a boiler that needs heating.

This is from the log:

Boiler direct opwarmen staat uit
Boiler actuele temperatuur 45.0 °C
Boiler setpoint 50.0 °C
Boiler hysterese 2.0 K
Boiler cooling rate 0.4 K/uur
Boiler stookgrens 44 °C
Het programma heeft geen speelruimte tussen heating allowed below 44 en de boiler ondergrens 48.0(= setpoint 50.0 - hysterese 2.0
De waarde voor heating_allowed_below is verhoogd naar 45
Boiler wordt wel opgewarmd door de warmtepomp
Boiler warmtecapaciteit : 0.246 kWh/K
Boiler cop : 2.900
Boiler vermogen : 1.500 kW

The value of the hysteresis is to low: setpoint - hysterese should be lower than heating_allowed_below
A value of 2 K for hysteresis is always to little to give DAO enough room to "play" with.

I shall:

  • change the code: generate an error and an according error-message when hysteresis is to low
  • make a scenario to test this
  • keep boiler out of the Tier A scenarios
  • set hysterese in base_states.json to 10 K

@JoostBaltissen

Copy link
Copy Markdown
Collaborator

Sounds like a good plan!
You can set new tier C baselines with the scenario bless command. python -m dao.prog.da_debug scenario-bless battery-flat-no-incentive this will only work when the scenario actually solves.

@corneel27
corneel27 marked this pull request as ready for review November 25, 2026 21:49
@corneel27
corneel27 requested a review from storeman November 25, 2026 21:50
@corneel27

Copy link
Copy Markdown
Owner Author

@storeman
when I try this branche locally with the webserver I get this:
image
What should I do/what do I wrong?
Am I missing a file or a module?

JoostBaltissen and others added 3 commits November 26, 2026 22:51
…1086)

This is to support the development of the new boiler model and to
 ensure that the solver behaves as expected in these edge cases.
…1098)

and the check reads the limit there.

boiler_stook_grens is just a constant in a constraint, so the check took
heating_allowed_below from the config. When day_ahead.py raises it to
floor + 1, the check flagged valid starts.
@corneel27

Copy link
Copy Markdown
Owner Author

@JoostBaltissen @storeman
I think this PR is ready for review and (if OK) ready for merge with the main-branche.
Can you review it?

Comment thread dao/prog/day_ahead.py Outdated
extension=0
)
if horizon_extension > 0:
if len(fixed_price_data) > 10 and horizon_extension > 0:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What happens when there are 8 fixed prices? Then only the fixed_price_data is used without the extension. The exit on line 294 does not break with 8 prices.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fix would be setting horizon_extension = 0 in the else branch?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

That is indeed the intention. When there are at 15 o'clock no prices for tomorrow available then and the user calculates with 1hour-interval then there 9 values and calculation goes on until there are 5 values (19:00).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Okay. But this block defines the pred_price_data var, which is used after the check. So with 6 to 10 fixed prices it will result in an issue with this var.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

But why would you ignore the extension when there are only a few prices available? The optimizer could detect that warming up the boiler is better tomorrow (in the extension), when there are a few prices, the extension is ignored and warming the boiler is started immediately. I think it would make sense to always use the extension when available.

A general rule to stop the optimizer if the actual window is to small would make sense, but that could checked at the very beginning of the run.

Also, within this block, horizon_extension is assigned the value of really available prices in the extension, while before the if, the var has the configured extension in it. In the else-block, the configured-extension value stays assigned to horizon_extension.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Shall I try to resolve it in this way:

  • when period of fixed_prices <= 10 hours: warning and continue
  • when period of fixed_prices <= 5 hours; error and stop
  • when "extension" in config > 0: get predicted prices
  • when hours of get_predicted_prices < expected: warning

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sounds good! I don't fully understand how this would work with 15minutes interval, but you undoubtedly have given it your thoughts, so just saying, in case you might have forgotten.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

I fixed it as planned.

Comment thread dao/prog/day_ahead.py Outdated
if self.hp_adjustment == "on/off":
hp_hours = 0
interval_avail = U - boiler_int - 1
# interval_avail = U - boiler_int - 1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

boiler_int is gone so the solver does not correct for hours the hp produces DHW instead of heating.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

You are right. I fixed this with an update

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

fixed: added correction for the heating time

"x-validation-hint": "Must be > 0, use 1.0 for resistive, 2.5-4.0 for heat pump",
},
)
cop_temperature_curve: list[CopTemperaturePoint] = Field(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe add validation to check for valid stage configuration? Could be a near copy-paste from the heating validate_stages

@corneel27 corneel27 Nov 30, 2026 •

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Is indeed the same as with the heatpump, but the boiler has no stages. Only one cop that may change with the outdoor temperature.
I moved the model of CopTemperaturePoint] to the base.py. Now heating and boiler use the same model.
I added the validation in the boiler-model

@corneel27 corneel27 Dec 1, 2026 •

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

added validation in boiler-config

Comment thread dao/prog/day_ahead.py Outdated
for u in range(U):
model += (
boiler_temp[u + 1]
>= boiler_max_temp - M * (1 - boiler_finish[u])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Bij boiler_finish = 0 dwingt deze regel al na het eerste interval boiler_min_temp af, ondanks de soepelere lb bij het aanmaken van boiler_temp. Repro met een elektrische boiler van 1,5 kW, 38 °C gemeten en een ondergrens van 40 °C. Na het eerste kwartier op vol vermogen is ongeveer 39,4 °C haalbaar. Daardoor wordt de hele planning infeasible. Kunnen we bij een start onder de ondergrens direct verwarmen en per interval een haalbare tijdelijke ondergrens gebruiken, zowel bij lb als in deze voorwaarde? Eventueel een scenario/fixture toevoegen om dit te testen.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Snelle aanpassing aan test case "boiler-below-floor" met "states": {
"sensor.boiler_gemeten": "30"
},
bevestigt bovenstaande.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Een lege of 0 waarde uit Home assistant leidt ook direct tot een probleem.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

fixed with:
variable boiler_min_temp:
variable boiler_max_temp
big M dependent of boiler-min and boiler_max

Comment thread dao/prog/day_ahead.py Resolved
Comment thread dao/prog/day_ahead.py Outdated
for u in range(U):
model += (
boiler_temp[u + 1]
>= boiler_max_temp - M * (1 - boiler_finish[u])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Snelle aanpassing aan test case "boiler-below-floor" met "states": {
"sensor.boiler_gemeten": "30"
},
bevestigt bovenstaande.

Comment thread dao/prog/day_ahead.py Outdated
for u in range(U):
model += (
boiler_temp[u + 1]
>= boiler_max_temp - M * (1 - boiler_finish[u])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Een lege of 0 waarde uit Home assistant leidt ook direct tot een probleem.

Comment thread dao/prog/day_ahead.py Outdated
+ total_low_soc_cost
+ battery_storage
+ boiler_storage
+ boiler_end_value.x

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

in the model at line 3411 it's a minus sign.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed

Comment thread dao/prog/day_ahead.py Outdated
extension=0
)
if horizon_extension > 0:
if len(fixed_price_data) > 10 and horizon_extension > 0:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fix would be setting horizon_extension = 0 in the else branch?

@dewi-ny-je

Copy link
Copy Markdown
Contributor

I'm not following much this PR but it's very important so can someone please ping me once you think it's ready to merge, so I have it reviewed to add another pair of virtual eyes?

@dewi-ny-je

Copy link
Copy Markdown
Contributor

By the way, so that you can focus on the infeasible runs:

Wrong sign of the boiler term in the cost summary

  • Before: boiler_storage = (temp[0] - temp[U]) * ... * p_avg (a loss is positive, like battery_storage).
  • Now: total_cost = ... + battery_storage + boiler_end_value.x, with
    boiler_end_value = (temp[U] - temp[0]) * ... (a gain is positive). The sign is flipped, so
    "Total" in the cost log is off by twice the boiler storage value and "Boiler storage" shows the
    opposite sign of "Battery storage". Only logging, the objective (- boiler_end_value) is correct.
  • Fix: + (-boiler_end_value.x) in total_cost and in the "Boiler storage" line.

@corneel27

Copy link
Copy Markdown
Owner Author

@storeman @JoostBaltissen
I fixed the found errors, thank you for taking time.
Please review again the fixed PR

Comment thread dao/prog/day_ahead.py Outdated
hours_avail = math.floor(interval_avail * self.interval_s / 3600)
hours_avail = min(48, sum(hour_fraction))
if boiler_heated_by_heatpump:
boiler_heating_hours = math.ceil(boiler_cooling[1] * hours_avail / boiler_heating_rate[1])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does this fix not also apply if self.hp_adjustment != "on/off"?

Comment thread dao/prog/day_ahead.py
# is boiler_max_temp - boiler_min_temp voldoende als Big-M.
M = boiler_max_temp - boiler_min_temp
M = max(boiler_max_temp, boiler_act_temp) - min(boiler_min_temp, boiler_act_temp)
for u in range(U):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

boiler_temp[u + 1] is the end of interval u, so the cooling of interval u counts: [:u + 1].

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

After second thought: I think you are right:
sum(boiler_cooling[:u+1]) count from 0 up to and including u.
Fixed

@dewi-ny-je

dewi-ny-je commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Since it's getting closer, and most bugs were fixed, the LLM review.
It looks good!

num_int off by one when the cycle does not finish: in the start log when the cycle does not finish within the horizon the loop ends at
j = U and reports one interval too many.

A commented-out line remains
(# boiler_max_temp = max(...)).

N1. New: no plan at all when 5 h or less of day-ahead prices are left (regression vs main)

  • a8e926e: hours_fixed_price_data = int(len(fixed_price_data) * interval_s / 3600); if <= 5 the
    run logs "berekening wordt gestopt" and returns False, before the predicted-price extension is added.
    Main only stopped when the whole price series (fixed + extension) had <= 5 rows.
  • Effect: from 19:00 (hourly) or 18:15 (15 min) until tomorrow's prices are in, nothing is planned or
    written to HA, also when a horizon extension with predicted prices is configured. Normally prices
    come in around 13:00, so this hits days with late or failed publication, which is exactly when the
    extension is useful.
  • Reproduced: start 19:00, 5 h of day-ahead prices, with and without 29 h of predicted prices:
    stops on the PR, solves on main.
  • Suggested fix: keep the guard for an empty frame (len(fixed_price_data) > 0 before iloc[-1]),
    and apply the "too short" check to price_data after the extension, as main did (rows, or hours
    if the hour limit is intended). If stopping without prices beyond 5 h is intended, it deserves its
    own PR and a note in the release notes.

N2. Minor: heat pump hours capped at 48

  • hours_avail = min(48, sum(hour_fraction)) for all heat pump modes. heat_needed covers at most
    today + tomorrow, so the cap matches that, but with a 96 h horizon the power-mode max/min heat
    production is now scaled to 48 h of the horizon. Not a bug I could make fail; worth a comment in
    the code on why 48.

Why was it capped at 48, actually? Performance?

This branch has not been deployed

No deployments
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.

4 participants