Skip to content

feat: OpenDTU Zero-Export (supports Shelly LNM or MQTT) - #3227

Open
mathieucarbou wants to merge 1 commit into
tbnobody:masterfrom
mathieucarbou:feat/zero-export
Open

mathieucarbou wants to merge 1 commit into
tbnobody:masterfrom
mathieucarbou:feat/zero-export

Conversation

@mathieucarbou

@mathieucarbou mathieucarbou commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

feat: OpenDTU Zero-Export (supports Shelly LNM or MQTT)

Summary

This PR adds a native Zero-Export controller to OpenDTU.

It regulates Hoymiles inverter power limits directly from the grid power measurement, removing the need for an external Home Assistant automation loop. The grid power is kept around a configurable setpoint (default: 0 W, i.e. neither export to nor import from the grid).

The regulation follows the same feedback model previously used in Home Assistant:

missedPower = gridPower - setpoint
newLimit = previousRequestedLimit + missedPower

The correction is distributed proportionally to the inverters' rated power and constrained by:

  • Each inverter's nominal power
  • The configured minimum production power (per inverter, default: 40 W)
  • Inverter reachability and the command-enabled state
  • The configured regulation interval

The regulation feedback is only the grid error: the controller tracks the last absolute limit it requested per inverter and uses those values as the starting point of the next step. The inverters' reported limits and production telemetry are deliberately not used as feedback because those values may be delayed or stale. (The one-time startup adoption below is the only exception.)

Two additional safeguards shape the correction:

  • Source-adaptive damping: each source estimates its own update period (EWMA of the intervals between accepted samples). Upward corrections are spread over the measured source period plus the estimated inverter response latency, so the loop gain does not multiply when the previous correction has not been measured yet. Downward corrections remain immediate to reduce export.
  • Production cap: the requested total limit is capped above the currently measured production (with headroom: at least 300 W or 30 %), so limits cannot drift far above what the inverters actually produce. The cap's base never drops below the enforced per-inverter floor sum, so a low-light start can always ramp up again.

How try this firmware ?

You can find complete released firmware to download to test that from my fork:

=> https://github.com/mathieucarbou/tbnobody-OpenDTU/releases/

Grid Sources

Grid sources are implemented through the ZeroExportGridSource interface, which also tracks measurement freshness and estimates the source update period. This keeps the regulation algorithm independent from the transport and makes additional sources easy to add later.

Currently supported sources:

  • Shelly LNM
  • MQTT

Future sources such as Victron Modbus TCP or Fronius Modbus TCP can be added without changing the regulation logic.

Shelly LNM

Shelly Local Network Messaging is Shelly's local UDP multicast protocol. Shelly devices publish measurements such as active power, voltage, current, power factor, and frequency without requiring HTTP polling.

OpenDTU:

  • Joins the configured multicast group using WiFiUDP
  • Processes packets from the scheduler without blocking inverter communication
  • Parses the 12-byte LNM binary header (starting with the "SL" magic) and its JSON payload
  • Extracts the configured power field from the status components (e.g. em1:0 / em:0): act_power (Shelly EM), total_act_power (Shelly 3EM), or the per-phase a_act_power / b_act_power / c_act_power
  • Marks the source unavailable when no fresh packet is received

Default configuration:

  • Multicast group: 239.255.55.55
  • UDP port: 5555
  • Power field: act_power
  • Failsafe timeout: 300 seconds (configurable, 5-300 s)

MQTT

The MQTT source uses OpenDTU's existing MQTT client and subscribes to a configurable grid-power topic.

Supported payloads (configurable "MQTT Data Type"):

  • Raw value: plain numeric values, for example -123.4
  • JSON field: JSON objects containing the configured field — act_power, total_act_power, a_act_power, b_act_power, or c_act_power (Shelly EM / 3EM style payloads, as used in YaSolR)

Retained MQTT messages are ignored because they may contain an old grid value that must not drive regulation.

The MQTT failsafe timeout defaults to 300 seconds (configurable, 5-300 s), allowing slower MQTT publishers than Shelly LNM.

Inverter Power Limits

Zero-Export only sends non-persistent limits:

PowerLimitControlType::AbsolutNonPersistent

The persistent inverter limit is never modified. The controller tracks the last absolute limit it requested per inverter; that value — not the value read back from the inverter — is the starting point of each regulation step.

Startup and Reboot

After a DTU reboot, the previous session's non-persistent limits are no longer known locally; they are reverted by the inverters' own non-persistent-limit timeout.

When Zero-Export starts regulating, each inverter therefore:

  • Adopts the limit currently active in the inverter once it becomes known through the regular SystemConfigPara poll, so regulation starts from reality instead of guessing a value (which could dump a producing inverter's output or leave it unrestrained)
  • Receives no Zero-Export command until the active limit is known; the startup is retried after the poll response arrives
  • Starts at nominal power when the previous operation ended with a 100 % release, because the last command already released the inverter
  • Is initialized only once it becomes reachable and command-enabled (e.g. a night-disabled inverter is initialized in the morning)

Startup commands are additionally deferred until the grid source has delivered a value, so an unavailable source never generates RF traffic.

Unreachable Inverters

When an inverter becomes temporarily unreachable:

  • No new power-control command is queued for it: the radio layer retries unacknowledged commands for a long time, which would block the command queue and delay commands for all other inverters
  • Its last requested limit remains fixed
  • Other reachable inverters absorb the correction when possible
  • It is included again when communication returns

Release commands follow the same queue-safety rule: a pending release or fail-safe is retried on each regulation tick until the inverter is reachable and command-enabled.

Grid Source Failure

The controller distinguishes two situations when no fresh grid value is available:

Startup (no value received yet — module just enabled, source just switched, network just reconnected): this is not an outage. No regulation and no fail-safe happen, and the inverters' current limits are left untouched, so enabling Zero-Export never yanks producing inverters down to the minimum.

Measurement outage (a value existed but has expired): normal regulation is paused, the previous grid value is not reused, and a fail-safe limit is commanded to every reachable, command-enabled inverter. Instead of dropping every inverter to its bare floor, the fail-safe distributes the configured Home Minimal Consumption (default: 0 W) as a total production target proportionally across the inverters pending the command, falling back to the per-inverter minimum production floor (default: 40 W) when it is 0:

  • The fail-safe command is retried per inverter until it could be sent
  • It is deliberately not re-sent on a timer: if the inverter's own non-persistent-limit timeout later reverts it to full power, the regulation loop readjusts as soon as fresh grid values arrive again

The status API exposes the grid power, its age, the effective failsafe threshold, the measured source update period and the active fail-safe state, so a dashboard does not keep displaying a stale value.

MQTT Integration

Zero-Export state is published under dtu/zeroexport/status (enabled, setpoint, production_limit, grid_power_age, grid_update_period, failsafe), and the module can be controlled through dtu/zeroexport/cmd (enabled, setpoint).

Changes received through MQTT are applied live without persisting the configuration, to avoid flash wear.

Regulation Interval

The default regulation interval is 30 seconds (minimum: 5 seconds).

PR #3225 ("feat(hoymiles): early RX exit for faster inverter control") has been merged into the base of this branch: a limit command now completes in its actual round-trip time (~100-150 ms instead of the full 2000 ms RX timeout), and a regulation cycle across 8 HMS inverters takes about 2 seconds instead of ~16. The regulation interval can therefore be reduced down to the 5-second minimum.

Configuration

The Zero-Export configuration includes:

  • Enable/disable switch
  • Grid power setpoint
  • Minimal production power per inverter (default: 40 W, minimum 40 W)
  • Home minimal consumption (default: 0 W) — total production target applied by the fail-safe when the grid source expires
  • Regulation interval (default: 30 s, minimum 5 s)
  • Grid source selection (Shelly LNM / MQTT)
  • Shelly LNM multicast group, UDP port, component power field and failsafe timeout
  • MQTT grid-power topic, data type and failsafe timeout

The configuration is included in the existing config.json export and import flow. The config version was bumped, and older configuration files remain compatible through defaults and migration handling.

Web API

Added endpoints:

GET  /api/zeroexport/config
POST /api/zeroexport/config
GET  /api/zeroexport/status

The status endpoint exposes:

  • Whether the configured grid source is running
  • Grid power and its age (null when no fresh value is available)
  • The effective failsafe timeout of the active source, in seconds (so age > failsafe can be evaluated without a config round-trip)
  • The measured grid update interval (EWMA of the source's sample interval)
  • The currently applied total production limit
  • The active fail-safe state
  • Per-inverter state: serial, name, commanded limit, pending startup / release / fail-safe flags, reachability and command enablement

Home Assistant

When MQTT Home Assistant discovery is enabled, OpenDTU publishes:

  • Zero-Export enable switch
  • Zero-Export setpoint number entity
  • Production Limit sensor
  • Grid Update Interval diagnostic sensor
  • Grid Power Age diagnostic sensor
  • Fail-safe binary sensor (diagnostic)

The enable switch and setpoint can be controlled directly from Home Assistant; the sensors are tied to Zero-Export's availability.

Web Interface

Added a Zero-Export settings page under:

Settings -> Zero-Export

The page provides:

  • Enable/disable control
  • Grid setpoint
  • Home minimal consumption
  • Minimal production power per inverter
  • Regulation interval
  • Grid source selection
  • Shelly LNM configuration (multicast group, port, component power field, failsafe timeout)
  • MQTT configuration (grid-power topic, data type, failsafe timeout)
  • Live status: runtime enabled state, live setpoint, grid power, grid power age, measured grid update interval, and current production limit

Status values refresh automatically every 5 seconds.

The page is available in English, German, and French.

Observability

The controller logs its decisions for on-device diagnosis:

  • Accepted grid values and stale sources
  • Startup limits and their origin (adopted / after release)
  • Skipped commands (unreachable inverters) and slow-source correction factors
  • Fail-safe activation with the distributed limit

For command-queue observability (unique command IDs, enqueue -> TX -> RX -> success/failure lifecycle, queue inspection), see companion PR #3226.

Validation

The following checks pass:

  • Firmware build for generic_esp32s3_usb
  • Webapp production build
  • Webapp Prettier check
  • Configuration export/import integration
  • git diff --check

References

Use Case

Automatic activation of Zero-Export or Full Export with 3ERL in France.

You can have a look at my Home Assistant Dashboard and how I now use OpenDTU + Shelly LNM to regulate my inverters:

https://gist.github.com/mathieucarbou/382556f1279d612962e03232544692d1

I simply need to switch the on/off flag of OpenDTU
And set an appropriate setpoint depending if my EV is plugged for charging or not.

Screenshots

Shelly LNM Setup

Shelly LNM setup

OpenDTU Zero-Export Configuration

Shelly LNM:

image

MQTT

image

Home Assistant Integration

image

Regulation Example

image 655118428-7f79e9e6-420a-427b-9d7a-07e6a36feb7b

@mathieucarbou
mathieucarbou force-pushed the feat/zero-export branch 2 times, most recently from 6840d97 to 40bd9ea Compare September 19, 2026 10:44
@mathieucarbou
mathieucarbou marked this pull request as ready for review September 19, 2026 13:06
@mathieucarbou
mathieucarbou force-pushed the feat/zero-export branch 3 times, most recently from 37e9f14 to 6a0d8e4 Compare September 19, 2026 14:31
@mathieucarbou
mathieucarbou force-pushed the feat/zero-export branch 2 times, most recently from 80a4bf5 to 427cb5e Compare September 20, 2026 07:16
@mathieucarbou mathieucarbou changed the title feat: OpenDTU Zero-Export with Shelly LNM feat: OpenDTU Zero-Export (supports Shelly LNM or MQTT) Sep 20, 2026
@elmr91

elmr91 commented Sep 20, 2026

Copy link
Copy Markdown

Thanks @mathieucarbou,

I'm currently testing your branch (from your repo including your 3 PRs) with MQTT measurement source.
It is working very well with 2xHMS-2000-4T
(BTW, I think I got my fist DTU-NRF24 from you few years ago)

My second HMS is a bit picky about timings and signal, but you branch is working fine.

I wonder if it would be possible to implement a dynamic limit relative to current production:
Limit max power to 20% above live production for example (when current production is too low).

Use case:

  • All inverters are producing few power (under a cloud)
  • It is not enough to reach the configured balance point
  • Inverters limit is then slightly raised until the max 2 kW per inverter
  • When cloud is gone, solar production is then suddenly raising far above the configured limit.
  • It take some time to reduce the production.

We can also imagine to have steps (20, 40, 60, 80, 100 %) and set production limit to the next step above current production.
It may take 1 or more cycles to adjust to a new target if the target is very high, but is will work.

I tweaked the hoymileszeroexport from reserve85 this way ...
It was working fine.

@mathieucarbou

Copy link
Copy Markdown
Contributor Author

I'm currently testing your branch (from your repo including your 3 PRs) with MQTT measurement source.
It is working very well with 2xHMS-2000-4T

Thanks!

Do not forget that the regulation interval has to be configured depending on how fast the power control commands are dequeued. This can be seen in the logs. If you have an inverter relying on timeout and not early exit, then its command power control command could take 2 second to be dequeued.

In my case my HMS-1000-@r work nicely and are all applying power control within 2 sec.

Limit max power to 20% above live production for example (when current production is too low).

It cannot be done easily because if you set an upper limit, it means you are allowing more excess. It is equivalent as setting a negative setpoint to increase the limit. The problem is that you never know if this allowance will lead to some production or not. If yes, then what do you do ? You step back ? You allow more excess ?

So if you play this game with trying to increase the limit always to "see" if it lead to production or not, just in order to place your limit above, you end up creating production and consumption spikes. That's not a good way to regulate.

The current algorithm as it is should be quite immediate because it does not work by reading inverter states.

It works by:

  • reading grid power
  • comparing it so setpoint
  • spreading the difference across live inverters propotionnaly

So if you have a sudden production spike or decrease, the algorithm should adjust that in about 1-3 rounds max, so in my case 30 sec since I set a regulation interval of 10 sec.

@mathieucarbou
mathieucarbou force-pushed the feat/zero-export branch 2 times, most recently from 77210b4 to ac57261 Compare September 20, 2026 12:06
@elmr91

elmr91 commented Sep 20, 2026

Copy link
Copy Markdown

This is the exact same algorithm I'm using.
The only difference is when calculating the new limit:

  • reading grid power
  • compare it to setpoint and calculate the new limit
  • if limit is over current produced power + 20% fullpower, adjust limit (for this round) to this value
  • spread the difference across live inverters proportionaly

Inverters will increase their production (if possible), next round will adjust again if not enough to reach the setpoint.
In all other cases, it will not change anything to current behavior.

The only idea is to avoid to have a limit way too high above what inverters are currently producing.
I already observed spikes of nearly 3 kW on my 4 kW system when weather is 50% cloudy (I'm also living in the "64").
I'm trying not sending too much to the network (they do not like spikes of injection especially over 3 kW)

This will not change at all the global system behavior.

I'm trying to avoid such situation:

  • current production : 500 W (big thick cloud)
  • limit set to 2*2000 W
    If direct sun reaches panels suddenly, system can increase production by few kW in seconds...
    If you set balance point to zero or some negative values, injection can easily go over this 3 kW limit.

@mathieucarbou

mathieucarbou commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Inverters will increase their production (if possible), next round will adjust again if not enough to reach the setpoint.
In all other cases, it will not change anything to current behavior.

Oh! I think I did not understood what you meant by +20%.

If I am correct, you are stepping the increases and decreases to avoid sudden increases or decreases (spikes upon sudden changes) right ?

If so, this is equivalent to introducing a PID fo regulation.
Right now the regulation is a simple PID working on error where the I term would be 1.

It is definitely of course possible to add a PID implementation.

I did one for YaSolR (solar router - https://yasolr.carbou.me/manual/#pid) specially for MCU, that is quite tested and robust and even support a noise reduction feature, and it is in a lightweight lib that OpenDTU could definitely use (https://mathieu.carbou.me/MycilaUtilities/pid).

It even supports proportional on measurements, which helps limit overshoot (that's what you are talking about I think - avoiding overshoots).

But I doubt this would help.

here is my regulation today at ~ -200W since lunch time:

image

And a zoom on a spikes:

image

If you were working with a stepping PID, the grid power would not remain flat but would oscillate more because the sudden change would not be accounted for and would be progressive. So you end up having more excess or consumption.

With the changes did in OpenDTU with others PRs to fasten the com, you are not anymore subject to a slow regulation. Changes are applies immediately in less than 2 seconds. Shelly LNM allows a 1 sec interval data: this is even more precise than what HA gets from MQTT because Shelly's only do MQTT publications when the % change in power is above a threshold. With Shelly LNM this is different: every state is received each second.

And the regulation is fast: each 10 sec in my case but could even be lowered.

So with such second-level scale, there is no need to step the increase or decrease I think...
Especially also because grid providers are monitoring zero-export not on a second scale but on a minute scale.

This would need more testing of course, I can be wrong, but let's see if these cases happen first before introducing a PID.

For example we see in the graph such spike where the grid power bumped to +1000W then -1000W. But these spikes lasted what ? about 10 seconds. Compared to if you were using a PID which would adjust in 2-3 rounds, you would probably consume or inject more maybe ?

@elmr91

elmr91 commented Sep 20, 2026

Copy link
Copy Markdown

I'm using MQTT because my Shelly is Gen1 without LNM support.

For variations within +20% of fullpower (maybe around +1kW in your case) the proposed algorithm would have produced the exact same curve you got (when variations remained within +1 kW range):
image

There would have been slight changes when increasing quickly production:
It would have taken 1 or 2 intermediate steps instead of only one big step:
image

Note : I'm fighting with one of my inverters that sometimes does not want to respond at all (or only 66% sucess).
It is difficult to test today -> It is in a bad mood day.

@mathieucarbou

mathieucarbou commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor Author

I'm using MQTT because my Shelly is Gen1 without LNM support.

Ah! Indeed! Look at what is happening with MQTT grid power reported in HA:

  • in red, all the Shelly values pushed by OpenDTU through MQTT each 5 sec (we do not have better granularity with MQTT publication in OpenDTU sadly)

  • in cyan: all the received grid power from MQTT pushed by Shelly

image

MQTT is slower and misses a lot of values, especially where there is a gradual increase or a short pulse.

image

This spike was seen by OpenDTU who increased production but this was a short spike so then just after decreased production. But it took more time for the Shelly to publish a MQTT update.

So yes, MQTT being slower, in this case, you would definitely benefit of a PID that is ramping up the correction.

=> I can definitely add a variant of that if you are ready to test ? Otherwise if it was just a feature request or idea, just let me know when you have everything setup and ready to test so that you could have at least a before and after comparison. Implementing that is quick.

Note : I'm fighting with one of my inverters that sometimes does not want to respond at all (or only 66% sucess).

I got the same issue with 2 of mine. I went on the roof and discovered that we did not pay attention to the inverter orientation when installing them. Them have a short radio but so many obstacles... I just moved the inverter 1 meter on the roof and installed in the correct orientation for the antenna to have less obstacles.

In my case this was a stupid installation mistake... We did not account for radio com and obstacles.

@elmr91

elmr91 commented Sep 20, 2026 •

Copy link
Copy Markdown

I would be very happy to test and experiment with a tuned regulation.

Shelly Gen1 behave better than new gen regarding MQTT updates.
It can update every second if measurement changes (by few %).
If measurement is still, it updates every 30s maximum (I changed it to 10s max between 2 reports)

Initially my HMS inverters were both working fine.
They are installed under the panels on a nearly flat (10%) iron roof (bac acier).
They both handle a row of 4 panels.

They are installed the same way, antenna on the top.
DTU is 10m away (behind a concrete wall) : -61 dBm for the bottom inverters (HMS1), -68 dBm for the top inverters (HMS2)
I would have expected rather the same signal level for both.
I already lost communication with HMS2 several times.
I think something happened to this one, it has degraded over time.

When it works well, it always has lowest RX success (around 66-75%), the other is 100%

Edit:
I have juste moved my DTU just below the roof where inverters are installed Signal increased to -46/-51 dBm and 2 MHS are online with 100% RX success.
But now WiFi signal is too weak.
I may have to rebuild my DTU with an ESP+external Wi-Fi antenna.

@mathieucarbou

mathieucarbou commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor Author

I would be very happy to test and experiment with a tuned regulation.

I will make up something and let you know. My grid MQTT updates are worse than yours so if the solution works for me it will for you ;-)

There were some appliances stop/start at home and see the mqtt update saw nothing.

image

Shelly Gen1 behave better than new gen regarding MQTT updates.
It can update every second if measurement changes (by few %).

Didn't know!

If measurement is still, it updates every 30s maximum (I changed it to 10s max between 2 reports)

Pay attention to set a regulation interval in OpenDTU that is more than the frequency at which the measurements are coming. Because if you do not do that, you can end up with the same difference between last grid power and setpoint that will be re-applied again, and this causes an over-consumption or excess.

The curent implementation is the equivalent of an integral-only controller with gain 1.
It's unconditionally stable only if the regulation period ≫ source latency + inverter response.

  • With Shelly LNM (1 s updates), a 5–30 s interval gives ~3–10 fresh samples per correction — fine.

  • With a slow MQTT source (say 30 s updates) and a 5 s interval, you need to have a loop interval in zero-export config that is at leats 35 seconds.

@elmr91

elmr91 commented Sep 20, 2026 •

Copy link
Copy Markdown

DTU moved very near from the inverters.

WiFi is in range (low but usable) / MQTT updates are coming quickly when noticeable changes occurred :
image

  • Regulation loop set to 15s
  • Shelly/MQTT set to update at least every 10s (or lower in case of change)
  • Early exit is triggered at every limit change
image

@mathieucarbou

mathieucarbou commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor Author

DTU moved very near from the inverters.

  • Regulation loop set to 15s
  • Early exit is triggered at every limit change

is that better now for the graphs ?

I am currently doing an update to keep track of the last update intervals in an exponential moving average in order to determine the average update interval time for the metrics and consequently provide a limit update that is in function of that. For example, if the calculated average delay is 10 sec to get a new grid power update and the regulation interval is 5 second, then when applying a new power control, half of the value will be applied (something similar).

This is a source-adaptive correction which is automatically spreading the correction to apply across the time.

The advantage of that: user does not need to know that the interval of the regulation has to be larger than the delays at which the grid power is coming.

@elmr91

elmr91 commented Sep 20, 2026

Copy link
Copy Markdown

Example of scenario were home consumption if higher than solar production (+setpoint)

Stable starting point, stable home consumption, setpoint -800W
Solar is producing and limited to 1600W.

[16:31:26.517] I (2467420) zeroexport: Grid -796.7 W, setpoint -800.0 W -> adjusting total limit from 1600 to 1604 W
[16:31:31.673] D (2472579) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-7/7)
[16:31:32.172] I (2472579) zeroexport: Grid Power from MQTT: -815.3 W
[16:31:35.565] D (2476472) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-7/7)
[16:31:36.524] I (2476473) zeroexport: Grid Power from MQTT: -843.9 W
[16:31:36.524] I (2477420) zeroexport: Grid -843.9 W, setpoint -800.0 W -> adjusting total limit from 1604 to 1561 W
[16:31:39.470] D (2480377) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-7/7)
[16:31:40.885] I (2480378) zeroexport: Grid Power from MQTT: -792.2 W
[16:31:40.885] D (2481793) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-7/7)
[16:31:42.177] I (2481793) zeroexport: Grid Power from MQTT: -795.7 W
[16:31:42.278] D (2483132) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-6/6)

Starting a 1200W device.
Home consumption : -800W -> 400W

[16:31:42.278] I (2483133) zeroexport: Grid Power from MQTT: 379.1 W
[16:31:43.447] D (2484355) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-6/6)
[16:31:45.001] I (2484356) zeroexport: Grid Power from MQTT: 359.2 W

Regulation increased limit by nearly 1200W : OK

[16:31:46.515] I (2487420) zeroexport: Grid 359.2 W, setpoint -800.0 W -> adjusting total limit from 1562 to 2722 W
[16:31:47.277] D (2488120) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-6/6)
[16:31:47.277] I (2488120) zeroexport: Grid Power from MQTT: -75.6 W
[16:31:50.201] D (2491110) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-6/6)
[16:31:51.336] I (2491111) zeroexport: Grid Power from MQTT: -72.8 W
[16:31:51.336] D (2491219) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-6/6)
[16:31:51.336] I (2491220) zeroexport: Grid Power from MQTT: -69.4 W
[16:31:51.336] D (2492236) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-6/6)
[16:31:52.188] I (2492237) zeroexport: Grid Power from MQTT: -84.7 W
[16:31:53.480] D (2494388) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-6/6)
[16:31:56.517] I (2494389) zeroexport: Grid Power from MQTT: -85.4 W

But there is not enough solar power to reach the limit
Regulation tries to increase again the limit
This is one case where limiting max power above xx% of current production could make sense

[16:31:56.517] I (2497420) zeroexport: Grid -85.4 W, setpoint -800.0 W -> adjusting total limit from 2722 to 3437 W
[16:31:58.308] D (2499218) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-6/6)
[16:31:59.932] I (2499219) zeroexport: Grid Power from MQTT: -30.9 W
[16:31:59.933] D (2500841) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-6/6)
[16:32:00.443] I (2500842) zeroexport: Grid Power from MQTT: -30.9 W
[16:32:00.443] D (2501353) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-6/6)
[16:32:01.387] I (2501353) zeroexport: Grid Power from MQTT: -79.8 W
[16:32:01.387] D (2502296) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-6/6)
[16:32:02.188] I (2502296) zeroexport: Grid Power from MQTT: -96.5 W
[16:32:03.413] D (2504322) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-6/6)
[16:32:05.768] I (2504322) zeroexport: Grid Power from MQTT: -80.8 W
[16:32:05.768] D (2506676) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-7/7)
[16:32:06.517] I (2506677) zeroexport: Grid Power from MQTT: -108.4 W

Once again regulation increased limit, reaching the max
(I cut a bit of logs below)

[16:32:06.517] I (2507420) zeroexport: Grid -108.4 W, setpoint -800.0 W -> adjusting total limit from 3438 to 4000 W
[16:32:07.289] D (2508119) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-7/7)
[16:32:07.289] I (2508120) zeroexport: Grid Power from MQTT: -107.7 W
[16:32:08.235] D (2509142) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-7/7)
[16:32:12.194] I (2509142) zeroexport: Grid Power from MQTT: -107.7 W
[16:32:12.292] D (2513122) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-6/6)
[16:32:12.292] I (2513124) zeroexport: Grid Power from MQTT: -92.6 W
[16:32:13.347] D (2514255) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-7/7)
[16:32:15.703] I (2514257) zeroexport: Grid Power from MQTT: -102.7 W
[16:32:15.703] D (2516611) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-6/6)
[16:32:16.419] I (2516612) zeroexport: Grid Power from MQTT: -37.5 W
[16:32:16.419] D (2517326) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-6/6)
[16:32:17.198] I (2517327) zeroexport: Grid Power from MQTT: -19.5 W
[16:32:17.198] D (2517421) zeroexport: Grid -19.5 W, setpoint -800.0 W -> no adjustment needed (total limit 4000 W)
[16:32:17.198] D (2517551) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-6/6)
[16:32:17.198] I (2517552) zeroexport: Grid Power from MQTT: -19.5 W
[16:32:17.294] D (2518127) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-4/4)
[16:32:17.294] I (2518128) zeroexport: Grid Power from MQTT: 1.9 W
[16:32:19.204] D (2520111) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-5/5)
[16:32:22.200] I (2520112) zeroexport: Grid Power from MQTT: -8.0 W
[16:32:23.503] D (2524411) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-6/6)
[16:32:26.511] I (2524411) zeroexport: Grid Power from MQTT: -16.3 W
[16:32:26.511] D (2527420) zeroexport: Grid -16.3 W, setpoint -800.0 W -> no adjustment needed (total limit 4000 W)
[16:32:28.094] D (2529003) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-4/4)
[16:32:28.149] I (2529004) zeroexport: Grid Power from MQTT: 2.0 W
[16:32:28.149] D (2529004) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-6/6)
[16:32:28.149] I (2529005) zeroexport: Grid Power from MQTT: -10.2 W
[16:32:28.149] D (2529033) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-5/5)
[16:32:28.149] I (2529034) zeroexport: Grid Power from MQTT: -8.2 W
[16:32:28.149] D (2529035) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-5/5)
[16:32:28.149] I (2529035) zeroexport: Grid Power from MQTT: -8.2 W
[16:32:29.659] D (2529035) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-5/5)
[16:32:29.659] I (2529035) zeroexport: Grid Power from MQTT: -3.0 W
[16:32:29.659] D (2530474) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-4/4)
[16:32:30.119] I (2530477) zeroexport: Grid Power from MQTT: 10.0 W
[16:32:31.581] D (2531095) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-4/4)
[16:32:31.581] I (2531095) zeroexport: Grid Power from MQTT: 6.0 W
[16:32:31.581] D (2532490) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-5/5)
[16:32:32.205] I (2532490) zeroexport: Grid Power from MQTT: 10.7 W
[16:32:35.669] D (2536579) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-5/5)
[16:32:36.511] I (2536579) zeroexport: Grid Power from MQTT: 14.7 W
[16:32:36.512] D (2536798) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-4/4)
[16:32:36.512] I (2536799) zeroexport: Grid Power from MQTT: 0.0 W

************

[16:33:26.510] D (2587420) zeroexport: Grid 4.7 W, setpoint -800.0 W -> no adjustment needed (total limit 4000 W)
[16:33:27.350] D (2588185) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-5/5)
[16:33:27.350] I (2588187) zeroexport: Grid Power from MQTT: 16.9 W
[16:33:28.678] D (2589575) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-5/5)
[16:33:28.978] I (2589577) zeroexport: Grid Power from MQTT: 34.4 W
[16:33:28.978] D (2589658) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-5/5)
[16:33:29.436] I (2589658) zeroexport: Grid Power from MQTT: 34.4 W
[16:33:29.436] D (2590346) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-8/8)

I stopped the 1200W load.
Production is now a bit above -800W setpoint.
Regulation tries to decrease production by lowering the limit
As limit was way too high (max 4000W) above the real solar production, it take many cycles for the limit to take effect.

[16:33:31.480] I (2590347) zeroexport: Grid Power from MQTT: -1096.6 W
[16:33:31.480] D (2592391) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-8/8)
[16:33:32.255] I (2592391) zeroexport: Grid Power from MQTT: -1120.8 W
[16:33:36.512] I (2597420) zeroexport: Grid -1120.8 W, setpoint -800.0 W -> adjusting total limit from 4000 to 3680 W
[16:33:38.135] D (2599045) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-8/8)
[16:33:38.736] I (2599045) zeroexport: Grid Power from MQTT: -1094.5 W
[16:33:46.514] I (2607420) zeroexport: Grid -1094.5 W, setpoint -800.0 W -> adjusting total limit from 3680 to 3386 W
[16:33:47.266] D (2607675) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-8/8)
[16:33:47.266] I (2607676) zeroexport: Grid Power from MQTT: -1099.3 W
[16:33:56.039] D (2616951) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-8/8)
[16:33:56.512] I (2616952) zeroexport: Grid Power from MQTT: -1128.7 W
[16:33:56.512] I (2617420) zeroexport: Grid -1128.7 W, setpoint -800.0 W -> adjusting total limit from 3386 to 3058 W
[16:34:04.883] D (2625795) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-8/8)
[16:34:06.512] I (2625796) zeroexport: Grid Power from MQTT: -1110.5 W
[16:34:06.512] I (2627420) zeroexport: Grid -1110.5 W, setpoint -800.0 W -> adjusting total limit from 3058 to 2748 W
[16:34:13.857] D (2634761) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-8/8)
[16:34:16.512] I (2634763) zeroexport: Grid Power from MQTT: -1102.1 W
[16:34:16.512] I (2637420) zeroexport: Grid -1102.1 W, setpoint -800.0 W -> adjusting total limit from 2748 to 2446 W
[16:34:22.974] D (2643887) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-8/8)
[16:34:26.515] I (2643889) zeroexport: Grid Power from MQTT: -1070.2 W
[16:34:26.515] I (2647420) zeroexport: Grid -1070.2 W, setpoint -800.0 W -> adjusting total limit from 2446 to 2176 W
[16:34:32.002] D (2652911) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-8/8)
[16:34:32.292] I (2652911) zeroexport: Grid Power from MQTT: -1057.5 W
[16:34:33.431] D (2654344) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-8/8)
[16:34:36.512] I (2654344) zeroexport: Grid Power from MQTT: -1057.1 W
[16:34:36.512] I (2657420) zeroexport: Grid -1057.1 W, setpoint -800.0 W -> adjusting total limit from 2176 to 1919 W
[16:34:41.053] D (2661963) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-8/8)
[16:34:42.301] I (2661964) zeroexport: Grid Power from MQTT: -1032.7 W
[16:34:46.514] I (2667420) zeroexport: Grid -1032.7 W, setpoint -800.0 W -> adjusting total limit from 1920 to 1688 W
[16:34:47.403] D (2668234) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-7/7)
[16:34:47.403] I (2668235) zeroexport: Grid Power from MQTT: -829.0 W
[16:34:49.187] D (2670097) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-7/7)
[16:34:49.815] I (2670098) zeroexport: Grid Power from MQTT: -781.1 W
[16:34:49.815] D (2670731) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-7/7)
[16:34:52.304] I (2670731) zeroexport: Grid Power from MQTT: -781.1 W
[16:34:56.512] I (2677420) zeroexport: Grid -781.1 W, setpoint -800.0 W -> adjusting total limit from 1688 to 1707 W
[16:35:00.178] D (2680773) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-7/7)
[16:35:02.312] I (2680775) zeroexport: Grid Power from MQTT: -806.5 W
[16:35:06.511] I (2687420) zeroexport: Grid -806.5 W, setpoint -800.0 W -> adjusting total limit from 1708 to 1702 W
[16:35:12.317] D (2688779) mqtt: Received MQTT message on topic 'shellies/shellyem-E868E7D2B0B5/emeter/0/power' (Bytes 1-7/7)
[16:35:12.317] I (2688779) zeroexport: Grid Power from MQTT: -793.1 W

@elmr91

elmr91 commented Sep 20, 2026

Copy link
Copy Markdown

The algorithm is OK as soon as solar is producing enough.
It works less well in under production cases if we let the limit going too far from the effective production.

@mathieucarbou

Copy link
Copy Markdown
Contributor Author

The algorithm is OK as soon as solar is producing enough. It works less well in under production cases if we let the limit going too far from the effective production.

I am testing the new algorithm that is auto-correcting the new limites based on the EMA of the measurement delays.

image

I still have the regulation loop running each 10 sec, but this time, with my infrequent grid power updates.

You can see that the algorithm now paces the increases or decreases (steps in graphs) based on the delays these updates were received.

If the regulation loop is faster than the measurement delays, some warnings are shown in the logs to display the % of correction applied:

[17:08:04.958] W (716386) zeroexport: Slow grid source (period 23478 ms): correction factor: 39%
[17:08:14.943] W (726386) zeroexport: Slow grid source (period 21052 ms): correction factor: 43%
[17:08:24.940] W (736386) zeroexport: Slow grid source (period 21052 ms): correction factor: 43%
[17:08:34.943] W (746386) zeroexport: Slow grid source (period 21052 ms): correction factor: 43%
[17:08:44.976] W (756386) zeroexport: Slow grid source (period 21052 ms): correction factor: 43%
[17:08:54.939] W (766386) zeroexport: Slow grid source (period 21052 ms): correction factor: 43%
[17:09:02.558] W (773654) zeroexport: Zero-Export MQTT payload on homeassistant/states/sensor/grid_power/state could not be parsed as grid power
[17:09:14.948] W (786387) zeroexport: Slow grid source (period 20850 ms): correction factor: 44%
[17:09:25.440] W (796886) zeroexport: Slow grid source (period 17012 ms): correction factor: 53%
[17:09:55.439] W (826886) zeroexport: Slow grid source (period 9480 ms): correction factor: 87%
[17:10:15.477] W (846256) hoymiles: All missing
[17:10:15.477] W (846256) hoymiles: Nothing received, resend whole request: [1194] RealTimeRunData (1410a01e2cdd)
[17:11:08.313] W (899767) zeroexport: Zero-Export MQTT payload on homeassistant/states/sensor/grid_power/state could not be parsed as grid power
[17:11:15.940] W (907386) zeroexport: Slow grid source (period 12184 ms): correction factor: 71%
[17:11:25.978] W (917386) zeroexport: Slow grid source (period 10387 ms): correction factor: 81%
[17:11:38.721] W (929522) hoymiles: All missing
[17:11:38.721] W (929522) hoymiles: Nothing received, resend whole request: [1315] ActivePowerControl (HMS, 00) (1410a01f010c)
[17:12:21.385] W (972831) zeroexport: Zero-Export MQTT payload on homeassistant/states/sensor/grid_power/state could not be parsed as grid power
[17:12:26.444] W (977886) zeroexport: Slow grid source (period 13970 ms): correction factor: 63%
[17:12:36.444] W (987886) zeroexport: Slow grid source (period 13970 ms): correction factor: 63%

I discovered that besides being infrequent, HA also published unavailable sometimes lol in case Shelly does not update in time 😆 I really have the poorest MQTT use case lol so this should be better on your side.

@mathieucarbou

mathieucarbou commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor Author

@elmr91 : you can install v26.3.30-mathieu8 ;-) I did also and will keep it running tomorrow also to see how it behaves with bigger load spikes.

Works fine with a source-adaptive correction:

image

and this is on my poor MQTT setup ;-)

@elmr91

elmr91 commented Sep 20, 2026

Copy link
Copy Markdown

I have installed the latest beta few minutes ago.

Here are some graphs from this afternoon (previous beta)
image
We can see AC power following production limit by few seconds.

Load spike (17:43) has been well handled -> 5 seconds measured before increasing power and back to setpoint -800W
image

Problems are only when production is too low to reach setpoint -> limit is slightly increasing up to the max.
This is where I want to stop the raising of the limit (to some amount above the current production)
image

@mathieucarbou

mathieucarbou commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Today:

image
  • production is ramping up, regulation ensures the production limit is targeting -200W (my setpoint).

  • EV car plugged, OpenEVSE starts charging and try to take as much power as it can, regulation automatically increases the production limit and sets it to 30% more than the current solar production to give some room for increases without allowing too much space to speed up decreases

  • 5 PM: zero-export turned off: no effect since EV charging is still on and makes sure to only charge on the excess power

  • Some communication issues: shelly lnm paquets delayed so failsafe mode activated for a short time. I pushed a fix to set to 300 seconds (5min) the failsafe timeout. By default it was too short and was activating failsafe mode for transiant communication issues.

Conclusion

Everything is working pretty well!

v26.3.30-mathieu14 was releases which brings support for Shelly 3EM both in 3-phase and single-phase use cases.

@mathieucarbou
mathieucarbou force-pushed the feat/zero-export branch 2 times, most recently from 3774936 to a8ff7a2 Compare September 24, 2026 10:39
@mathieucarbou

Copy link
Copy Markdown
Contributor Author

New release: v26.3.30-mathieu15

Bugfix for MQTT and clear separation between the persisted config used at startup and the live config (enable and setpoint) used at runtime that can be changed through Home Asisstant

image image

@mathieucarbou
mathieucarbou force-pushed the feat/zero-export branch 2 times, most recently from 7af97d8 to a36caf3 Compare September 25, 2026 07:09
@elmr91

elmr91 commented Sep 28, 2026

Copy link
Copy Markdown

You last build (18) is running fine for the whole week-end.
It may be worth including this PR #2584 (it should avoid HA to record a wrong energy value at every DTU restart/upgrade).

@mathieucarbou

Copy link
Copy Markdown
Contributor Author

You last build (18) is running fine for the whole week-end. It may be worth including this PR #2584 (it should avoid HA to record a wrong energy value at every DTU restart/upgrade).

Yes I am also quite happy with the result it is running fine on my side also!
And a lot of included fixes will be soon in next OpenDTU version.

I've looked at the PR and its state and it would need some cleanup, rebase and extracting a fix out of it.

I am also irritated by that, and now do not use these sensors anymore. They give wrong values in case some inverters are unreachable, besides creating stat jumps yes.

The way the PR solves that by making the sensor unavailable is good. It just needs to be cleaned up though.

@elmr91

elmr91 commented Sep 29, 2026 •

Copy link
Copy Markdown

Hi @mathieucarbou ,

I noticed some non symmetric exchanges with inverters:
My second DTU has only 2 HMS-200-4T configured (8 panels side by side : 2 inverters have 99% time the same solar/output power).

I notice the polling rate of both are not identical.
I reset radio message counters for both at the same time.
After 10 minutes, DTU has sent 105 radio messages to the first one and 165 to the second one.

image image

I'm not familiar with Hoymiles radio protocol, but it seems strange.
I was expecting roughly the same message count for both (no retransmission at all).

I recorder console logs during these 10 minutes.
opendtu-log-2026-09-29_14-13-07.txt

Edit: There are 2 kinds of expected message sent to the inverters:
RealTimeRunData (normal polling) and ActievPowerControl -> same amount of message sent to both inverters.
This is expected behavior.

image

But there are lots of AlarmData messages sent to the second inverter only.
Nearly one message per polling cycle (10s).

@mathieucarbou

Copy link
Copy Markdown
Contributor Author

@elmr91 : you are running with the new firmware -19 ?
Because it was rebased on master and got a lot of merges between -18.
If this happeared between -18 and -19, them maybe this is something that was merged in master.
Otherwise if not, maybe upgade and check again.
FYI I also have sometimes some transmission loss and the request is retried. Seems normal to be to have some radio transmission loss.

@elmr91

elmr91 commented Sep 29, 2026 •

Copy link
Copy Markdown

@elmr91 : you are running with the new firmware -19 ? Because it was rebased on master and got a lot of merges between -18. If this happeared between -18 and -19, them maybe this is something that was merged in master. Otherwise if not, maybe upgade and check again. FYI I also have sometimes some transmission loss and the request is retried. Seems normal to be to have some radio transmission loss.

I noticed only today you have released beta19 with rebase.
I noticed this problem while running beta18.
I'll upgrade to beta19 within few minutes and watch for AlarmData.
I don't understand why DTU is requesting AlarmData every poll cycle (and is receiving answers for every request).

Edit: beta19 is behaving exactly the same way regarding AlarmData
(sent every cycle only to one inverter)

@mathieucarbou

Copy link
Copy Markdown
Contributor Author

I don't understand why DTU is requesting AlarmData every poll cycle (and is receiving answers for every request).

Do you know if this is new or was there with last release ?

Maybe worth opening an issue or discussion also ?

@tbnobody

Copy link
Copy Markdown
Owner

Edit: beta19 is behaving exactly the same way regarding AlarmData
(sent every cycle only to one inverter)

Just checked it here. definetely not the case. with yesterdays release (Just have a 4 channel HM and 4 Channel HM available for testing)

@mathieucarbou

mathieucarbou commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

@tbnobody @elmr91 : fyi checked my logs in debug and I don't see any, whether zero-export is enabled at 10 sec interval or not...
Running with v26.3.30-mathieu19 since yesterday.
8x HMS-1000-2T, poll interval 5 sec, and that:
image

@elmr91

elmr91 commented Sep 29, 2026

Copy link
Copy Markdown

@tbnobody @elmr91 : fyi checked my logs in debug and I don't see any, whether zero-export is enabled at 10 sec interval or not... Running with v26.3.30-mathieu19 since yesterday. 8x HMS-1000-2T, poll interval 5 sec, and that: image

I have the exact same settings.
It happens only on one inverter.

I will try to understand how it is supposed to work between DTU and inverters regarding alarm buffer.
I'm pretty sure there is something unusual on this inverter.

@mathieucarbou

Copy link
Copy Markdown
Contributor Author

I'm pretty sure there is something unusual on this inverter.

Did you check its firmware version and grid profile to see if there is a difference with the other one ?

@tbnobody

Copy link
Copy Markdown
Owner

@mathieucarbou when did you rebase to the latest master? Was beta18 still running with the source of 26.3.30?
I am just wondering when this behavior was introduced.

@mathieucarbou

Copy link
Copy Markdown
Contributor Author

@mathieucarbou when did you rebase to the latest master? Was beta18 still running with the source of 26.3.30? I am just wondering when this behavior was introduced.

Yesterday after all your merges i rebased and created -19.

-18 was based on master before all your merges.

but @elmr91 seemed to had the issue in -18 as he told above also so that’s why I asked him above if the behavior was also there with last release.

I agree that finding when the issue started would be nice but for that he needs first to reflash the last release and check.

@mathieucarbou

Copy link
Copy Markdown
Contributor Author

@tbnobody @elmr91 : please have a look at #3254 for the alarmdata issue.

@mathieucarbou
mathieucarbou marked this pull request as ready for review September 29, 2026 20:44
@mathieucarbou

mathieucarbou commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

@tbnobody : Just to let you know:

I am moving this zero-export feature from draft to ready in a way to mean that users can now pull it and use it.
It works fine and was tested since several days with different grid sources.

The feature was written in a way to easily add more grid sources, although I would IMO not add any grid source relying on polling like calling a REST API or TCP Modbus in order to not add extra libraries or memory usage in this project.

The current grid source implementations do not add any big overhead since they are using UDP and MQTT which are already used in OpenDTU.

A "quick and simple" Zero-Export feature in OpenDTU is a nice addition I think, especially that it integrates well with Home Assistant and allows a Zero-Export control of inverters without requiring any external Home Assistant for the control loop. I'm a big fan of simple/efficient/isolated features like that which solves probably 80% of the use cases for people who need Z-E because in France people having a solar installation are more and more required or advised to activate Z-E. So this feature mimics what's available from Hoymiles (DTU Pro + DDSU). It plays well will the current electrical constraints in Europe where electricity prices are falling into negative values and Zero-Export is becoming more and more common / required.

If one day you think about accepting it in the project and need help / rebase / changes, please let me know 👍

Note: if the feature is accepted I will create a PR in https://github.com/tbnobody/OpenDTU-docs/tree/master/docs for the doc and internal working algorithm (how production limit caps, source-adaptive algorithm and failsafe are working)

@mathieucarbou

Copy link
Copy Markdown
Contributor Author

v26.3.30-mathieu21 was released which also includes a bunch of fixes not yet merged.

@mathieucarbou

Copy link
Copy Markdown
Contributor Author

Latest OpenDTU Zero-Export release v26.11.11-ze1 rebased on latest OpenDTU version v26.11.11

…d sources

Add a Zero-Export module that regulates Hoymiles inverter power limits so
that the grid power stays around a configurable setpoint (default: 0 W,
i.e. neither export to nor import from the grid), based on the grid
power received from a configurable grid source.

Two sources are currently available:

- Shelly LNM (Local Network Messaging): Shelly meters stream LNM status
  messages through UDP multicast, avoiding periodic HTTP polling. OpenDTU
  listens with WiFiUDP and processes incoming datagrams from the
  scheduler without blocking inverter communication. The wire format is
  a 12-byte binary header starting with the "SL" magic followed by a
  JSON payload (em1:0 / em:0 / etc.) whose act_power field carries the
  grid power.

- MQTT: any power meter publishing a plain numeric value or a JSON
  object with an act_power / total_act_power field (Shelly EM / 3EM
  style) can be used by subscribing to a configurable "Grid Power Topic"
  on the existing OpenDTU MQTT client. Retained messages are ignored so
  stale retained values never drive the regulation.

Grid sources are modelled as a small ZeroExportGridSource interface that
tracks measurement freshness, estimates the source update period as an
EWMA of the intervals between accepted samples, and enforces a
per-source fail-safe timeout. Adding a new source means implementing
the interface and adding a switch case.

The regulation loop reads the grid power from the active source and
distributes the needed correction proportionally to the inverters'
rated power, never commanding an inverter below a configurable minimal
production (default: 40 W per inverter). Inverters that are temporarily
unreachable keep their last commanded limit while the others
compensate. Upward corrections are damped for slow sources, using the
measured source period plus the estimated inverter response latency, to
avoid overshoot; downward corrections remain immediate to reduce
export. The tracked state is the set of limits this controller has
requested, not the values read back from the inverters (the one-time
startup adoption below is the only exception).

Safety behavior:

- Limits are only ever sent to reachable, command-enabled inverters.
- On disable, a RelativNonPersistent 100 % release is sent and retried
  each regulation tick until every command-enabled inverter has
  received it.
- After a DTU restart, limits left by a previous session are reverted
  by the inverters' own non-persistent-limit timeout; nothing is
  commanded until regulation is established. On startup each inverter
  adopts the limit currently active in the inverter once it becomes
  known through the regular SystemConfigPara poll, instead of guessing
  one, so a producing inverter is never yanked to another value.
  Re-enabling after a release starts at nominal power.
- When a grid measurement existed but has expired (measurement
  outage), a minimum-production fail-safe is commanded once per
  inverter and retried until it could be sent. It is deliberately not
  kept alive: if the inverter's own non-persistent-limit timeout
  reverts it to full power, the regulation loop readjusts as soon as
  fresh grid values arrive again.
- A source that has not delivered a single value yet (module just
  enabled, source just switched, network just reconnected) is a
  startup condition, not an outage: no RF traffic is generated and the
  inverters' limits are left untouched.
- Requested limits are capped above the currently measured production
  (with headroom), so they cannot drift far above what the inverters
  actually produce. The cap's base never drops below the enforced
  per-inverter floor sum, so a low-light start can always ramp up
  again.

The default regulation interval is 30 seconds (allowed range: 5-3600
seconds). With the current radio layer, each command occupies the
radio for its full RX timeout and the command queue also carries the
regular poll requests, so a 30 s interval leaves room for a full poll
cycle and for the grid source to measure the effect of a correction.
Once tbnobody#3225 ("feat(hoymiles): early RX exit for faster
inverter control") is merged, a limit command completes in its actual
round-trip time (~100-150 ms instead of the full 2000 ms timeout) and a
regulation cycle across 8 HMS inverters takes about 2 seconds instead
of ~16, which would allow reducing the regulation interval to the
5-second minimum.

The settings page exposes:

- Enable/disable switch
- Grid power setpoint
- Minimum production power per inverter (minimum 40 W)
- Regulation interval (5-3600 seconds)
- Grid source dropdown (Shelly LNM / MQTT)
- Shelly LNM multicast group, port and fail-safe timeout
  (defaults: 239.255.55.55:5555, 10 s)
- MQTT grid power topic and fail-safe timeout (default: 30 s)
- Live status with a 5-second refresh: grid power, measured grid
  update interval, and the currently applied production limit

The status API additionally reports per-inverter state (commanded
limit, pending startup / release / fail-safe flags, reachability,
command enablement).

Zero-Export state is published under dtu/zeroexport/status (enabled,
setpoint, production_limit, grid_update_period), and the module can be
controlled through dtu/zeroexport/cmd (enabled, setpoint). Changes
received through MQTT are applied live without persisting the
configuration to avoid flash wear.

Home Assistant integration (when MQTT auto-discovery is enabled)
publishes a switch (enabled), a setpoint number, a production-limit
sensor and a grid-update-interval diagnostic sensor; the switch and
the setpoint can be changed from Home Assistant.
@mathieucarbou

Copy link
Copy Markdown
Contributor Author

Latest OpenDTU Zero-Export release v26.11.11-ze2 rebased on latest OpenDTU version v26.11.11

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.

3 participants