Martin's corner on the web

Driving our BYD battery from Home Assistant over Modbus TCP

Our rooftop PV feeds a 7.7 kWh BYD battery through a Fronius GEN24 inverter. Left alone, the inverter charges the battery whenever there is surplus and empties it whenever the house draws power. That is fine for a simple setup, but the house knows much more than the inverter: the night tariff, the PV forecast for the rest of the day, the battery temperature, when the car charges. I wanted the battery to act on all of that, so Home Assistant controls it directly.

The GEN24 exposes the battery controls over Modbus TCP (SunSpec storage model), and Home Assistant has a native Modbus integration, so there is nothing in between. The one thing that took me a while: a charge or discharge limit only sticks if you write the whole group of registers, one at a time, with the revert timer before the control mode and the mode last. If you write only the rate, the inverter ignores it.

What it does here:

  • Night tariff. At night we buy cheap from the grid and the battery sits still. Shortly before sunrise it powers the house again, timed to run down to my reserve as the sun comes up.
  • Charging paced by the forecast. On a sunny day the battery charges slowly and fills through the day instead of in the first sunny hours.
  • Summer ceiling. When the cells are warm, charging stops short of full.
  • Balance charge. If the pack hasn’t been full for a while, it tops up from the grid at night, so the BMS recalibrates (owners on the BYD thread on photovoltaikforum.com warn that a battery that never gets to 100% can lose 10–15% of its capacity after a while).
  • Presets. Hold, charge only, force charge from the grid, eco: one tap on the dashboard.
  • Watchdog. If the battery starts feeding the grid with no reason to, Home Assistant puts the inverter back to automatic and tells me.

I can’t do this from the Fronius app alone, it has a SoC range in one menu and a timed charge power limit in another and nothing ties the charge power to the battery level.

This has been extremely useful to me. The code is in a gist.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.