Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support TopBand Batteries #194

Closed
4 tasks done
Fandu21 opened this issue Feb 17, 2025 · 12 comments · Fixed by #200
Closed
4 tasks done

Support TopBand Batteries #194

Fandu21 opened this issue Feb 17, 2025 · 12 comments · Fixed by #200
Assignees
Labels
enhancement New feature or request

Comments

@Fandu21
Copy link

Fandu21 commented Feb 17, 2025

Checklist

  • I have filled out the template to the best of my ability.
  • I have understood that this integration is only about battery management systems with Bluetooth Low Energy support.
  • This only contains 1 feature request (if you have multiple feature requests, open one feature request for each feature request).
  • This issue is not a duplicate of any previous feature requests.

Please describe the enhancement you would like to have.

Thank you for this amazing add-on!! I am currently running version 1.12.0 and my TopBand BMS does not appear to currently be supported and I'm hoping that it can be added.

Additional context

[core-ssh ~]$ bluetoothctl info FC:45:C3:BC:D6:A8
Unable to open mgmt_socket
Device FC:45:C3:BC:D6:A8 (public)
Name: ZM20210512010036�
Alias: ZM20210512010036�
Paired: no
Bonded: no
Trusted: no
Blocked: no
Connected: yes
LegacyPairing: no
UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
UUID: Device Information (0000180a-0000-1000-8000-00805f9b34fb)
UUID: Unknown (0000ffe0-0000-1000-8000-00805f9b34fb)
UUID: Vendor specific (f000ffc0-0451-4000-b000-000000000000)
Modalias: bluetooth:v000Dp0000d0110
ManufacturerData Key: 0x0000 (0)
ManufacturerData Value:
fc 45 c3 bc d6 a8 .E....
RSSI: 0xffffffd0 (-48)
AdvertisingFlags:
05 .
[core-ssh ~]$`

Link to TBEnergy IOS App

@Fandu21 Fandu21 added the enhancement New feature or request label Feb 17, 2025
@Fandu21
Copy link
Author

Fandu21 commented Feb 18, 2025

IOS BT Packet Logs available here.

IOS App Manual

@patman15
Copy link
Owner

Hi @Fandu21! Looks like an Ective BMS, so implementation exists, although I see some differences. Can you try the development branch via manual install and send me a debug log?

@Fandu21
Copy link
Author

Fandu21 commented Feb 20, 2025

Thank you for the quick response! I manually installed the development branch and the battery was detected and all everything appeared to be working as expected. However, HA has since lost the BLE connection to the battery and I've been unable to re-establish it by restarting HA. The integration reports " Failed setup, will retry: Could not find BMS (FC:45:C3:BC:D6:A8) via Bluetooth. "

As for debug logs, I'm able to enable debug logging in the integration but I do not have any option to actually download the logs. When installed through HACS I do have the option to download the logs. Not sure what's happening there, probably user error but I'm not too sure.

@patman15
Copy link
Owner

Could it be that Bluetooth is turned off by the battery, when there is no current?

For the logs, if you are at integration, you can turn debug logs off and it will prompt you with a download then.

@Fandu21
Copy link
Author

Fandu21 commented Feb 21, 2025

I'm still able to connect to the battery using the ios app so I don't think it's an issue of the BMS turning off or anything. So I did a little more digging and found something interesting. While initially setting up the integration, bluetoothctl produced the following output:

[core-ssh ~]$ bluetoothctl devices Unable to open mgmt_socket ��Device CC:20:26:42:3C:78 CC-20-26-42-3C-78�� ��Device D3:73:D6:5B:19:CA D3-73-D6-5B-19-CA�� Device 34:13:43:1E:88:FD telink_mesh1 ��Device 75:76:B7:81:C4:BA 75-76-B7-81-C4-BA�� Device 0A:38:B2:97:CF:CB 0A-38-B2-97-CF-CB ��Device C0:C3:9A:B4:A8:8F C0-C3-9A-B4-A8-8F�� Device 78:F7:A3:40:72:0D 78-F7-A3-40-72-0D ��Device 49:F0:88:91:3C:73 49-F0-88-91-3C-73�� Device 4C:A7:BE:26:24:F6 4C-A7-BE-26-24-F6 Device 4D:7F:52:59:6B:BD 4D-7F-52-59-6B-BD Device 6B:37:AC:6E:40:B1 6B-37-AC-6E-40-B1 Device 70:45:1D:79:B2:92 70-45-1D-79-B2-92 ��Device 0C:E2:82:4A:6B:E7 0C-E2-82-4A-6B-E7�� Device 66:34:67:1D:87:93 66-34-67-1D-87-93 ��Device F3:5C:11:F3:6C:C8 F3-5C-11-F3-6C-C8�� ��Device C6:B2:63:82:E8:63 C6-B2-63-82-E8-63�� ��Device D2:35:3D:B7:CB:8E D2-35-3D-B7-CB-8E�� ��Device DF:04:5A:0A:9D:EB DF-04-5A-0A-9D-EB�� ��Device E3:CA:68:91:73:A8 E3-CA-68-91-73-A8�� ��Device 0B:08:A9:80:92:E3 0B-08-A9-80-92-E3�� ��Device 25:98:05:27:A8:2E 25-98-05-27-A8-2E�� ��Device 7C:51:BD:6C:38:60 7C-51-BD-6C-38-60�� Device 40:17:60:14:D4:39 40-17-60-14-D4-39 Device 40:2A:01:E0:FF:B3 40-2A-01-E0-FF-B3 Device 4C:D5:85:F5:C9:8E 4C-D5-85-F5-C9-8E Device 62:C1:B8:96:CB:2D 62-C1-B8-96-CB-2D Device 47:AB:B7:04:08:3A 47-AB-B7-04-08-3A Device 43:4F:92:10:1C:C7 43-4F-92-10-1C-C7 ��Device 65:77:66:9C:7F:17 65-77-66-9C-7F-17�� Device FC:45:C3:BC:D6:A8 ZM20210512010036� ��Device 5E:56:52:A6:61:8F 5E-56-52-A6-61-8F�� ��Device 46:F5:31:4B:3E:C6 46-F5-31-4B-3E-C6�� Device 5D:1A:02:82:BF:A8 5D-1A-02-82-BF-A8 ��Device 34:13:43:1E:CF:F4 1FA178DE9D0E1212�� ��Device B8:3A:9D:81:4B:57 ALAM (81:4B:56)�� ��Device 5B:DB:DB:9F:D9:ED 5B-DB-DB-9F-D9-ED�� ��Device 44:84:84:68:23:30 44-84-84-68-23-30�� Device 44:C6:5D:6B:78:22 44-C6-5D-6B-78-22 ��Device 28:E6:A9:46:BF:13 65" OLED�� Device 88:4A:EA:36:8B:AD Leviton DDMX1 V5.1 Device 60:A7:3C:E6:FB:BD 60-A7-3C-E6-FB-BD Device 08:66:98:9F:C6:C5 08-66-98-9F-C6-C5 Device 50:8B:B9:EB:FB:97 TY

However, now the output is quite different:

[core-ssh bms_ble]$ bluetoothctl devices Unable to open mgmt_socket Device 34:13:43:1D:7C:72 1FA178DE9D0E1212 Device 6E:BC:3B:92:7C:6F 6E-BC-3B-92-7C-6F Device 18:87:4E:38:AE:E3 18-87-4E-38-AE-E3 Device 6B:AC:A8:5B:46:82 6B-AC-A8-5B-46-82 Device 56:C8:17:A1:A0:76 56-C8-17-A1-A0-76 Device 11:EE:A7:D2:E5:08 11-EE-A7-D2-E5-08 Device 5E:12:CD:6D:22:79 5E-12-CD-6D-22-79 Device 63:5B:37:F1:C7:7A 63-5B-37-F1-C7-7A Device 44:C6:5D:6B:78:22 44-C6-5D-6B-78-22 Device 7B:91:D0:99:4C:A5 7B-91-D0-99-4C-A5 Device 4C:BD:31:05:58:00 4C-BD-31-05-58-00 Device 77:AE:79:9C:6C:59 77-AE-79-9C-6C-59 Device 7C:73:1B:C2:0B:30 7C-73-1B-C2-0B-30 Device 7E:A5:A9:E3:6E:27 7E-A5-A9-E3-6E-27 Device 88:4A:EA:36:8B:AD Leviton DDMX1 V5.1 Device 50:8B:B9:EB:FB:97 TY Device 08:66:98:9F:C6:C5 08-66-98-9F-C6-C5 Device 60:A7:3C:E6:FB:BD 60-A7-3C-E6-FB-BD Device 4F:2A:A9:B5:0C:50 4F-2A-A9-B5-0C-50

What finally worked was removing the integration, restarting HA, and then re-installing the integration. The output from bluetoothctl has returned to the expected. With things functioning again, I enabled logging, left things to setting for a few minutes, then moved the battery out of BLE signal range, waiting a few minutes, and then brought the battery back in range.

Log here.

@patman15
Copy link
Owner

patman15 commented Feb 21, 2025

EDIT: ok, I found the correct entries. Still the log shows a huge number of transmission errors that alter the data. I do not know how this can happen via BT but it is just messed up. I will do some fixes to make it more reliable, but in general the connection is bad.

@patman15 patman15 linked a pull request Feb 21, 2025 that will close this issue
@Fandu21
Copy link
Author

Fandu21 commented Feb 25, 2025

With the updated error checking, I'm no longer getting any data from the battery at all. Log here

I'm not sure why there would be so many BT errors. The RSSI is -64, nice and strong.

Edit: Parsing through the debug logs it appears that I'm receiving a valid data frame every 30.000 seconds and non-decodable data in between:

2025-02-24 21:44:42.984 DEBUG (MainThread) [custom_components.bms_ble] ZM20210512010036�: BMS data sample {'voltage': 13.295, 'current': 0.0, 'battery_level': 97, 'cycle_charge': 9.0, 'cycles': 1, 'temperature': 24.3, 'problem_code': 0, 'cell#0': 3.32, 'cell#1': 3.324, 'cell#2': 3.322, 'cell#3': 3.329, 'delta_voltage': 0.009, 'cycle_capacity': 119.655, 'power': 0.0, 'battery_charging': False, 'problem': False}

2025-02-24 21:45:12.983 DEBUG (MainThread) [custom_components.bms_ble] ZM20210512010036�: BMS data sample {'voltage': 13.286, 'current': 0.0, 'battery_level': 97, 'cycle_charge': 9.0, 'cycles': 1, 'temperature': 24.3, 'problem_code': 0, 'cell#0': 3.317, 'cell#1': 3.322, 'cell#2': 3.32, 'cell#3': 3.327, 'delta_voltage': 0.01, 'cycle_capacity': 119.574, 'power': 0.0, 'battery_charging': False, 'problem': False}

2025-02-24 21:45:42.983 DEBUG (MainThread) [custom_components.bms_ble] ZM20210512010036�: BMS data sample {'voltage': 13.286, 'current': 0.0, 'battery_level': 97, 'cycle_charge': 9.0, 'cycles': 1, 'temperature': 24.3, 'problem_code': 0, 'cell#0': 3.316, 'cell#1': 3.322, 'cell#2': 3.32, 'cell#3': 3.328, 'delta_voltage': 0.012, 'cycle_capacity': 119.574, 'power': 0.0, 'battery_charging': False, 'problem': False}

2025-02-24 21:46:12.983 DEBUG (MainThread) [custom_components.bms_ble] ZM20210512010036�: BMS data sample {'voltage': 13.275, 'current': 0.0, 'battery_level': 97, 'cycle_charge': 9.0, 'cycles': 1, 'temperature': 24.3, 'problem_code': 0, 'cell#0': 3.315, 'cell#1': 3.319, 'cell#2': 3.317, 'cell#3': 3.324, 'delta_voltage': 0.009, 'cycle_capacity': 119.475, 'power': 0.0, 'battery_charging': False, 'problem': False}

2025-02-24 21:46:42.983 DEBUG (MainThread) [custom_components.bms_ble] ZM20210512010036�: BMS data sample {'voltage': 13.276, 'current': 0.0, 'battery_level': 97, 'cycle_charge': 9.0, 'cycles': 1, 'temperature': 24.3, 'problem_code': 0, 'cell#0': 3.315, 'cell#1': 3.32, 'cell#2': 3.317, 'cell#3': 3.324, 'delta_voltage': 0.009, 'cycle_capacity': 119.484, 'power': 0.0, 'battery_charging': False, 'problem': False}

2025-02-24 21:47:12.983 DEBUG (MainThread) [custom_components.bms_ble] ZM20210512010036�: BMS data sample {'voltage': 13.285, 'current': 0.0, 'battery_level': 97, 'cycle_charge': 9.0, 'cycles': 1, 'temperature': 24.3, 'problem_code': 0, 'cell#0': 3.317, 'cell#1': 3.321, 'cell#2': 3.32, 'cell#3': 3.327, 'delta_voltage': 0.01, 'cycle_capacity': 119.565, 'power': 0.0, 'battery_charging': False, 'problem': False}

@patman15 patman15 self-assigned this Feb 25, 2025
@patman15
Copy link
Owner

Ok, I checked the log again, the parsing is correct. A lot of the received data is garbage, too short, or has incorrect checksum. By chance, are you using the Raspberry Pi internal BT? I do not see anything I could fix more from coding point of view. So I'll merge that code soon. Let me know if you need more help or if it is ok like this.

@Fandu21
Copy link
Author

Fandu21 commented Feb 26, 2025

Yes I'm using the built-in BT hardware on the RPi4b and I'm using the USB3 ports so that may explain some of the checksum issues.

I left the battery overnight and I'm getting valid data every 30 seconds. That's fine for my needs. However there does seem to be an issue with the connection recovering after an interruption. I intentionally moved the battery out of BT range and then brought it back within range, expecting the connection to automatically re-establish and data to resume, but that's not the behavior I'm seeing.

After bringing the battery back within BT range, the debug logs show packets being received but all data is invalid. Log here

The only way I can coax things to work again is by rebooting the RPi.

@patman15
Copy link
Owner

patman15 commented Feb 26, 2025

After bringing the battery back within BT range, the debug logs show packets being received but all data is invalid.

Ok, I see a chance to fix that in the protocol parsing (thanks for testing), but the basic issue with the RPi messing up data will persist. For that I strongly recommend to take a look at proper adapters, e.g. I took this LogiLink for no money (no I do not get any commission 😉)
I'll provide you an update that should further enhance robustness.

@patman15
Copy link
Owner

@Fandu21 I pushed a small fix that should bring the battery back in cases like you tested yesterday. Btw. I assume that you just kept the battery to short out of range before the connection was considered to be lost, otherwise it would have resynced. Anyway thanks for pointing it out, now it should even cover that case. 😃

@Fandu21
Copy link
Author

Fandu21 commented Feb 27, 2025

Tested and the connection now re-establishes itself automatically. Awesome!

@Fandu21 Fandu21 closed this as completed Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants