Skip to content

Reaction rules: a headroom per direction, up to the nearest kink, so a device also absorbs what would cross a site capacity beyond the plan - #2965

Open
Flix6x wants to merge 25 commits into
feat/reaction-soft-site-capacity-kinkfrom
feat/reaction-guard-nearby-site-capacity
Open

Flix6x wants to merge 25 commits into
feat/reaction-soft-site-capacity-kinkfrom
feat/reaction-guard-nearby-site-capacity

Conversation

@Flix6x

@Flix6x Flix6x commented Dec 6, 2026 •

Copy link
Copy Markdown
Member

Description

Stacked on #2963 (breach-priced site capacities as kinks), and follows #2905 (reaction rules).

The gap. Off the price kink, a reacting device's band only extended from the plan to the side that absorbs deviations towards the kink. A site capacity just beyond the plan, away from the kink, therefore got no reaction. For example: a plan importing 11.36 kW against a breach-priced import limit of 12 kW, an EV at its 11 kW maximum (react 0), and a battery with band [[-1.137, 5]] kW and react 1. A 2 kW rise in base load takes the site to about 13.4 kW, and nothing reacts. The same holds with a hard site capacity, so this is not specific to soft limits.

The change: a headroom per direction. Each rule gains a headroom, [low, high] in the schedule's unit and sign convention: the deviations the device lets pass. The client absorbs only the excess outside it:

excess   = deviation − clip(deviation, low, high)
setpoint = clip(p − react · excess, band)
  • On a kink (the plan on the price kink, a mode-shaped miss, or a binding hard or breach-priced site capacity), the headroom is [0, 0]: the rule is unchanged.
  • Off the kink, each side is the distance from the planned connection power to the nearest kink that way: the price kink, or the nearest site capacity on that side (hard or breach-priced, per commodity), whichever is nearer; null on a side without one, where the device never reacts. Between two kinks the connection's cost is linear, so absorbing there gains nothing.
  • The band keeps both sides of the plan; the headroom, not a one-sided band, decides which deviations a device reacts to. The earlier per-device reach check is gone.
  • The headroom is a distance at the connection, the same for every reacting device of the site. Devices still react in series in flex-model order, each absorbing the excess of what the ones before it left, so a chain absorbs together exactly what would cross a kink, as far as the bands allow.
  • A device that must cross a hole between its operation modes towards the price kink (an idle charger that charges from 1.4 kW) gets that side shrunk by the hole's width, floored at 0, so it is in its next mode by the time the connection would cross the kink.
  • This also covers the case without a price kink (production and consumption priced equally above zero): a device then still absorbs what would cross a site capacity.
  • The parsing of hard and breach-priced site capacities lives in _site_capacities, shared by _intended_connection_power and the reaction rules.
  • Docs: a client needs to know every device that set react, and their order; where react is set in a flex-model stored on the asset, it finds them among the job's outputs, as the sensors whose schedule comes with a reaction array.
  • A coarser sensor keeps a slot's rule only where the sub-slots' headrooms agree too; otherwise react 0 and headroom [0, 0].
  • Reference: the plans of flexible devices without react are now part of the reference, which was only the inflexible forecast. The client subtracts only the power of the devices that get reaction rules from the meter, so such a device is uncontrolled as the client sees it; before, a client following the docs saw its whole planned power as a deviation (an EV charging at 11 kW as planned made the battery discharge against it). A departure from its plan still counts as a deviation. A device that set react but has react 0 in a slot is subtracted at its planned power, so its departure from plan counts as a deviation too; the docs now say so.
  • Docs: "Reacting to deviations at the connection" says that reaction rules are no protection function, and that physical limits stay with the installation's own protection and local load balancing; it describes the headroom; the API changelog's entry for the reaction field and the 1.2.0 changelog entry are extended (no entry of their own, since reaction rules are unreleased).

Backwards compatibility. Reaction rules are unreleased, so nothing released changes. A client that finds no headroom uses [0, 0], which gives the rule as served by #2905.

What it buys. On a synthetic replay against a site capacity 637 W beyond the plan, the headroom absorbs what would cross the capacity as well as holding the plan both ways does, at a lower cost. Without a reaction to it, 37.55 kWh crosses the capacity; both ways of reacting to it cut that to 0.07 kWh, the part the battery's band cannot cover. Holding the plan both ways makes the battery absorb 96.4 kWh to get there, with 147 drift retriggers; the headroom 37.5 kWh, with 74. The difference is energy absorbed from deviations that would never have crossed the capacity: it only moves the state of charge away from the plan. A deviation within the headroom is not absorbed, so it causes no state-of-charge drift and no retrigger.

Behaviour change in an existing test. A charger whose plan the operation modes keep 0.35 kW below a hard 5.75 kW fuse, at its 7.4 kW limit, used to get react 0 (band a single point). It now reacts to what would cross the fuse; the test is renamed to test_plan_just_below_the_fuse_absorbs_what_would_cross_it.

Look & Feel

For the example above, the battery's rule for that slot gets band [[-5, 5]] kW, react 1, the reference unchanged, and a headroom of 11.363 kW towards the price kink and 0.637 kW towards the limit. A +2 kW base-load swing then takes the site to the 12 kW limit and no further; a +0.5 kW swing passes unabsorbed.

How to test

pytest flexmeasures/data/models/planning/tests/test_reaction.py flexmeasures/api/v3_0/tests/test_reaction_response.py, under both solver backends. Among others:

  • test_site_capacity_beyond_the_plan_absorbs_beyond_the_headroom, test_far_site_capacity_absorbs_only_beyond_its_distance, test_big_battery_lets_a_far_site_capacity_pass.
  • test_chain_absorbs_what_would_cross_a_site_capacity, test_chain_absorbs_what_would_cross_a_site_capacity_beyond_each_battery: what no single battery could absorb, the chain absorbs together.
  • test_absorbs_what_would_cross_a_site_capacity_without_a_price_kink.
  • test_off_the_kink_importing_absorbs_what_crosses_the_kink and its exporting twin.
  • test_idle_charger_starts_charging_before_the_connection_crosses_the_kink, test_step_towards, test_headroom_per_side, test_headroom_without_capacities.
  • test_flexible_device_without_react_is_part_of_the_reference: an EV without react next to a reacting battery; the reference holds the EV's plan, the battery follows its plan with the house as forecast, absorbs what a load rise would take across the limit, and lets the EV stopping pass. It fails without the reference change.
  • test_reaction_response.py: the headroom is served in the schedule's unit and sign convention, with null for a side without a kink.

Further Improvements

Related Items

Stacked on #2963; follows #2905. The client side is FlexMeasures/flexmeasures-client#299, which documents that only devices with reaction rules enter the meter subtraction and its residuals.


Sign-off

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on code under GPL or other license that is incompatible with FlexMeasures

🤖 Generated with Claude Code

https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE

Flix6x and others added 5 commits December 6, 2026 00:47
The reaction rules need the hard and breach-priced site capacities also where the plan does not sit at them, so their parsing moves out of `_intended_connection_power` into `_site_capacities`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…g device's reach

Off the price kink, a reacting device's band only kept the kink's side of the plan, so a deviation pushing the connection away from the kink was not absorbed, even where a site capacity (hard or breach-priced) lay just beyond the plan.
Where such a capacity, per commodity, is closer to the planned connection power than the device could still move against a deviation in that direction within its band, the band now keeps both sides, and the device reacts against the same reference, holding the planned connection power both ways.
It then also absorbs deviations that would not have crossed the capacity; the drift gate and retrigger handle the resulting drift.
A charger whose plan the modes keep just below a hard fuse now defends that fuse.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…nd an off-kink plan

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…thin reach

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
@Flix6x Flix6x added this to the 1.2.0 milestone Dec 6, 2026
@Flix6x Flix6x added Scheduling Feature A new feature labels Dec 6, 2026
@Flix6x Flix6x self-assigned this Dec 6, 2026
…ing devices

A site capacity beyond an off-kink plan was defended only where a single device could reach it.
Since reacting devices act in series, each taking what the devices before it could not, the chain of reacting devices of a commodity can defend a capacity that no single device can reach.
So "within reach" now compares the distance to the capacity with the room of all reacting devices of the commodity together, and every reacting device with room to move against a deviation towards the capacity keeps its whole band and reacts, also where no kink is within its own reach.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
@read-the-docs-community

read-the-docs-community Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

📖 6 files modified


Preview · build overview · flexmeasures · built Dec. 6, 2026, 2:34 p.m. UTC

Flix6x and others added 9 commits December 6, 2026 01:20
…e kink

Where consumption and production are priced the same and above zero, there is no price kink, and a device used to get react 0 unless a site capacity bound.
A site capacity within the combined reach of the reacting devices, on either side of the plan, is now defended there too: the devices with room to move against a deviation towards it get react 1, their whole band, and the forecast as reference.
On symmetric prices, this also makes a battery react in slots where it plans to export well within the site's export limit, as long as that limit is within its reach; two existing tests are updated accordingly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…adroom

Each reaction rule now carries a headroom, the range (low, high) of deviations the device lets pass.
On the kink it is 0 on both sides; off the kink it is 0 towards a price kink within the device's reach,
and the distance to the nearest site capacity (hard or breach-priced) away from it, or on both sides without a price kink.
The band is left as the device's feasibility, no longer cut to the kink's side,
and the "within reach" guard is dropped: with the headroom, a far site capacity costs no reaction until a deviation would cross it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…sign convention of its values

Each reaction object gains a headroom [low, high], null on a side where the device never reacts.
A production-positive sign convention swaps its sides, a coarser sensor keeps it only where the sub-slots agree,
and rules stored without one are served with [0, 0], so they keep their meaning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
… direction

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…ay, the same for every device

Each side of the headroom is now the distance from the planned connection power to the nearest kink in that direction,
the price kink or a site capacity, whichever is nearer, so a deviation that keeps the connection between its neighbouring kinks passes.
The per-device reach of the price kink is dropped: every reacting device gets the same site-level headroom,
its band limits what it can do, and the chain passes the rest on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…deviation within it causes no drift

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
… must take from its planned mode

A device that must cross a hole between its operation modes to absorb towards the price kink, such as an idle charger that charges from 1.4 kW,
gets that side of the headroom shrunk by the hole's width, floored at 0, where the price kink is the nearest kink on that side,
so it is in its next mode by the time the connection would cross the kink, rather than only after crossing it by the whole step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…rice kink starts that much earlier

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
@Flix6x Flix6x changed the title Reaction rules: defend a site capacity within a device's reach, also when the plan sits below it Reaction rules: a headroom per direction, up to the nearest kink, so a site capacity beyond the plan is defended Dec 6, 2026
Flix6x and others added 5 commits December 6, 2026 14:24
…tion reference

The client subtracts only the power of the devices that get reaction rules from the meter,
so a flexible device without react is uncontrolled as the client sees it.
Leaving its plan out of the reference made a client see its planned power as a deviation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…out react, and the client subtracts the planned power of a device that does not react in a slot

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
… with the installation's own protection and load balancing

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…limit it defends

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…nd, rather than holding the connection

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
@Flix6x Flix6x changed the title Reaction rules: a headroom per direction, up to the nearest kink, so a site capacity beyond the plan is defended Reaction rules: a headroom per direction, up to the nearest kink, so a device also absorbs what would cross a site capacity beyond the plan Dec 6, 2026
…he scheduling job's result

A client learns from the job it already waits for which devices to subtract from the meter and where it stands in the series,
also for devices whose react was set in a flex-model stored on the asset.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Flix6x and others added 4 commits December 6, 2026 15:07
…, from the job's reaction-sensors

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…es order, from the job's reaction-sensors"

This reverts commit d2a366b: the list of reacting devices waits for a design of a central schedule response.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…er, in the scheduling job's result"

This reverts commit 087fa8f: the list of reacting devices waits for a design of a central schedule response.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…hose set on the asset among the job's outputs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGt2vUmJ4goxUYxexuArDE
Signed-off-by: F.N. Claessen <claessen@seita.nl>

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant