Skip to content

BYD Battery-Box Binding ​

This binding reads the BYD Battery-Box Premium HVS/HVM home batteries over your local network. Its focus is long-term monitoring of the battery's health: every cell voltage and cell temperature, balancing, state of charge and state of health, and the battery's own event logs. All values can be persisted and used in rules, for example to be alerted when the voltage spread between the cells grows.

The binding only reads from the battery and never changes its settings. To get fresh cell values and the event log, it asks the battery to measure its cells and to load its log, as the BYD configuration tool does. For towers with 160 cells, an additional measurement can be enabled, see Towers With 160 Cells.

Supported Things ​

Thing TypeDescription
hv-premiumOne BYD Battery-Box Premium HVS/HVM system, addressed through its BMU (battery management unit)

Towers and modules are not separate Things, but channel groups of the hv-premium Thing. Channel groups are defined for up to 3 towers with up to 8 modules each. After the first reading, the binding removes the channels of towers and modules your battery does not have.

BatteryStatus
Battery-Box Premium HVS, BMU firmware 3.xTested (HVS 7.7, 1 tower with 3 modules)
Battery-Box Premium HVS with 5 modulesTested with recorded data of 2 towers with 5 modules each; see Towers With 160 Cells
Battery-Box Premium HVMUntested, but expected to work (16 cells and 8 temperature sensors per module)
Several towers in parallelTested with recorded data of 2 towers
Battery-Box Premium HVLPartly supported: status values and event logs, no tower and cell details yet; see Help Wanted: HVL Owners
Battery-Box Premium LVSNot supported. Status values may work, cell details are not available.
Battery-Box HVB / BCU 2.0Not supported

Help Wanted: HVL Owners ​

With a Battery-Box Premium HVL, the binding reads the status values and the event logs, but no tower and cell details. The cell layout of HVL modules is not known yet, and no HVL system was available for testing. If you own an HVL and would like to help, please get in touch in the community thread. A short recording of the battery's answers, taken with a script on any computer in your network, is enough to add tower and cell details for HVL.

Before You Start ​

Only One App at a Time ​

The battery accepts only one connection at a time. While the BYD app (Be Connect), another tool or another home automation system is connected to the battery, openHAB cannot read it, and the Thing goes OFFLINE with the message that another client is probably connected. openHAB connects only for the few seconds a reading takes, so you can use the BYD app between two readings. If the battery is busy, the binding tries again later, waiting longer after each failed attempt (at most 15 minutes).

Connecting the Battery to Your Network ​

The battery is reached on port 8080, in one of two ways:

  • Ethernet: the LAN port of the BMU, connected to your home network. Look up the address the battery received from your router (DHCP server).
  • Wi-Fi access point: the BMU's own access point, with the battery at 192.168.16.254. The openHAB host, or another host in between, needs a Wi-Fi interface connected to this access point with a static address, e.g. 192.168.16.50/24, and no default route.

If openHAB runs on a different host than the one connected to the battery's access point, forward the port on the connected host, for example with socat:

bash
socat TCP-LISTEN:8080,fork,reuseaddr,max-children=1 TCP:192.168.16.254:8080

Then enter the address of the forwarding host as hostname. The one-connection limit still applies: an app connected through the forwarding host and an app connected directly to the battery still exclude each other.

Discovery ​

Discovery is not supported, because the battery cannot be found automatically on the network. Add the Thing manually with its hostname or IP address.

Thing Configuration ​

hv-premium Thing Configuration ​

NameTypeDescriptionDefaultRequiredAdvanced
hostnametextHostname or IP address of the battery, or of the forwarding hostN/Ayesno
portintegerPort of the battery8080noyes
refreshIntervalintegerSeconds between two status readings (minimum 30)60nono
detailIntervalintegerSeconds between two cell measurements, 0 turns them off600nono
eventLogIntervalintegerSeconds between two event log readings (at least 150), 0 turns them off600nono
readExtendedCellsbooleanAlso read cells 129–160 of towers with 5 modules, see Towers With 160 Cellsfalsenoyes
connectionTimeoutintegerSeconds to wait for the battery to connect and to answer5noyes

Cell measurements and event logs are read together with a status reading. Their intervals are therefore rounded up to a multiple of refreshInterval: with refreshInterval=60, a detailInterval of 90 seconds results in a cell measurement every 120 seconds. A cell measurement takes about 2–3 seconds per tower; during that time, the BYD app cannot connect.

Towers With 160 Cells ​

In a regular measurement, the battery reports at most 128 cell voltages per tower. An HVS tower with 5 modules has 160 cells, so the cell voltages and the module voltage of its 5th module stay UNDEF; its temperatures are always available.

With readExtendedCells enabled, the binding requests a second measurement for such towers to get cells 129–160, the same way other integrations (ioBroker, Home Assistant, smarthomeNG) do. BYD does not document this measurement; on the tested system, it affected nothing beyond that one measurement. It adds about 3 seconds per tower to each cell measurement. Towers with at most 128 cells are never measured twice.

The number of balancing cells includes the 5th module only with the option enabled, and has not yet been verified for that module.

Properties ​

PropertyDescription
serialNumberSerial number of the system, as reported by the battery
modelIdModule type: HVS or HVM
firmwareVersionBMU firmware currently in use, e.g. 3.26-B
bmuFirmwareA, bmuFirmwareBBMU firmware in slot A and slot B
bmsFirmwareBMS firmware currently in use
towersNumber of towers
modulesPerTowerNumber of modules per tower
cellsPerModuleNumber of cells per module
temperatureSensorsPerModuleNumber of temperature sensors per module
nominalCapacityCapacity of the system when new, e.g. 7.68 kWh (HVS and HVM only, see Capacity)
parameterTableVersion of the parameter table
inverterTypeInverter setting of the battery, e.g. Fronius HV (0), or only the number if the name is not known
applicationApplication setting of the battery: Off Grid (0), On Grid (1) or Backup (2), or only the number if the name is not known
phasePhase setting of the battery: Single-phase (0) or Three-phase (1), or only the number if the name is not known
tower<n>SerialNumberSerial number of the BMS of tower n (after the first cell measurement)
tower<n>FirmwareBMS firmware of tower n, slot A and slot B

Channels ​

The current is positive while the battery discharges and negative while it charges, as reported by the battery. The same applies to the power.

Group status ​

Updated every refreshInterval.

ChannelTypeDescription
state-of-chargeNumber:DimensionlessState of charge (1 % resolution)
state-of-healthNumber:DimensionlessState of health
voltageNumber:ElectricPotentialBattery voltage
output-voltageNumber:ElectricPotentialVoltage at the battery output, behind the main relay
currentNumber:ElectricCurrentBattery current
powerNumber:PowerBattery power, calculated from current and output voltage
max-cell-voltageNumber:ElectricPotentialHighest cell voltage (10 mV resolution)
min-cell-voltageNumber:ElectricPotentialLowest cell voltage (10 mV resolution)
cell-voltage-spreadNumber:ElectricPotentialHighest minus lowest cell voltage (10 mV resolution)
max-cell-temperatureNumber:TemperatureHighest cell temperature
min-cell-temperatureNumber:TemperatureLowest cell temperature
bmu-temperatureNumber:TemperatureTemperature of the BMU
charged-energyNumber:EnergyLifetime charged energy
discharged-energyNumber:EnergyLifetime discharged energy
efficiencyNumber:DimensionlessLifetime discharged energy divided by lifetime charged energy
usable-capacityNumber:EnergyNominal capacity reduced by the state of health, see Capacity
stored-energyNumber:EnergyEnergy currently stored: usable capacity multiplied by the state of charge
errorSwitchON while the battery reports a system error
errorsStringThe system errors as text, or None

Capacity ​

The battery does not report its capacity, so the binding calculates it from the number of towers and modules: 2.56 kWh per HVS module and 2.76 kWh per HVM module. An HVS 7.7 with 3 modules has a nominal capacity of 7.68 kWh.

  • usable-capacity is the nominal capacity multiplied by the state of health: with a state of health of 94 %, the HVS 7.7 has 7.22 kWh left.
  • stored-energy is the usable capacity multiplied by the state of charge: at 50 %, it holds 3.61 kWh.
  • Each tower has its own usable-capacity and stored-energy, calculated from its own state of health and state of charge; the usable capacity shows whether one tower ages faster than the others.

These values are only as precise as the state of charge and state of health reported by the battery, in steps of 1 %. For batteries with an unknown module type, such as the HVL, they are UNDEF.

Group tower-<n> ​

One group per tower, updated every detailInterval. Minimum, maximum, average and spread cover all cells of the tower; cells and sensors are numbered from 1 within the tower.

ChannelTypeDescription
state-of-chargeNumber:DimensionlessState of charge (0.1 % resolution)
state-of-healthNumber:DimensionlessState of health
voltageNumber:ElectricPotentialTower voltage
output-voltageNumber:ElectricPotentialVoltage at the tower output, behind the main relay
currentNumber:ElectricCurrentTower current
powerNumber:PowerTower current × tower output voltage
charged-energyNumber:EnergyLifetime charged energy of the tower (Wh resolution)
discharged-energyNumber:EnergyLifetime discharged energy of the tower (Wh resolution)
usable-capacityNumber:EnergyNominal capacity of the tower reduced by its state of health
stored-energyNumber:EnergyUsable capacity of the tower multiplied by its state of charge (0.1 % resolution)
efficiencyNumber:DimensionlessLifetime discharged energy of the tower divided by its lifetime charged energy (advanced)
max-cell-voltageNumber:ElectricPotentialHighest cell voltage
max-cell-voltage-cellNumberNumber of the cell with the highest voltage
min-cell-voltageNumber:ElectricPotentialLowest cell voltage
min-cell-voltage-cellNumberNumber of the cell with the lowest voltage
average-cell-voltageNumber:ElectricPotentialAverage cell voltage
cell-voltage-spreadNumber:ElectricPotentialHighest minus lowest cell voltage (1 mV resolution)
max-cell-temperatureNumber:TemperatureHighest cell temperature
max-cell-temperature-sensorNumberNumber of the sensor with the highest temperature
min-cell-temperatureNumber:TemperatureLowest cell temperature
min-cell-temperature-sensorNumberNumber of the sensor with the lowest temperature
average-cell-temperatureNumber:TemperatureAverage temperature of all sensors of the tower
balancing-cellsNumberNumber of cells currently being balanced
warningSwitchON while the tower reports a warning
warningsStringThe tower warnings as text, or None
errorSwitchON while the tower reports an error
errorsStringThe tower errors as text, e.g. Main relay failure, or None

Group tower-<n>-module-<m> ​

One group per module, updated every detailInterval. Module m holds cells (m-1) × 32 + 1 to m × 32 of the tower for HVS (16 cells per module for HVM), in the order the battery reports them. HVM modules only have the channels cell-voltage-01 … cell-voltage-16 and cell-temperature-01 … cell-temperature-08. A module's balancing-cells and balancing-cell-numbers show which module and which cells the battery keeps balancing, an early sign of a weak module. They are UNDEF for the 5th module of a 160-cell tower without readExtendedCells. Cell and sensor numbers count from 1 within the module.

ChannelTypeDescription
voltageNumber:ElectricPotentialSum of the cell voltages of the module
max-cell-voltageNumber:ElectricPotentialHighest cell voltage of the module
max-cell-voltage-cellNumberNumber of the cell with the highest voltage, 1–32 within the module
min-cell-voltageNumber:ElectricPotentialLowest cell voltage of the module
min-cell-voltage-cellNumberNumber of the cell with the lowest voltage, 1–32 within the module
average-cell-voltageNumber:ElectricPotentialAverage cell voltage of the module
cell-voltage-spreadNumber:ElectricPotentialHighest minus lowest cell voltage of the module
max-cell-temperatureNumber:TemperatureHighest temperature of the module
max-cell-temperature-sensorNumberNumber of the sensor with the highest temperature, 1–12 within the module
min-cell-temperatureNumber:TemperatureLowest temperature of the module
min-cell-temperature-sensorNumberNumber of the sensor with the lowest temperature, 1–12 within the module
average-cell-temperatureNumber:TemperatureAverage temperature of the module
balancing-cellsNumberNumber of cells of the module currently being balanced (advanced)
balancing-cell-numbersStringCells of the module currently being balanced, e.g. 5, 17, or None (advanced)
cell-voltage-01 … cell-voltage-32Number:ElectricPotentialVoltage of each cell (HVM: 01 … 16)
cell-temperature-01 … cell-temperature-12Number:TemperatureTemperature of each sensor (HVM: 01 … 08)

Group events ​

Updated every eventLogInterval from the logs of the BMU and of each tower.

ChannelTypeDescription
last-eventStringNewest log entry, e.g. BMS 1: Stop discharging (SoC 7 %, 305.3 V, 0.0 A)
last-event-timeDateTimeTime of the newest log entry
eventTriggerFired once for every new log entry, oldest first, with the source and event code as payload, e.g. BMS1:7

When a reading finds several new entries, last-event and last-event-time show the newest of them, while the trigger fires once for each entry. A rule triggered by event should therefore take the entry from its payload (receivedEvent), not from last-event.

The battery keeps several weeks of entries per unit and hands them out in pages of 20, newest first. Each request returns the next older page, and only after a pause of about two minutes does the battery start at the newest page again. The binding therefore reads the event logs at most every 150 seconds, also when eventLogInterval is set lower or a reading failed. If more than 20 entries were written since the previous reading, it reads up to 5 pages, so that up to 100 new entries fire the trigger. After a restart of openHAB or of the binding, entries that were already in the log do not fire the trigger again; only newer entries do. The battery clock is not set automatically, so the binding corrects the times of the log entries by the measured deviation (see bmu-clock-offset).

Group diagnostics ​

ChannelTypeDescription
bmu-clock-offsetNumber:TimeHow far the battery clock, taken as UTC, is ahead of the openHAB clock; negative when it is behind
last-detail-updateDateTimeTime of the last successful cell measurement

Full Example ​

Thing Configuration ​

dsl
Thing bydbatterybox:hv-premium:home "BYD Battery-Box" [ hostname="192.168.69.9", refreshInterval=60, detailInterval=600, eventLogInterval=600 ]

Item Configuration ​

dsl
Group gBattery "Battery" ["Battery"]

Number:Dimensionless     BYD_SoC          "State of Charge [%.0f %%]"     <batterylevel> (gBattery) ["Measurement", "StateOfCharge"] { channel="bydbatterybox:hv-premium:home:status#state-of-charge" }
Number:Dimensionless     BYD_SoH          "State of Health [%.0f %%]"                    (gBattery) ["Measurement"]                  { channel="bydbatterybox:hv-premium:home:status#state-of-health" }
Number:Power             BYD_Power        "Power [%.0f W]"                               (gBattery) ["Measurement", "Power"]         { channel="bydbatterybox:hv-premium:home:status#power" }
Switch                   BYD_Error        "Error"                                        (gBattery) ["Alarm"]                        { channel="bydbatterybox:hv-premium:home:status#error" }
String                   BYD_Errors       "Errors [%s]"                                  (gBattery) ["Status"]                       { channel="bydbatterybox:hv-premium:home:status#errors" }

Number:ElectricPotential BYD_CellSpread   "Cell Spread [%.0f mV]"                        (gBattery) ["Measurement", "Voltage"]       { channel="bydbatterybox:hv-premium:home:tower-1#cell-voltage-spread", unit="mV" }
Number:ElectricPotential BYD_CellMin      "Lowest Cell [%.0f mV]"                        (gBattery) ["Measurement", "Voltage"]       { channel="bydbatterybox:hv-premium:home:tower-1#min-cell-voltage", unit="mV" }
Number                   BYD_CellMinNo    "Lowest Cell No. [%d]"                         (gBattery)                                  { channel="bydbatterybox:hv-premium:home:tower-1#min-cell-voltage-cell" }
Number:ElectricPotential BYD_M1_Spread    "Module 1 Spread [%.0f mV]"                    (gBattery) ["Measurement", "Voltage"]       { channel="bydbatterybox:hv-premium:home:tower-1-module-1#cell-voltage-spread", unit="mV" }
Number:ElectricPotential BYD_M1_Cell01    "Module 1 Cell 1 [%.0f mV]"                    (gBattery) ["Measurement", "Voltage"]       { channel="bydbatterybox:hv-premium:home:tower-1-module-1#cell-voltage-01", unit="mV" }
Number:Temperature       BYD_M1_Temp01    "Module 1 Sensor 1 [%.0f °C]"                  (gBattery) ["Measurement", "Temperature"]   { channel="bydbatterybox:hv-premium:home:tower-1-module-1#cell-temperature-01" }

String                   BYD_LastEvent    "Last Event [%s]"                              (gBattery) ["Status"]                       { channel="bydbatterybox:hv-premium:home:events#last-event" }
DateTime                 BYD_LastEventTime "Last Event Time [%1$tF %1$tR]"               (gBattery) ["Status", "Timestamp"]          { channel="bydbatterybox:hv-premium:home:events#last-event-time" }

To keep the history of every cell, link all cell-voltage-* and cell-temperature-* channels and persist them, e.g. with an everyChange strategy. Cell voltages change in steps of 1 mV, so everyChange stores only real changes.

Rule Example ​

Alert when the voltage spread between the cells of a tower exceeds 80 mV, log every new battery event, and react to one specific event:

rules
rule "Battery cell spread alert"
when
    Item BYD_CellSpread changed
then
    val spread = (BYD_CellSpread.state as QuantityType<?>).toUnit("mV").doubleValue
    if (spread > 80) {
        logWarn("battery", "Cell voltage spread is {} mV, lowest cell is no. {}", spread, BYD_CellMinNo.state)
    }
end

rule "Battery event"
when
    Channel "bydbatterybox:hv-premium:home:events#event" triggered
then
    logInfo("battery", "Battery event {}", receivedEvent)
end

rule "Battery stopped discharging"
when
    Channel "bydbatterybox:hv-premium:home:events#event" triggered "BMS1:7"
then
    logInfo("battery", "Tower 1 stopped discharging")
end

The spread depends on the state of charge: near empty and near full, LiFePO4 cells show a much larger spread than in the middle range. Compare values taken at a similar state of charge, or use a lower threshold in the middle range.

Troubleshooting ​

Thing Status Messages ​

Thing status messageMeaning
Another client is probably connectedThe battery refused the connection. Close the BYD app or the other tool.
The battery cannot be reachedWrong hostname or port, the battery or the forwarding host is offline, or the Wi-Fi connection is down.
The battery did not answer in timeThe connection is slow or interrupted; increase connectionTimeout if this happens regularly.

When a Reading Fails ​

If the battery cannot be reached or does not answer, the binding repeats the reading 20 seconds later, before it reports the Thing as OFFLINE. While the battery stays unreachable, the binding keeps trying at the next readings, waiting longer after each failed attempt.

Short Interruptions Without Internet Access ​

If the battery is blocked from the internet, for example by a router or firewall rule, its network connection restarts every 103 seconds. Each time, the battery does not answer on the network for about 19 seconds, not even to ping. In a measurement over 14 hours, about one in five readings fell into such an interruption. The repeated reading 20 seconds later always succeeded, so the values arrived only a little later and the Thing stayed ONLINE. No setting is needed for this, and allowing the battery to access the internet made the interruptions disappear.

If the Thing still goes OFFLINE regularly with the message that the battery cannot be reached, the cause is probably a different one: check the cable or Wi-Fi connection and the battery's address.

Logging ​

Set the log level of org.openhab.binding.bydbatterybox to DEBUG to see every reading with its result and duration, or to TRACE to also see the data exchanged with the battery.

Credits ​

BYD does not publish the protocol. The binding was written from scratch, using the following projects to understand the protocol:

Readings were cross-checked with "BYD-Logger" by Olli from the Photovoltaik-Forum.