Repository navigation
fix(alerts): replace corte_red heuristic with differential clamp + battery confirmation - #15
Merged
Merged
Conversation
…ature
The previous corte_red heuristic fired whenever currentGridPower was
near zero (gridMag < 0.02 kW) and the house was consuming. That
condition is normal in self-consumption, peak-shaving and cloud
transients — gridPower=0 with the grid perfectly up. It produced
false positives.
New signature uses the backed-up vs non-backed-up Tongou clamps on
the main house board (already wired as ENTITIES.consRespaldo and
consNoRespaldada): in a real outage with Solis EPS alive, the
non-backed-up circuit drops to ~0 W while the backed-up circuit
keeps running off the battery.
sinRed = fresco && gridMag < 0.05
&& noRespaldadaKw < 0.05
&& respaldoKw > 0.03
Fox signals (foxess_r_volt, running_state) are intentionally not used:
a Modbus/WiFi dropout of the Fox is indistinguishable from a real
outage (2025-07-12 incident: r_volt=0 for 20 h with the house
consuming 1.5 kW the whole time = comms dropout, not grid outage).
solar.computeLive now exposes respaldoKw and noRespaldadaKw on the
live snapshot. Tests cover the new behavior matrix: autoconsumption,
peak-shaving, Fox Modbus dropout, real outage + EPS, and full
blackout (covered by inversor_offline instead).
Refs #13
First production run surfaced a hole in the differential heuristic: when the non-backed-up Tongou clamp (vivienda_medidor_power) drops to 0 W due to a Zigbee dropout (HA holding the last value), the signature looks identical to a real outage and the engine fires a false critical. Observed 9-Aug-2026: clamp stuck at 0 W with grid perfectly up (Fox on-grid, calentador_voltage 232 V, inverterOnline=1) and the battery charging from PV at +0.29 kW. Add a hard confirmation: the battery must be DISCHARGING (<-0.05 kW). In a real outage with Solis EPS alive, the backed-up circuit is powered by the battery, so the battery cannot be charging. This drops the dropout case (and any other pinza-anomaly scenario where the backed-up circuit keeps running off the grid while the non-backed-up reading goes weird). Adds regression test for the exact scenario above. Refs #13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
corte_redwas firing on perfectly normal self-consumption: the old heuristic treatedcurrentGridPower ≈ 0as a proxy for "no grid", but that is just "not importing right now" — and a well-regulated Solis in self-consumption / peak-shaving holds grid flow at zero for minutes with the grid perfectly up. The audit log showed repeated false criticals every few minutes (8:37, 9:01, 9:07, 9:12, 9:32, 9:36, 9:42 on the day of the fix).New signature
Replaces the "zero grid flow" guess with a differential signature based on the Tongou clamps on the main house board (already wired as
ENTITIES.consRespaldoandENTITIES.consNoRespaldada):In a real outage with the Solis EPS alive, the non-backed-up circuit drops to ~0 W while the backed-up circuit keeps running off the battery, and the battery must be discharging to sustain it. In a full blackout without EPS, both clamps go to 0 and this alert does not fire —
inversor_offlinecovers that via anti-islanding.Why the Fox is NOT used
The first version of this PR tried to use
sensor.foxess_running_state(on-grid / off-grid) as the primary signal. Investigation against 8 months of recorder statistics showed it is unsafe: the 2025-07-12 incident hadfoxess_r_volt ≈ 0 Vfor ~20 hours whilevivienda_medidor_powerkept reading 200–1800 W the whole time. That was afoxess_modbuscommunication dropout, not a grid outage. Any signal based on the Fox can fire on Modbus/WiFi loss.Battery-discharging clause (second commit)
The pure differential signature was still fragile: when the non-backed-up clamp itself drops to 0 W due to a Zigbee dropout, the signature looks identical to a real outage. Caught this on the first production run after deploying commit b2c177f — the clamp was stuck at 0 W with grid perfectly up (Fox on-grid, calentador_voltage 232 V, inverterOnline=1) and the battery charging from PV. Requiring the battery to be discharging filters this case: in a real outage with Solis EPS, the backed-up circuit is powered by the battery, so the battery cannot be charging.
Tests
server/test/push.test.jscovers the new behavior matrix:solar.computeLivenow also exposesrespaldoKwandnoRespaldadaKwon the live snapshot.Verified in production: 0 false criticals in the observed window after deploy, while the clamp was still in dropout. Closing #13.