fl4p / batmon-ha

Add-on for Home Assistant to connect JK, JBD, Daly, ANT, SOK and Supervolt BMS via Bluetooth
MIT License
246 stars 53 forks source link

BMS JK-B2A20S20P connecting issue #189

Open kzajac83 opened 5 months ago

kzajac83 commented 5 months ago

Hello.

I got BMS JK-B2A20S20P (2A Balancing, up to 20 series, 200A) but cannot connect.

What I understood there are JK02 and JK04 protocols for Jikong BMS, where JK04 is not implemented fully here. First of all how to check does my BMS using JK02 or JK04 protocol?

Additional not sure about PIN because when I connect via application on smartphone then is need provide PIN 1st time. Please note I changed ping from default 1234 to 12345 - this is important?

Next question is regarding MAC address. [scanner] section in logs give me two MAC addresses but both not work, this mean I see lot's errors in py files in logs for both MAC.

General question is possible connect my BMS into batmon?

Model: JK-B2A20S20P HW: V10.XG SW: V10.07

Scanner provide 2 MAC addresses to me: DC:23:4D:EB:B9:E4 TY DC:23:4E:0A:8A:62 TY

BTW. Regarding logs - I cannot provide full log because is overwriting in batmon log tab and system -> logs -> batmon too even if I download full logs.

Paste log output between BEGIN and END for DC:23:4D:EB:B9:E4
BEGIN 

  File "/app/main.py", line 355, in fn
    await t()
  File "/app/bmslib/sampling.py", line 155, in __call__
    s = await self._sample_inner()
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/bmslib/sampling.py", line 227, in _sample_inner
    async with bms:
  File "/app/bmslib/bt.py", line 345, in __aenter__
    await self.connect()
  File "/app/bmslib/models/jikong.py", line 130, in connect
    await self._connect_with_scanner(timeout=timeout)
  File "/app/bmslib/bt.py", line 273, in _connect_with_scanner
    await self._connect_client(timeout=timeout / 2)
  File "/app/bmslib/bt.py", line 186, in _connect_client
    await asyncio.wait_for(self.client.connect(timeout=timeout), timeout=timeout + 1)
  File "/usr/lib/python3.11/asyncio/tasks.py", line 489, in wait_for
    return fut.result()
           ^^^^^^^^^^^^
  File "/app/venv/lib/python3.11/site-packages/bleak/backends/bluezdbus/client.py", line 348, in connect
    reply = await asyncio.wait_for(
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/tasks.py", line 502, in wait_for
    raise exceptions.TimeoutError() from exc
TimeoutError

23:50:38 INFO [sampling] connecting bms JKBt(DC:23:4D:EB:B9:E4,battery1)
23:50:38 INFO [bt] connecting battery1 (DC:23:4D:EB:B9:E4) adapter=default timeout=6
23:50:38 DEBUG [client] Connecting to device @ DC:23:4D:EB:B9:E4 with hci0
23:50:43 DEBUG [client] received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_DC_23_4D_EB_B9_E4): ['org.bluez.Device1', {'Connected': <dbus_next.signature.Variant ('b', True)>}, []]
23:50:44 DEBUG [client] Connection successful (/org/bluez/hci0/dev_DC_23_4D_EB_B9_E4)
23:50:44 DEBUG [client] Waiting for ServicesResolved (/org/bluez/hci0/dev_DC_23_4D_EB_B9_E4)
23:50:44 DEBUG [client] received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_DC_23_4D_EB_B9_E4): ['org.bluez.Device1', {'Name': <dbus_next.signature.Variant ('s', COMMON)>, 'Alias': <dbus_next.signature.Variant ('s', COMMON)>}, []]
23:50:45 DEBUG [client] received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_DC_23_4D_EB_B9_E4): ['org.bluez.Device1', {'ServicesResolved': <dbus_next.signature.Variant ('b', True)>}, []]
23:50:45 INFO [bt] [Service] 00001910-0000-1000-8000-00805f9b34fb (Handle: 15): Vendor specific
23:50:45 DEBUG [client] received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_DC_23_4D_EB_B9_E4/service000f/char0014): ['org.bluez.GattCharacteristic1', {'Value': <dbus_next.signature.Variant ('ay', b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')>}, []]
23:50:45 DEBUG [client] Read Characteristic 00002b11-0000-1000-8000-00805f9b34fb | /org/bluez/hci0/dev_DC_23_4D_EB_B9_E4/service000f/char0014: bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
23:50:45 INFO [bt]  [Characteristic] 00002b11-0000-1000-8000-00805f9b34fb (Handle: 20): Temperature Statistics (read,write-without-response,write), Value: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
23:50:45 DEBUG [client] received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_DC_23_4D_EB_B9_E4/service000f/char0014/desc0016): ['org.bluez.GattDescriptor1', {'Value': <dbus_next.signature.Variant ('ay', b'Phone->Module\x00')>}, []]
23:50:45 DEBUG [client] Read Descriptor 22 | /org/bluez/hci0/dev_DC_23_4D_EB_B9_E4/service000f/char0014/desc0016: bytearray(b'Phone->Module\x00')
23:50:45 INFO [bt]      [Descriptor] 00002901-0000-1000-8000-00805f9b34fb (Handle: 22): Characteristic User Description) | Value: b'Phone->Module\x00'
23:50:45 DEBUG [client] received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_DC_23_4D_EB_B9_E4/service000f/char0010): ['org.bluez.GattCharacteristic1', {'Value': <dbus_next.signature.Variant ('ay', b'\x00')>}, []]
23:50:45 DEBUG [client] Read Characteristic 00002b10-0000-1000-8000-00805f9b34fb | /org/bluez/hci0/dev_DC_23_4D_EB_B9_E4/service000f/char0010: bytearray(b'\x00')
23:50:45 INFO [bt]  [Characteristic] 00002b10-0000-1000-8000-00805f9b34fb (Handle: 16): Temperature Range (read,notify), Value: b'\x00'
23:50:45 DEBUG [client] received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_DC_23_4D_EB_B9_E4/service000f/char0010/desc0013): ['org.bluez.GattDescriptor1', {'Value': <dbus_next.signature.Variant ('ay', b'Module->Phone\x00')>}, []]
23:50:45 DEBUG [client] Read Descriptor 19 | /org/bluez/hci0/dev_DC_23_4D_EB_B9_E4/service000f/char0010/desc0013: bytearray(b'Module->Phone\x00')
23:50:45 INFO [bt]      [Descriptor] 00002901-0000-1000-8000-00805f9b34fb (Handle: 19): Characteristic User Description) | Value: b'Module->Phone\x00'
23:50:45 DEBUG [client] received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_DC_23_4D_EB_B9_E4/service000f/char0010/desc0012): ['org.bluez.GattDescriptor1', {'Value': <dbus_next.signature.Variant ('ay', b'\x00\x00')>}, []]
23:50:45 DEBUG [client] Read Descriptor 18 | /org/bluez/hci0/dev_DC_23_4D_EB_B9_E4/service000f/char0010/desc0012: bytearray(b'\x00\x00')
23:50:45 INFO [bt]      [Descriptor] 00002902-0000-1000-8000-00805f9b34fb (Handle: 18): Client Characteristic Configuration) | Value: b'\x00\x00'
23:50:45 INFO [bt] [Service] 0000180a-0000-1000-8000-00805f9b34fb (Handle: 12): Device Information
23:50:45 DEBUG [client] received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_DC_23_4D_EB_B9_E4/service000c/char000d): ['org.bluez.GattCharacteristic1', {'Value': <dbus_next.signature.Variant ('ay', b'\x02\x8a$f\x82\x01\x00')>}, []]
23:50:45 DEBUG [client] Read Characteristic 00002a50-0000-1000-8000-00805f9b34fb | /org/bluez/hci0/dev_DC_23_4D_EB_B9_E4/service000c/char000d: bytearray(b'\x02\x8a$f\x82\x01\x00')
23:50:45 INFO [bt]  [Characteristic] 00002a50-0000-1000-8000-00805f9b34fb (Handle: 13): PnP ID (read), Value: b'\x02\x8a$f\x82\x01\x00'
23:50:45 INFO [bt] [Service] 00001801-0000-1000-8000-00805f9b34fb (Handle: 8): Generic Attribute Profile
23:50:45 INFO [bt]  [Characteristic] 00002a05-0000-1000-8000-00805f9b34fb (Handle: 9): Service Changed (indicate), Value: None
23:50:45 DEBUG [client] received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_DC_23_4D_EB_B9_E4/service0008/char0009/desc000b): ['org.bluez.GattDescriptor1', {'Value': <dbus_next.signature.Variant ('ay', b'\x02\x00')>}, []]
23:50:46 DEBUG [client] Read Descriptor 11 | /org/bluez/hci0/dev_DC_23_4D_EB_B9_E4/service0008/char0009/desc000b: bytearray(b'\x02\x00')
23:50:46 INFO [bt]      [Descriptor] 00002902-0000-1000-8000-00805f9b34fb (Handle: 11): Client Characteristic Configuration) | Value: b'\x02\x00'
23:50:46 ERROR [sampling] battery1 error (#17): ('service %s not found (have %s)', '0000ffe0-0000-1000-8000-00805f9b34fb', ['00001910-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', '00001801-0000-1000-8000-00805f9b34fb'])
Traceback (most recent call last):
  File "/app/bmslib/sampling.py", line 155, in __call__
    s = await self._sample_inner()
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/bmslib/sampling.py", line 227, in _sample_inner
    async with bms:
  File "/app/bmslib/bt.py", line 345, in __aenter__
    await self.connect()
  File "/app/bmslib/models/jikong.py", line 132, in connect
    service = self.get_service(self.SERVICE_UUID)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/bmslib/bt.py", line 160, in get_service
    raise RuntimeError("service %s not found (have %s)", uuid, list(s.uuid for s in self.client.services))
RuntimeError: ('service %s not found (have %s)', '0000ffe0-0000-1000-8000-00805f9b34fb', ['00001910-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', '00001801-0000-1000-8000-00805f9b34fb'])
23:50:46 INFO [sampling] battery1 bms debug data: {'resp': {}, 'char_w': None, 'char_r': None}
23:50:46 INFO [sampling] Bleak version 0.13.1a1
23:50:46 ERROR [main] 1 exceptions occurred fetching BMSs
23:50:46 ERROR [main] Error (num 16, max 200) reading BMS: ('service %s not found (have %s)', '0000ffe0-0000-1000-8000-00805f9b34fb', ['00001910-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', '00001801-0000-1000-8000-00805f9b34fb'])
23:50:46 ERROR [main] Stack: Traceback (most recent call last):
  File "/app/main.py", line 44, in fetch_loop
    if await fn():
       ^^^^^^^^^^
  File "/app/main.py", line 360, in fn
    raise exceptions[0]
  File "/app/main.py", line 355, in fn
    await t()
  File "/app/bmslib/sampling.py", line 155, in __call__
    s = await self._sample_inner()
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/bmslib/sampling.py", line 227, in _sample_inner
    async with bms:
  File "/app/bmslib/bt.py", line 345, in __aenter__
    await self.connect()
  File "/app/bmslib/models/jikong.py", line 132, in connect
    service = self.get_service(self.SERVICE_UUID)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/bmslib/bt.py", line 160, in get_service
    raise RuntimeError("service %s not found (have %s)", uuid, list(s.uuid for s in self.client.services))
RuntimeError: ('service %s not found (have %s)', '0000ffe0-0000-1000-8000-00805f9b34fb', ['00001910-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', '00001801-0000-1000-8000-00805f9b34fb'])

23:50:47 WARNING [sampling] battery1 error fetching device info: 3

END
Paste log output between BEGIN and END for DC:23:4E:0A:8A:62
BEGIN 

23:53:48 DEBUG [client] received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_DC_23_4E_0A_8A_62/service000c/char000d): ['org.bluez.GattCharacteristic1', {'Value': <dbus_next.signature.Variant ('ay', b'\x02\x8a$f\x82\x01\x00')>}, []]
23:53:48 DEBUG [client] Read Characteristic 00002a50-0000-1000-8000-00805f9b34fb | /org/bluez/hci0/dev_DC_23_4E_0A_8A_62/service000c/char000d: bytearray(b'\x02\x8a$f\x82\x01\x00')
23:53:48 INFO [bt]  [Characteristic] 00002a50-0000-1000-8000-00805f9b34fb (Handle: 13): PnP ID (read), Value: b'\x02\x8a$f\x82\x01\x00'
23:53:48 INFO [bt] [Service] 00001801-0000-1000-8000-00805f9b34fb (Handle: 8): Generic Attribute Profile
23:53:48 INFO [bt]  [Characteristic] 00002a05-0000-1000-8000-00805f9b34fb (Handle: 9): Service Changed (indicate), Value: None
23:53:48 DEBUG [client] received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_DC_23_4E_0A_8A_62/service0008/char0009/desc000b): ['org.bluez.GattDescriptor1', {'Value': <dbus_next.signature.Variant ('ay', b'\x02\x00')>}, []]
23:53:48 DEBUG [client] Read Descriptor 11 | /org/bluez/hci0/dev_DC_23_4E_0A_8A_62/service0008/char0009/desc000b: bytearray(b'\x02\x00')
23:53:48 INFO [bt]      [Descriptor] 00002902-0000-1000-8000-00805f9b34fb (Handle: 11): Client Characteristic Configuration) | Value: b'\x02\x00'
23:53:48 ERROR [sampling] battery1 error (#1): ('service %s not found (have %s)', '0000ffe0-0000-1000-8000-00805f9b34fb', ['00001910-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', '00001801-0000-1000-8000-00805f9b34fb'])
Traceback (most recent call last):
  File "/app/bmslib/sampling.py", line 155, in __call__
    s = await self._sample_inner()
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/bmslib/sampling.py", line 227, in _sample_inner
    async with bms:
  File "/app/bmslib/bt.py", line 345, in __aenter__
    await self.connect()
  File "/app/bmslib/models/jikong.py", line 132, in connect
    service = self.get_service(self.SERVICE_UUID)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/bmslib/bt.py", line 160, in get_service
    raise RuntimeError("service %s not found (have %s)", uuid, list(s.uuid for s in self.client.services))
RuntimeError: ('service %s not found (have %s)', '0000ffe0-0000-1000-8000-00805f9b34fb', ['00001910-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', '00001801-0000-1000-8000-00805f9b34fb'])
23:53:48 INFO [sampling] battery1 bms debug data: {'resp': {}, 'char_w': None, 'char_r': None}
23:53:48 INFO [sampling] Bleak version 0.13.1a1
23:53:48 WARNING [sampling] battery1 error fetching device info: 3
23:53:56 ERROR [sampling] battery1 error (#2): timeout waiting for 2
Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/tasks.py", line 500, in wait_for
    return fut.result()
           ^^^^^^^^^^^^
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/app/bmslib/__init__.py", line 81, in wait_for
    return await asyncio.wait_for(self._futures.get(name), timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/tasks.py", line 502, in wait_for
    raise exceptions.TimeoutError() from exc
TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/bmslib/sampling.py", line 155, in __call__
    s = await self._sample_inner()
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/bmslib/sampling.py", line 237, in _sample_inner
    sample = await bms.fetch()
             ^^^^^^^^^^^^^^^^^
  File "/app/bmslib/models/jikong.py", line 244, in fetch
    await self._fetch_futures.wait_for(0x02, self.TIMEOUT)
  File "/app/bmslib/__init__.py", line 84, in wait_for
    raise asyncio.TimeoutError("timeout waiting for %s" % name)
TimeoutError: timeout waiting for 2
23:53:56 INFO [sampling] battery1 bms debug data: {'resp': {}, 'char_w': None, 'char_r': None}
23:53:56 INFO [sampling] Bleak version 0.13.1a1
23:53:56 ERROR [main] 1 exceptions occurred fetching BMSs
23:53:56 ERROR [main] Error (num 1, max 200) reading BMS: timeout waiting for 2
23:53:56 ERROR [main] Stack: Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/tasks.py", line 500, in wait_for
    return fut.result()
           ^^^^^^^^^^^^
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/app/bmslib/__init__.py", line 81, in wait_for
    return await asyncio.wait_for(self._futures.get(name), timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/tasks.py", line 502, in wait_for
    raise exceptions.TimeoutError() from exc
TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/main.py", line 44, in fetch_loop
    if await fn():
       ^^^^^^^^^^
  File "/app/main.py", line 360, in fn
    raise exceptions[0]
  File "/app/main.py", line 355, in fn
    await t()
  File "/app/bmslib/sampling.py", line 155, in __call__
    s = await self._sample_inner()
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/bmslib/sampling.py", line 237, in _sample_inner
    sample = await bms.fetch()
             ^^^^^^^^^^^^^^^^^
  File "/app/bmslib/models/jikong.py", line 244, in fetch
    await self._fetch_futures.wait_for(0x02, self.TIMEOUT)
  File "/app/bmslib/__init__.py", line 84, in wait_for
    raise asyncio.TimeoutError("timeout waiting for %s" % name)
TimeoutError: timeout waiting for 2

23:53:57 WARNING [sampling] battery1 error fetching device info: 3

END
6bishnoi commented 5 months ago

hi, enable install_newer_bleak to install bleak 0.20.2, which is more stable than the default version. I had to enable it

kzajac83 commented 5 months ago

Thank you, is working fine now :)

BTW, maybe you now, what mean number "cell index max" and "cell index min" (without UoM)? Additional "num_cycles", "num_samples" both in UoM [N] and "total cycles meter" with value "0,0 N" ? General what mean UoM [N]?

PS. All energy [kWh] entities and one capacity [Ah] value display in wrong format but will create other issue for that (or keep here?). Coma is in wrong place.

6bishnoi commented 5 months ago

good,

cell index max : is the cell number witch cell has the lowest Voltage cell index min: is the cell with the highest V

If you have VOLTRONIC basis inverter, you can try this new add-on: https://github.com/jean-luc1203/smartphoton-ha-addon/

I don’t now meters…

Le 29 janv. 2024 à 21:03, kzajac83 @.***> a écrit :

Thank you, is working fine now :)

BTW, maybe you now, what mean number "cell index max" and "cell index min" (without UoM)? Additional "num_cycles", "num_samples" both in UoM [N] and "total cycles meter" with value "0,0 N" ? General what mean UoM [N]?

PS. All energy [kWh] entities and one capacity [Ah] value display in wrong format but will create other issue for that (or keep here?). Coma is in wrong place.

— Reply to this email directly, view it on GitHub https://github.com/fl4p/batmon-ha/issues/189#issuecomment-1915466117, or unsubscribe https://github.com/notifications/unsubscribe-auth/BBSTMKVSWNYMUUQX6YDTM6TYQ76BRAVCNFSM6AAAAABCHZO27SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJVGQ3DMMJRG4. You are receiving this because you commented.