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

BT Pin code supported? #41

Closed
3 tasks done
HansWegman opened this issue Sep 1, 2024 · 21 comments
Closed
3 tasks done

BT Pin code supported? #41

HansWegman opened this issue Sep 1, 2024 · 21 comments
Labels
question Further information is requested Stale

Comments

@HansWegman
Copy link

HansWegman commented Sep 1, 2024

Checklist

  • I need support with using the integration.
  • My issue is not a feature request
  • I'm not avoiding to fill out the bug report form.

Describe the issue

I just tried to install the integration to connect by XiaoXiangElectric Battery (JBD) which went like a charm, unfortunately although my battery was detected nicely through the ESPHome proxy and 11 entities were added, none have any data. I suspect this is because I have added a bluetooth pin to the battery which unfortunately cannot be removed. I have set it to "000000" now but still no data and the integration reports: "Failed to initialise BMS Hans Battery, continuing". Any idea if it is possible to enter the pin somewhere?

log

2024-09-01 17:21:35.661 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration bms_ble which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2024-09-01 17:21:41.997 INFO (MainThread) [homeassistant.setup] Setting up bms_ble
2024-09-01 17:21:41.997 INFO (MainThread) [homeassistant.setup] Setup of domain bms_ble took 0.00 seconds
2024-09-01 17:21:41.997 DEBUG (MainThread) [custom_components.bms_ble] Setup of
2024-09-01 17:22:23.632 DEBUG (MainThread) [custom_components.bms_ble] Bluetooth device detected: <BluetoothServiceInfoBleak name=Hans Battery address=A4:C1:37:04:2D:BE rssi=-65 manufacturer_data={11710: b'\x047\xc1\xa4'} service_data={} service_uuids=['0000ff00-0000-1000-8000-00805f9b34fb'] source=10:06:1C:16:7C:28 connectable=True time=240246.576593881 tx_power=None>
2024-09-01 17:22:23.634 DEBUG (MainThread) [custom_components.bms_ble] Setup of
2024-09-01 17:22:23.679 DEBUG (MainThread) [custom_components.bms_ble] Initializing coordinator for Hans Battery (A4:C1:37:04:2D:BE) as Jiabaida Smart BMS
2024-09-01 17:22:23.679 DEBUG (MainThread) [custom_components.bms_ble] device data: {'name': 'Hans Battery', 'address': 'A4:C1:37:04:2D:BE', 'rssi': -63, 'manufacturer_data': {11710: b'\x047\xc1\xa4'}, 'service_data': {}, 'service_uuids': ['0000ff00-0000-1000-8000-00805f9b34fb'], 'source': '10:06:1C:16:7C:28', 'advertisement': AdvertisementData(local_name='Hans Battery', manufacturer_data={11710: b'\x047\xc1\xa4'}, service_uuids=['0000ff00-0000-1000-8000-00805f9b34fb'], tx_power=-127, rssi=-63), 'device': BLEDevice(A4:C1:37:04:2D:BE, Hans Battery), 'connectable': True, 'time': 240285.365139811, 'tx_power': None}
2024-09-01 17:22:23.679 DEBUG (MainThread) [custom_components.bms_ble] BMS Hans Battery data update
2024-09-01 17:22:23.680 DEBUG (MainThread) [custom_components.bms_ble.plugins.jbd_bms] Connecting BMS (Hans Battery)
2024-09-01 17:22:35.168 DEBUG (MainThread) [custom_components.bms_ble] Device communication timeout
2024-09-01 17:22:35.169 DEBUG (MainThread) [custom_components.bms_ble] Finished fetching Hans Battery data in 11.489 seconds (success: False)
2024-09-01 17:22:35.169 WARNING (MainThread) [custom_components.bms_ble] Failed to initialize BMS Hans Battery, continuing
2024-09-01 17:22:35.176 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up bms_ble.binary_sensor
2024-09-01 17:22:35.178 INFO (MainThread) [homeassistant.components.sensor] Setting up bms_ble.sensor
2024-09-01 17:23:05.091 DEBUG (MainThread) [custom_components.bms_ble] BMS Hans Battery data update
2024-09-01 17:23:05.092 DEBUG (MainThread) [custom_components.bms_ble.plugins.jbd_bms] BMS Hans Battery already connected
2024-09-01 17:23:15.095 DEBUG (MainThread) [custom_components.bms_ble] Device communication timeout
2024-09-01 17:23:15.095 DEBUG (MainThread) [custom_components.bms_ble] Finished fetching Hans Battery data in 10.004 seconds (success: False)
2024-09-01 17:23:45.091 DEBUG (MainThread) [custom_components.bms_ble] BMS Hans Battery data update
2024-09-01 17:23:45.091 DEBUG (MainThread) [custom_components.bms_ble.plugins.jbd_bms] BMS Hans Battery already connected
2024-09-01 17:23:55.094 DEBUG (MainThread) [custom_components.bms_ble] Device communication timeout
2024-09-01 17:23:55.095 DEBUG (MainThread) [custom_components.bms_ble] Finished fetching Hans Battery data in 10.003 seconds (success: False)

@HansWegman HansWegman added the question Further information is requested label Sep 1, 2024
@patman15
Copy link
Owner

patman15 commented Sep 1, 2024

Looks like the device does not respond, which is highly likely due to the set pin. Unfortunately, there is currently no function to set a pin for a battery in the integration. Would need to take a look on how to implement that. Would you volunteer as beta-tester (since I have no battery with pin available)?
Thanks for the log, simplified the response a lot!

@patman15
Copy link
Owner

patman15 commented Sep 1, 2024 via email

@HansWegman
Copy link
Author

Thanks for your quick reply! I will be very happy to do the beta test for sure! And I will try to pair from the terminal right away, will let you know asap.

@HansWegman
Copy link
Author

Hmm, tried to pair but maybe from the wrong terminal? I have a ssh and terminal add-on in HA which reports:
unable to open mgmt_socket, device A4:C1:37:04:2D:BE not available.

@HansWegman
Copy link
Author

And maybe a silly suggestion since my programming skills are very low but maybe this could be solved (by someone with te right skills) with a small setting added to the ESPHome proxy based upon this:

on_passkey_request
This automation is triggered when the BLE device requests a passkey for authentication.

ble_client:

  • mac_address: XX:XX:XX:XX:XX:XX
    id: ble_itag
    on_passkey_request:
    then:
    - ble_client.passkey_reply:
    id: ble_itag
    passkey: 123456

@patman15
Copy link
Owner

patman15 commented Sep 1, 2024

unable to open mgmt_socket, device A4:C1:37:04:2D:BE not available.

You see that as reply to which command?

When you enter the terminal you should see:

       ▄██▄           _   _                                    
     ▄██████▄        | | | | ___  _ __ ___   ___               
   ▄████▀▀████▄      | |_| |/ _ \| '_ ` _ \ / _ \              
 ▄█████    █████▄    |  _  | (_) | | | | | |  __/              
▄██████▄  ▄██████▄   |_| |_|\___/|_| |_| |_|\___|          _   
████████  ██▀  ▀██      / \   ___ ___(_)___| |_ __ _ _ __ | |_ 
███▀▀███  ██   ▄██     / _ \ / __/ __| / __| __/ _` | '_ \| __|
██    ██  ▀ ▄█████    / ___ \\__ \__ \ \__ \ || (_| | | | | |_ 
███▄▄ ▀█  ▄███████   /_/   \_\___/___/_|___/\__\__,_|_| |_|\__|
▀█████▄   ███████▀

Welcome to the Home Assistant command line.

System information
  IPv4 addresses for enp0s18: 192.---------
  IPv6 addresses for enp0s18: ---------------------------

  OS Version:               Home Assistant OS 13.1
  Home Assistant Core:      2024.8.3

  Home Assistant URL:       http://home.local:8123
  Observer URL:             http://home.local:4357
➜  ~ 
  • Next, run bluetoothctl devices, you should get a list of available (and unavailable) devices and their MAC addresses.
  • Next, try bluetoothctl pair <MAC_of_your_BMS>

@HansWegman
Copy link
Author

Yes, I tried it there indeed but my BMS device is not listed there... It is in the log of the proxy though, see the attached logfile.
logs_m5stack-atom-lite-167c28_run.txt

@HansWegman
Copy link
Author

I changed the log settings in the proxy to VERY_VERBOSE and copied the parts with the Battery which seem to indicate it gets connected if I understand it well. Still do not understand why it does not appear in HA though. I attached a screenshot of the bluetoothctl devices output as well. Also strange, I reloaded your integration without the proxy and it failed on the entities. When I connected the proxy again it reloaded well.
devices
Proxy_very_verbose Log battery part.txt

@patman15
Copy link
Owner

patman15 commented Sep 2, 2024 via email

@HansWegman
Copy link
Author

HansWegman commented Sep 2, 2024

I am running HA core 2024.8.3 with supervisor 2024.08.0 on OS 13.1 on generic-x86-64

@patman15
Copy link
Owner

patman15 commented Sep 2, 2024

Can you please check the output of bluetoothctl list to show the adapters?
I think it is an issue with the proxy. Pairing needs to be between the adapter and the device, IMHO. That means that since you are using a proxy the BMS needs to be paired with the proxy (which you can't do unless it shows up in bluetoothctl). Probably you can use the automation you have used so far?
Sorry, just guessing a bit, but maybe it helps to move forward. What is a bit irritating is the message unable to open mgmt_socket that should not happen. Can you bring the battery closer to the actual host so that we can check the pairing works there?

@HansWegman
Copy link
Author

Attached is the result of the list command. I guess however looking at the log that the MBS is paired with the proxy. I also sniffed the communication between the original app and the device and it looks like there is some special communications. I will include the log as well.

What I did, I removed and reinstalled the app so it would ask for the password again.
I started the log
I opened the app and entered the password 123123
Than the readings came in, battery 99% charged
I switched to some other screens in the app
I closed the app
I reopened the app and this time I did not need to enter the password, I guess it saves it and uses the same or another way to connect
The data reappeared

Im am looking at it and trying to make some sense out of it:
XiaoXiang log 2.log

Screenshot of list command

@patman15
Copy link
Owner

patman15 commented Sep 3, 2024 via email

@HansWegman
Copy link
Author

The XiaoXiangElectric app on my iPhone, there is also an Android version, see https://xiaoxiangbms.com/download/.

@patman15
Copy link
Owner

patman15 commented Sep 3, 2024

Hi! I digged a bit through the documentation on the Internet regarding the proxy and pairing, which is very weak regarding hints. Can you please try to bring the BMS into the range of your controller directly attached to homeassistant (and probably also disable the BT proxy) and then try to pair the device once see #41 (comment). If I interpret the documentation correct, it should afterwards also work with the BT proxy, but the pairing needs to happen directly without the proxy.

@HansWegman
Copy link
Author

Hi Patrick,

that is going to be quite a challenge but I will see whether I can figure something out to make that possible. Will get back to you hopefully soon.

@patman15
Copy link
Owner

patman15 commented Sep 4, 2024

Hi Hans,

I have not too much hope, but you could try this code: https://github.com/patman15/BMS_BLE-HA/tree/feature/pairing
See https://github.com/patman15/BMS_BLE-HA/tree/feature/pairing?tab=readme-ov-file#manual on how to get the code manually to your system.
Please send me the debug log to see what happens.

I found some hints that pairing is not supported by the bleak library which is used by Home Assistant.

Copy link

This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 15 days.

@github-actions github-actions bot added the Stale label Oct 20, 2024
Copy link

github-actions bot commented Nov 5, 2024

This issue was closed because it has been stalled for 15 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 5, 2024
@krasnoukhov
Copy link

@HansWegman Did you have any luck with on_passkey_request? I'm trying to set up this integration with ESPHome BT proxy and JK BMS that apparently does require PIN, but no luck so far

@HansWegman
Copy link
Author

Hello Dmitri,

unfortunately not. I have found a possible solution though with https://github.com/syssi/esphome-jbd-bms. The author has figured out the encryption and is working on implementing that into the software so hopefully there is a solution soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

3 participants