Repository navigation
Conversation
Update switching heatpump off when no longer heat required
|
LLM review
Minor
|
|
Small update under item 2. My main is now up to date.
2 - partial quarter removed - now until last full quarter until actual
runtime of the function, ie no longer aligned to 15' clock. This resolves
issues when calculation runs bit earlier or later than 15' clock intervals
Any further comments?
Op vr 27 nov 2026 om 14:34 schreef Olaf Marzocchi ***@***.***
…:
*dewi-ny-je* left a comment (corneel27/day-ahead#1073)
<#1073 (comment)>
LLM review
1.
*Crash on every run with no heat demand* (day_ahead.py ~2487 and
~3688). With heat_needed <= 0, hp_enabled now stays True, but the
whole else: branch that creates h_hp, blocks_num, hp_start_index,
block_len, hp_bl_on is skipped. After the solve, the report block
if self.hp_present and self.hp_enabled: runs if blocks_num > 0:, so
calc_optimum raises UnboundLocalError: cannot access local variable
'blocks_num' (and next h_hp[u].x on None). Both names are locals of
calc_optimum, assigned only inside that branch (blocks_num at ~2904;
the one at ~2628 is inside a """ string). This hits every heat pump
user
once today's heat is produced, and every run on mild days (degree days
0).
The output step that should switch the pump off is never reached, so
the
#1047 <#1047> goal fails
too. The scenario heatpump-mild-day-idle
(scenarios/cases/heatpump.json, 18 °C, no heat demand) runs exactly
this
path, so CI's "Scenario suite (solve)" should fail. Fix: keep a
separate
flag, e.g. self.hp_planned = self.hp_enabled and heat_needed > 0, use
it
for the report/log block at ~3688 and keep hp_enabled for the output
step; or initialise blocks_num = 0, h_hp/p_hp and guard the log loop.
2.
*The current partial quarter still resets the count* (part A, unchanged
from #1062 <#1062> item 2).
The last endpoint is now, compared with the total at
the last quarter boundary. Checked on SQLite with the PR's query and
loop:
a pump that has run 3 h with the sensor updating every 60 s gives
*0.0 h* when the calc starts at hh:15:05, and 2.75 h when it starts at
hh:14:30. With 0 the code takes the "staat stil" path
(first_block_start = None), so the solver may switch the pump off
before
the minimum run length: the #1008
<#1008> symptom. Fix:
drop the partial segment
when it is shorter than a few minutes, or let a partial segment
without a
rise keep the count instead of resetting it.
3.
*Sensor resolution / update rate* (part A). A quarter counts as running
only if the sensor rose within that quarter. Many heat pumps report
heat
produced in whole kWh, or update every few minutes. Checked: 1 kWh
resolution and 2 kW thermal (one step per 30 min) gives *0.0 h* for a
pump running for 3 h. Either look at a longer window (rise in the last
30–60 min), or fall back to / combine with consumption (the existing
get_heatpump_run_hours with wp_consumption_sensors).
4.
*Daily-reset sensor breaks the count at midnight* (#1062
<#1062> item 5).
entity hp heat produced is the heat produced *today* (it is subtracted
from today's need at ~2470). At 00:00 the total drops, the quarter is
counted as "not running" and the count restarts. Checked: a pump
running
since 22:00 gives 0.25 h at 00:29:30. Treat total < previous as a reset
and count the new value as production.
5.
*Snapshot capture/replay doesn't cover the new method* (#1062
<#1062> item 6).
da_debug.py patches Report.get_heatpump_run_hours only. With
entity hp heat produced set, a capture records nothing for run length,
and a replay hits _FakeDbManager.__getattr__ (db_ha.engine) and fails
with SnapshotMiss. The scenario corpus doesn't set that entity, so CI
won't show it, but user snapshots of heat pump setups will. Patch the
new
method the same way, or keep the old name.
6.
*Rounding throws away the gain* (#1062
<#1062> item 7). With 1 h
minimum and
0.75 h run, max(1, 1 - floor(0.75)) plans another full hour (1.75 h).
block_len is already int(first_block_len * 3600 / interval_s), so for
15min use max(0.25, min_run_length - run_hours) (rounded up to the
interval), for 1hour math.ceil on the remainder. Check the on/off
blocks_num/last_block_len formulas with a fractional first block.
7.
*Raw SQL portability* (#1062
<#1062> item 10). WITH
RECURSIVE and
CAST(... AS FLOAT) need MySQL ≥ 8.0.17 / MariaDB ≥ 10.4.5. One query
for
all states of the entity in the window plus a Python loop would avoid
dialect issues and match the SQLAlchemy Core style of the other HA
queries.
Minor
8. -2 ("geen data") is unreachable: quarters always yields rows, so an
entity with no states (typo) returns 0 and the log says "Warmtepomp
staat
stil". Return -2 when all totals are NaN.
9. The inner on/off if heat_needed > 0: ... else: "Geen warmtebehoefte"
is
now dead code; the commented-out # self.hp_enabled = False
should go.
10. "Warmtepomp draait al minimaal {run_hours} uur" now prints 0.75
etc.;
the new info line fires every quarter while the first block runs.
—
Reply to this email directly, view it on GitHub
<#1073?email_source=notifications&email_token=AL7BIJPR2LVYFV6DY74RHBT53F7GJA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTOMRRHE3DKMRVGEZKM4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#issuecomment-7219652512>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AL7BIJNMQN3TBFRAPJY5GCL53F7GJAVCNFSNUABFKJSXA33TNF2G64TZHM2TSNBQGQZDCMJUHNEXG43VMU5TMNJRGQ2TMNZYHA3KC5QC>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/AL7BIJN57DOECGDNRL4Z2EL53F7GJA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTOMRRHE3DKMRVGEZKM4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KUZTPN52GK4S7NFXXG>
and Android
<https://github.com/notifications/mobile/android/AL7BIJKDBGQM5IOUIPKMEE353F7GJA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTOMRRHE3DKMRVGEZKM4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2K4ZTPN52GK4S7MFXGI4TPNFSA>.
Download it today!
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
Diff provided: New findingsA. Blocking: crash when the sensor has no state older than 5 h B. Should fix: the 0.2 kWh threshold misses low and quantised output. C. Should fix: the midnight reset now forces a start. A drop is counted |
Update calculation of minimum run length heatpump
|
A. fixed - thanks for pointing out
B. A threshold > 0 is required as the pump when switched off is not
immediately giving 0kW thermal power. Also the actual switch on/off happens
later than the sensor readings (delay caused by the optimization).
Threshold is however depending on the heatpump capacity. So I've introduced
a new optional parameter: hp_maximum_thermal_power and set the threshold at
10% of its maximum power in any quarter. For an 8kW heatpump this is 0.2kWh
in any quarter. The help files are adjusted too. I've not
made the code even more complicated by reading the unit of measurement. The
help files clearly say unit of measure should be kWh. Users can now change
the threshold as necessary.
C. Fixed.
Op di 1 dec 2026 om 15:16 schreef Olaf Marzocchi ***@***.***>:
… *dewi-ny-je* left a comment (corneel27/day-ahead#1073)
<#1073 (comment)>
Diff provided:
pr1073-fixes.diff.txt
<https://github.com/user-attachments/files/35686988/pr1073-fixes.diff.txt>
New findings
*A. Blocking: crash when the sensor has no state older than 5 h*
(da_report.py, loop in get_heatpump_run_hours). difference is only
assigned in the else branch, but every row inside the window appends
"diff": difference. If the first endpoint (now − 5 h) has no state, the
second row has previous_total is None and difference was never set:
UnboundLocalError, and the whole calc stops. Checked: no states at all
(typo or newly created entity) and history that starts 2 h ago both crash.
A sensor whose older states were purged by the recorder would do the same.
Fix: set difference = None (or float("nan")) before the if, and return
-2 when all totals are NaN.
*B. Should fix: the 0.2 kWh threshold misses low and quantised output.*
0.2 kWh per quarter is 0.8 kW thermal, and the test is strictly >.
Checked: 1 kW thermal on a sensor with 0.1 kWh steps gives per-quarter
rises
of 0.2 or 0.3, so it reads 0.25 h for a pump that has run for 3 h; exactly
0.8 kW gives 0.0 h; 1 kWh resolution at 2 kW also gives 0.25 h. Float noise
makes it worse (10.2 - 10.0 = 0.19999…). The threshold also assumes the
sensor is in kWh; a Wh sensor makes it meaningless. Better: any rise
counts,
look at a 30–60 min window for coarse sensors, and make the unit explicit
(or read unit_of_measurement).
*C. Should fix: the midnight reset now forces a start.* A drop is counted
as "running" (difference < 0). With a daily-reset heat sensor and the pump
*off* all evening, a calc between 00:00 and 00:15 sees the 35 → 0 drop and
gets 0.25 h (checked at 00:00:30 and 00:14:00). With eco/max demand that
takes the "draait korter dan minimum" branch: first_block_start = 0 and a
full min_run_length block, so the pump is switched on at midnight whether
or not that is the cheapest time. Once on, the next runs see it rising and
keep it on. Fix: on a drop, use the new total as the rise
(difference = total when total < previous), so a reset only counts when
heat was actually produced after it.
—
Reply to this email directly, view it on GitHub
<#1073?email_source=notifications&email_token=AL7BIJLWDFKD5BPPKVCPIW3533HFRA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTOMZRGM4TQMRRHA3KM4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#issuecomment-7313982186>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AL7BIJODRV6L326H6R7SJB3533HFRAVCNFSNUABFKJSXA33TNF2G64TZHM2TSNBQGQZDCMJUHNEXG43VMU5TMNJRGQ2TMNZYHA3KC5QC>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/AL7BIJKNST5T5PIB437PWWL533HFRA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTOMZRGM4TQMRRHA3KM4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KUZTPN52GK4S7NFXXG>
and Android
<https://github.com/notifications/mobile/android/AL7BIJIEJ2H574GDX7SVIJL533HFRA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTOMZRGM4TQMRRHA3KM4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2K4ZTPN52GK4S7MFXGI4TPNFSA>.
Download it today!
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
No description provided.