From 5cee4bd543488ef37f0bcc349708a5343af60654 Mon Sep 17 00:00:00 2001 From: Jannis Christiani Date: Sat, 11 Apr 2026 19:43:38 +0200 Subject: [PATCH] Fix BMS not responding to commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use write_gatt_char with response=True (Write With Response) — many BMS firmwares ignore Write Without Response packets - Add 0.5s delay after start_notify before sending first command to avoid race where BMS hasn't registered the notification subscription yet Co-Authored-By: Claude Sonnet 4.6 --- custom_components/xiaoxiang_bms/bluetooth_handler.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/custom_components/xiaoxiang_bms/bluetooth_handler.py b/custom_components/xiaoxiang_bms/bluetooth_handler.py index c2aa36b..2c9da02 100644 --- a/custom_components/xiaoxiang_bms/bluetooth_handler.py +++ b/custom_components/xiaoxiang_bms/bluetooth_handler.py @@ -58,6 +58,9 @@ class BmsBluetoothHandler: ) await self._client.connect() await self._client.start_notify(RX_CHAR_UUID, self._on_notify) + # Give the BMS a moment to register the notification subscription + # before we start sending commands — avoids dropped first response + await asyncio.sleep(0.5) _LOGGER.debug("Connected to BMS at %s", self._address) async def disconnect(self) -> None: @@ -126,7 +129,7 @@ class BmsBluetoothHandler: self._response_event.clear() self._response_data = None try: - await self._client.write_gatt_char(TX_CHAR_UUID, command, response=False) + await self._client.write_gatt_char(TX_CHAR_UUID, command, response=True) except BleakError as exc: _LOGGER.error("BLE write failed: %s", exc) return None