Skip to content

feat(sim): simulate relay diversion - #176

Merged
FredM67 merged 2 commits into
devfrom
sim/relays
Oct 1, 2026
Merged

FredM67 merged 2 commits into
devfrom
sim/relays

Conversation

@FredM67

@FredM67 FredM67 commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

grid_sim now simulates relay diversion, with three scenarios run against a firmware with two relays.

grid_sim

  • relay <pin> <phase> <W>: a resistive load on a relay - it follows its pin at once, with no zero-crossing latching.
  • Per load, the shortest complete ON and OFF periods; the summary shows them for relays:
    Relay D8    L1  1500 W:    2 switch-ons, on  44.1 %,   80.83 Wh, first on at 126.001 s
              shortest ON 120.0 s, shortest OFF 120.0 s (complete periods; -1: none)
    
  • New expectations: expect switches <pin> <min> <max>, expect min_on <pin> <s>, expect min_off <pin> <s>.

Firmware: configs/relays.patch

Two relays on D8 and D9: in at 1000 / 2000 W of export, out above 200 W of import, 2 minutes minimum ON and OFF, a 1-minute filter. Built in .pio/build-relays (PLATFORMIO_BUILD_DIR), so the basic firmware of make check stays.

The minimum times are longer than the 1-minute settle time the relay engine waits after any change. With 1-minute minimums, the settle time alone produced the very same holds, and a firmware ignoring the minimum times passed relay_min_times. Checked: such a mutant now fails both relay_steps and relay_min_times (it lets go after 91 s instead of 120 s).

Scenarios (make check-relays)

Scenario Checks
relay_steps relays come in by threshold, each once, not before their minimum OFF time from power-up; with import they go out in reverse order, a settle time apart
relay_min_times relay 1 held ON through an import, then OFF through a returning surplus, for its minimum times
relay_import_first import is cut first: relay 1 goes out before relay 2 while relay 2 is within its minimum ON time (intended - minimising import comes before the relays' order)

24 expectations; the three scenarios take ~80 s in parallel. They run in a CI job of their own, "Grid simulation (relays)", alongside the existing one, which does not get longer.

Test plan

  • the three relay scenarios pass: 10/10, 7/7, 7/7
  • a firmware without minimum ON/OFF times fails relay_steps and relay_min_times
  • make check unchanged (30/30)
  • actionlint, pre-commit

🤖 Generated with Claude Code

FredM67 and others added 2 commits October 1, 2026 11:35
grid_sim gets relay loads: `relay <pin> <phase> <W>` follows its pin at
once, with no zero-crossing latching. For every load it now tracks the
shortest complete ON and OFF periods, reported for relays, and checked
with `expect min_on|min_off <pin> <s>`; `expect switches <pin> <min>
<max>` counts switch-ons.

configs/relays.patch builds the firmware with two relays on D8 and D9
(1000 / 2000 W of export to come in, 200 W of import to go out, 2
minutes minimum ON and OFF, 1-minute filter), in .pio/build-relays so
the basic firmware stays. The minimum times are longer than the
1-minute settle time after any relay change: with equal ones, a
firmware ignoring them passed. Without them, relay_min_times now fails.

scenarios/relays (make check-relays, a CI job of its own):
- relay_steps: in by threshold, each once; out in reverse order,
  a settle time apart
- relay_min_times: held ON through an import, then OFF through a
  returning surplus, for the minimum times
- relay_import_first: import is cut first - relay 1 goes out before
  relay 2 while relay 2 is within its minimum ON time

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The relay job set the CI time (3 min, against 2 for the grid one). It
moves to relay-sim.yml, which runs on pull requests only when something
the relays depend on changes - relay engine, filter, pin writes, the
power they decide on, configuration, the simulator - and on every push
to main and dev.

The scenarios end shortly after their last event: 1185 s simulated
instead of 1300.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@FredM67
FredM67 merged commit 785b3f0 into dev Oct 1, 2026
10 checks passed
@FredM67
FredM67 deleted the sim/relays branch October 1, 2026 10:05
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.

1 participant