Coder Social home page Coder Social logo

fl4p / batmon-ha Goto Github PK

View Code? Open in Web Editor NEW
255.0 19.0 54.0 408 KB

Add-on for Home Assistant to connect JK, JBD, Daly, ANT, SOK and Supervolt BMS via Bluetooth

License: MIT License

Dockerfile 0.23% Python 99.63% Shell 0.14%
daly-bms dalybms home-assistant jikong-bms jkbms mqtt xiaoxiang jbd-bms smart-bms jk-bms

batmon-ha's Introduction

Home Assistant Add-on: BatMON

Home Assistant Dashboard Screenshot

Monitor and control various Battery management systems (BMS) over Bluetooth. This add-on reads the BMS and sends sensor data through MQTT to Home Assistant. Using bluetooth on the Home Assistant host system, it does not need any additional hardware (no USB/Serial/RS485).

I created this to compare BMS readings for a detailed evaluation of BMS reliability and accuracy.

Features

  • Uses Bluetooth Low-Energy (BLE) for wireless communication
  • Captures SoC, Current, Power, individual cell voltages and temperatures
  • Monitor multiple devices at the same time
  • Energy consumption meters (using trapezoidal power integrators)
  • Integrates with Home Assistant Energy dashboard and Utility Meter sensor helper
  • Control BMS charging and discharging switches
  • Home Assistant MQTT Discovery
  • Can write data to InfluxDB
  • Battery Groups, see doc/Groups.md
  • Charge Algorithms, see doc/Algorithms.md
  • Short delays for responsive automation (fast load shedding)

Supported Devices (bluetooth low energy)

  • JK BMS / jikong (JK02 protocol)
  • Daly BMS
  • JBD / Jiabaida/ Xiaoxiang / Overkill Solar BMS
  • ANT BMS
  • Supervolt BMS
  • SOK BMS
  • Victron SmartShunt (make sure to update to the latest firmware and enable GATT in the VictronConnect app)

I tested the add-on on a Raspberry Pi 4 using Home Assistant Operating System.

Installation

  • Go to your Home Assistant Add-on store and add this repository: https://github.com/fl4p/home-assistant-addons Open your Home Assistant instance and show the dashboard of a Supervisor add-on.
  • Install Batmon add-on
  • Install, configure and start Mosquito MQTT broker (don't forget to configure the MQTT integration)

Configuration

The add-on can read multiple BMS at the same time. Add an entry for each device, such as:

- address: CC:44:8C:F7:AD:BB
  type: jk
  alias: battery1            # MQTT topic prefix (regex [\w_.-/])
  pin: "12345"               # pairing PSK, victron only (optional)
  adapter: "hci0"            # switch the bluetooth hw adapter (optional)
  debug: true                # verbose log for this device only (optional)
  current_calibration: 1.0   # current [I] correction factor (optional)

address is the MAC address of the Bluetooth device. If you don't know the MAC address start the add-on, and you'll find a list of visible Bluetooth devices in the add-on log. Alternatively you can enter the device name here as displayed in the discovery list.

type can be jk, jbd, ant, daly, supervolt, sok, victron or dummy.

With the alias field you can set the MQTT topic prefix and the name as displayed in Home Assistant. Otherwise, the name as found in Bluetooth discovery is used.

If the device requires a PIN when pairing (currently Victron SmartShunt only) add pin: "123456" (and replace 123456 with device's PIN).

Add adapter: "hci1" to select a bluetooth adapter other than the default one.

With current_calibration you can calibrate the current sensor. The current reading is multiplied by this factor. Set it to -1 to flip the sign if you experience wrong charge/discharge meters.

For verbose logs of particular BMS add debug: true.

  • Set MQTT user and password. MQTT broker is usually core-mosquitto.
  • concurrent_sampling tries to read all BMSs at the same time (instead of a serial read one after another). This can increase sampling rate for more timely-accurate data. Might cause Bluetooth connection issues if keep_alive is disabled.
  • keep_alive will never close the bluetooth connection. Use for higher sampling rate. You will not be able to connect to the BMS from your phone anymore while the add-on is running.
  • sample_period is the time in seconds to wait between BMS reads. Small periods generate more data points per time.
  • Set publish_period to a higher value than sample_period to throttle MQTT data, while sampling BMS for accurate energy meters. On publish, samples since previous publish are averaged. Periods shorter than 2s can slow down history plots in HA.
  • invert_current changes the sign of the current. Normally it is positive during discharge, inverted its negative.
  • expire_values_after time span in seconds when sensor values become "Unavailable"
  • watchdog stops the program on too many errors (make sure to enable the Home Assistant watchdog to restart the add-on after it exists)
  • Enable install_newer_bleak to install bleak 0.20.2, which is more stable than the default version. The default version is known to be working with Victron SmartShunt.

Energy Meters

Batmon implements energy metering by computing the integral of power values from the BMS with the trapezoidal rule. You can add theses meters to your Home Assistant Energy Dashboard or use them with the HA Helper Utility Meter, see doc/HA Energy Dashboard.md.

  • Total Energy Discharge Meter: total Energy out of the battery (increasing only, use this for the Energy Dashboard)
  • Total Energy Charge: total Energy into the battery (increasing only, use this for the Energy Dashboard)
  • Total Energy: The total energy flow into and out of the battery (decreasing and increasing). This equals to (Total Energy Charge) - (Total Energy Discharge). It will increase over time because batteries are not ideal. You can create a derivative helper to compute energy flow within e.g. 24h.
  • Total Cycles: Total full cycles of the battery. One complete discharge and charge is a full cycle: SoC 100%-0%-100%. This is not a value provided by the BMS, Batmon computes this by differentiating the SoC ( e.g. integrate(abs(diff(SoC% / 100 / 2)))).

The accuracy depends on the accuracy of the voltage and current readings from the BMS. Consider these having an error of 2~5%. Some BMS do not detect small currents (<200mA) and can miss high frequency peaks, leading to even greater error.

Troubleshooting

  • Power cycle (turn off and on) the BMS Bluetooth hardware/dongle (or BMS)
  • Enable bt_power_cycle. If it doesn't work, manually power cycle Bluetooth on the host you are running batmon on #91.
  • When experiencing unstable connection enable keep_alive
  • TimeoutError: timeout waiting: put BT devices closer, disable inverters and other EMI sources
  • Enable verbose_log and check the logs. If that is too noisy set debug: true in the BMS configuration as described above
  • Toggle install_newer_bleak option
  • Try to find the BMS with a BLE scan linux
  • After a long-lasting bluetooth connection is lost both Daly and JBD dongles occasionally refuse to accept new connections and disappear from bluetooth discovery. Remove wires from the dongle and reconnect for a restart.
  • Some users reported unstable Bluetooth connection with Raspberry Pi 4 onboard bluetooth hardware and WiFi enabled. It appears that disabling WiFi helps. (#42)
  • Cheap inverters might cause heavy EMI (electromagnetic interference). Turn them off or keep them away from the bluetooth hardware
  • Either bleak or bluetooth support in HA docker seems unstable. see related issues 106 109
  • Try another bluetooth hardware. Note you can choose the adapter with adapter parameter for each BMS individually
  • doc/Downgrade.md to ab earlier version

TODO

Stand-alone

You can run the add-on outside of Home Assistant (e.g. on a remote RPI sending MQTT data of WiFI). All you need is an operating system supported by bleak. See doc/Standalone.md

Contribute / Donate

References

batmon-ha's People

Contributors

fl4p avatar fl4p-old avatar hialus avatar mdshw5 avatar p-zander avatar patman15 avatar webbbn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

batmon-ha's Issues

not work bms jkbms

`devices:

  • address: C8:47:8C:E8:FF:73
    type: jk
    alias: Irenahouse_48
    pin: "123456"
    mqtt_user: roman
    mqtt_password: "513024400"
    mqtt_broker: core-mosquitto
    concurrent_sampling: true
    keep_alive: true
    verbose_log: false
    sample_period: 10
    publish_period: 2
    invert_current: true
    watchdog: true
    expire_values_after: 20
    debug: true`

ERROR [sampling.py:125] Irenahouse_48 error: Device C8:47:8C:E8:FF:73 not discovered ({'B8:BC:5B:A9:98:AB'}) ERROR [main.py:85] Error (num 3) reading BMS: Device C8:47:8C:E8:FF:73 not discovered ({'B8:BC:5B:A9:98:AB'}) ERROR [main.py:86] Stack: Traceback (most recent call last): File "/app/bmslib/jikong.py", line 112, in connect await super().connect(timeout=4) File "/app/bmslib/bt.py", line 26, in connect await self.client.connect(timeout=timeout) File "/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 198, in connect raise BleakError( bleak.exc.BleakError: Device with address C8:47:8C:E8:FF:73 was not found. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/app/main.py", line 81, in fetch_loop await fn() File "/app/bmslib/sampling.py", line 47, in __call__ return await self.sample() File "/app/bmslib/sampling.py", line 65, in sample async with bms: File "/app/bmslib/bt.py", line 113, in __aenter__ await self.connect() File "/app/bmslib/jikong.py", line 115, in connect await self._connect_with_scanner(timeout=timeout) File "/app/bmslib/bt.py", line 47, in _connect_with_scanner raise Exception('Device %s not discovered (%s)' % (self.client.address, discovered)) Exception: Device C8:47:8C:E8:FF:73 not discovered ({'B8:BC:5B:A9:98:AB'}) INFO [sampling.py:61] connecting bms JKBt(C8:47:8C:E8:FF:73) INFO [jikong.py:114] normal connect failed, connecting with scanner ERROR [sampling.py:125] Irenahouse_48 error: Device C8:47:8C:E8:FF:73 not discovered ({'B8:BC:5B:A9:98:AB'}) ERROR [main.py:85] Error (num 4) reading BMS: Device C8:47:8C:E8:FF:73 not discovered ({'B8:BC:5B:A9:98:AB'}) ERROR [main.py:86] Stack: Traceback (most recent call last): File "/app/bmslib/jikong.py", line 112, in connect await super().connect(timeout=4) File "/app/bmslib/bt.py", line 26, in connect await self.client.connect(timeout=timeout) File "/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 198, in connect raise BleakError( bleak.exc.BleakError: Device with address C8:47:8C:E8:FF:73 was not found. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/app/main.py", line 81, in fetch_loop await fn() File "/app/bmslib/sampling.py", line 47, in __call__ return await self.sample() File "/app/bmslib/sampling.py", line 65, in sample async with bms: File "/app/bmslib/bt.py", line 113, in __aenter__ await self.connect() File "/app/bmslib/jikong.py", line 115, in connect await self._connect_with_scanner(timeout=timeout) File "/app/bmslib/bt.py", line 47, in _connect_with_scanner raise Exception('Device %s not discovered (%s)' % (self.client.address, discovered)) Exception: Device C8:47:8C:E8:FF:73 not discovered ({'B8:BC:5B:A9:98:AB'}) INFO [sampling.py:61] connecting bms JKBt(C8:47:8C:E8:FF:73) INFO [jikong.py:114] normal connect failed, connecting with scanner ERROR [main.py:120] MQTT never published a message after 120s, exit ERROR [sampling.py:125] Irenahouse_48 error: Device C8:47:8C:E8:FF:73 not discovered (set()) ERROR [main.py:85] Error (num 5) reading BMS: Device C8:47:8C:E8:FF:73 not discovered (set()) ERROR [main.py:86] Stack: Traceback (most recent call last): File "/app/bmslib/jikong.py", line 112, in connect await super().connect(timeout=4) File "/app/bmslib/bt.py", line 26, in connect await self.client.connect(timeout=timeout) File "/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 198, in connect raise BleakError( bleak.exc.BleakError: Device with address C8:47:8C:E8:FF:73 was not found. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/app/main.py", line 81, in fetch_loop await fn() File "/app/bmslib/sampling.py", line 47, in __call__ return await self.sample() File "/app/bmslib/sampling.py", line 65, in sample async with bms: File "/app/bmslib/bt.py", line 113, in __aenter__ await self.connect() File "/app/bmslib/jikong.py", line 115, in connect await self._connect_with_scanner(timeout=timeout) File "/app/bmslib/bt.py", line 47, in _connect_with_scanner raise Exception('Device %s not discovered (%s)' % (self.client.address, discovered)) Exception: Device C8:47:8C:E8:FF:73 not discovered (set()) INFO [main.py:282] Shutting down ... INFO [main.py:289] Disconnecting JKBt(C8:47:8C:E8:FF:73) INFO [main.py:298] exit signal handler... s6-rc: info: service legacy-services: stopping s6-rc: info: service legacy-services successfully stopped s6-rc: info: service legacy-cont-init: stopping s6-rc: info: service legacy-cont-init successfully stopped s6-rc: info: service fix-attrs: stopping s6-rc: info: service fix-attrs successfully stopped s6-rc: info: service s6rc-oneshot-runner: stopping s6-rc: info: service s6rc-oneshot-runner successfully stopped

1
Screenshot_2023-02-06-11-39-39-069_com jktech bms

Does not work with my version of Daly Smart BMS Bluetooth

Hi,

I have four Sterling Power LiFePO batteries that have built in Daly Smart BMS BT, however they use a different message header to what you are using. There is more information here; https://github.com/roccotsi2/esp32-smart-bms-simulation/blob/main/README.md

I'm in the process of trying to get to test the stand alone code, but use not working too well, and I am not a Python programmer so is step learning curve for me/

extract;

Data format of used Smart BMS from Daly:

This section does not contain the full data format for Daly Smart BMS (there seems to be different Smart BMS that uses another data format, anyway), because I found no official documentation on this and therefore I analyzed the data packets. The results of my analysis are documented in this section. It seems to be the case that Smart BMS is waiting for some data (because Android App does send commands to my simulation while connected to it), but I do not know how to interpret these data yet. This section will be updated if I get new insights on the data format.

Daly Smart BMS expects following commands (data from client to Smart BMS):

Request RunInfo (tab status in Smart BMS app): D2 03 00 00 00 3E D7 B9
Request some unknown values (tab status in Smart BMS app): D2 03 00 A9 00 20 87 91
Request some unknown values (tab parameter in Smart BMS app): D2 03 00 80 00 29 96 5F
Daly Smart BMS uses the following format to send data (data from Smart BMS to a client):

<HEADER_READ><CONTENT_LENGTH>
<-----------CRC relevant------------->
HEADER_READ: always 0xD203
CONTENT_LENGTH: content length in bytes
CONTENT: the content (depends on the information which is sent)
CRC: checksum (2 bytes). The checksum is calculated over HEADER_READ, CONTENT_LENGTH and CONTENT. See function "getCRC" to see how CRC is calculated
The content lengths are in bytes:

Run Info: 124
Run Info Last Battery Value: 32
Set Info: 82
Version Info: 64
PWD: 6

Content format Run Info

All positions needs 2 bytes:

Position 0-31: Battery volt (in mV)
Position 32-39: Battery temperature in Celsius (offset: 40)
Position 40: current V (in 0,1V)
Position 41: current A (offset: 30000 in 0,1A)
Position 42: SOC - State Of Charge in Percent (in 0,1 percent)
Position 43: max cell voltage (in mV)
Position 44: min cell voltage (in mV)
Position 45: ???
Position 46: ???
Position 47: ???
Position 48: ???
Position 49: count battery volt
Position 50: count battery temperatures (max. 8)
Position 51: cycle
Position 52: JH on/off
Position 53: CDMOS on/off (1 = on, everything else off)
Position 54: FDMOS on/off
Position 55: average voltage (in mV)
Position 56: differential voltage (in mV)
Position 57: current KW (in W)
Position 58: Alarm1
Position 59: Alarm2
Position 60: Alarm3
Position 61: Alarm4

Content format Version Info

<App Version: 16 bytes as String> (reversed), <MCU Version: 16 bytes as String>, <Machine Version: 32 bytes as String>

Content format Run Info Last Battery Value

16 values (each 2 byte): Battery volt (in mV)

Remote Pi - Error Reading BMS - Already waiting

Firstly, thank you for your amazing work on this project!
I am having an issue with the remote Pi installation. Removing and re-adding the installation works after a few attempts until a device reboot. After which the "Error Reading BMS - Already Waiting" appears. Cannot run as a service as well. Attached is a screenshot.
BMS

Service won't start

Since the latest update of HA the service is starting but no log, no cpu usage, no memory usage, and no access to the entities.
Are you experiencing the same ?

JBD/xiaoxiang BMS triggers math.isfinite(soc) assertion due to incorrectly parsed unsigned capacity

Debug data from my BMS:
0a:3f 26.23V
00:6f 1.11A
71:7d 290.53 AH charge
da:c0 560.00 AH capacity -- this should be parsed as unsigned, otherwise it's negative.
remaining bytes: 00:00:2c:f3:00:00:00:00:00:00:16:34:03:08:02:0b:64:0b:5f:fa:56:77

I think that the only signed field here should be current:
https://github.com/fl4p/batmon-ha/blob/master/bmslib/jbd.py#L84-L90
I haven't confirmed that, but the data from at least my device is correct in home assistant with that change.

add possibility to support the project

I really enjoy what you built here. Is there a way to support your work? I was searching for a solution to integrate my Liontron LiFePo4 Batteries into home-assistant for months. now finally, there is a comfortable solution for this :)

Please think about adding a PayPal donation link so I can buy you a beer or two 🍺

Fehlermeldung

Hallo ich bekomme immer folgende Meldung:

INFO [jikong.py:114] normal connect failed, connecting with scanner

Woran kann das liegen? Gruss Thomas

First HA setup of the add-on

Hi, so much thanks for this effort!
This is my first installation of this addon.

I do get an error on the latest Home Assistant 2022.9.7 when trying to connect to a SmartShunt via bluetooth.

INFO     [victron.py:63] Connecting DA:88:D3:60:A0:50 to pair
ERROR    [main.py:205] 1 exceptions occurred fetching BMSs
ERROR    [main.py:83] Error (num 2) reading BMS: [org.freedesktop.DBus.Error.UnknownObject] Method "SetDiscoveryFilter" with signature "a{sv}" on interface "org.bluez.Adapter1" doesn't exist
ERROR    [main.py:84] Stack: Traceback (most recent call last):
  File "/app/main.py", line 79, in fetch_loop
    await fn()
  File "/app/main.py", line 206, in fn
    raise exceptions[0]
  File "/app/main.py", line 201, in fn
    await t
  File "/app/main.py", line 118, in _fetch_victron
    result = await victron.fetch_device(dev['address'], psk=dev.get('pin'))
  File "/app/victron.py", line 64, in fetch_device
    async with BleakClient(address, handle_pairing=bool(psk)) as client:
  File "/usr/lib/python3.10/site-packages/bleak/backends/client.py", line 97, in __aenter__
    await self.connect()
  File "/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 190, in connect
    device = await BleakScannerBlueZDBus.find_device_by_address(
  File "/usr/lib/python3.10/site-packages/bleak/backends/scanner.py", line 205, in find_device_by_address
    return await cls.find_device_by_filter(
  File "/usr/lib/python3.10/site-packages/bleak/backends/scanner.py", line 234, in find_device_by_filter
    async with cls(detection_callback=apply_filter, **kwargs):
  File "/usr/lib/python3.10/site-packages/bleak/backends/scanner.py", line 79, in __aenter__
    await self.start()
  File "/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/scanner.py", line 145, in start
    assert_reply(reply)
  File "/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/utils.py", line 23, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.freedesktop.DBus.Error.UnknownObject] Method "SetDiscoveryFilter" with signature "a{sv}" on interface "org.bluez.Adapter1" doesn't exist

I've tried rebuilding the add-on with the bluetooth integration setup and without it setup (thought it was not taking the bluetooth USB device). Tried downgrading to 2022.6.7 (the last before the python breaking changes in 2022.7) but nothing changed so far.

This is my configuration for the addon:

devices:
  - address: DA:88:D3:60:A0:50
    type: victron
    alias: LiFePo4
    pin: "PINHERE"
mqtt_user: user
mqtt_password: password
mqtt_broker: core-mosquitto
concurrent_sampling: false
keep_alive: false
verbose_log: true
sample_period: 30
invert_current: true

Cannot connect JK BMS

Hi - sorry if I'm missing something obvious here, but I would really like to get this working.

First it appears to connect ok (it has the correct bt address & correct Pin)

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
INFO [main.py:68] BT Discovery:
INFO [main.py:73] BT Device �JKbms address=C8:47:8C:E5:02:41
INFO [main.py:73] BT Device 6C-A6-94-6C-7B-04 address=6C:A6:94:6C:7B:04
INFO [main.py:73] BT Device 5A-A1-02-59-86-96 address=5A:A1:02:59:86:96
INFO [main.py:73] BT Device N09XA address=E1:2F:A1:F9:CA:62
INFO [main.py:73] BT Device Tile address=FE:04:2B:6C:AF:EC
INFO [bt.py:126] BMS JKBt(C8:47:8C:E5:02:41) keep alive enabled
INFO [main.py:195] connecting mqtt mosquitto@core-mosquitto
INFO [main.py:232] Fetching 1 BMS + 0 others concurrently, period=1.00s, keep_alive=True
INFO [sampling.py:61] connecting bms JKBt(C8:47:8C:E5:02:41)
INFO [main.py:106] mqtt watchdog loop started with timeout 120.0s

But then I get an error message:

asyncio.exceptions.TimeoutError
ERROR [sampling.py:125] battery1 error: <class 'asyncio.exceptions.TimeoutError'>
INFO [sampling.py:51] bms debug data: %s
ERROR [main.py:85] Error (num 6) reading BMS:
ERROR [main.py:86] Stack: Traceback (most recent call last):
File "/usr/lib/python3.10/asyncio/tasks.py", line 456, 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/main.py", line 81, in fetch_loop
await fn()
File "/app/bmslib/sampling.py", line 47, in call
return await self.sample()
File "/app/bmslib/sampling.py", line 69, in sample
sample = await bms.fetch()
File "/app/bmslib/jikong.py", line 167, in fetch
await self._fetch_futures.wait_for(0x02, self.TIMEOUT)
File "/app/bmslib/init.py", line 44, in wait_for
return await asyncio.wait_for(self._futures[name], timeout)
File "/usr/lib/python3.10/asyncio/tasks.py", line 458, in wait_for
raise exceptions.TimeoutError() from exc

Do you have an idea what the cause of this could be? I have added the pin in the configuration pin: "1234" - I believe it needs the "" or it doesn't work. Or should I be adding the pin some other way? Thanks for your help.

not a real issue, but somebody might have a solution.

Hi, I'm running a 16S setup with a JBD BMS which is just communicating via BT. Batmon log is showing that it gets all required valous from the BMS.
INFO [sampling.py:100] JbdBt(A4:C1:37:00:03:C9) times: connect=0.00s fetch=0.16s
INFO [sampling.py:68] BMS1 result@2022-11-24T13:34:09.862145 BmsSample(U=51.0V,I=-2.10A,P=-107W,q=44.8Ah/280.0,mos=nan°C)
INFO [sampling.py:75] BMS1 volt=3187,3184,3185,3187,3186,3186,3186,3186,3188,3187,3186,3187,3186,3188,3185,3183 temp=[7.1, 13.8, 12.3]

but the graph in HA differs between cells 1-8 and 9-16, as 9-16 writes 0 values occasionally.

changed now the sampling period from 1 to 5 seconds.

If disconected BMS device, HA device has not status unavailable

Hi, the third my issue is, that if is BMS unavailable with BATMON, and Addon running or not running, the device and entities has not status unavailable, and in the history, I see the last values. In the graphs, I see horizontal lines.
Please use availability option for the device.
As you see in the picture, addon has configured two BMS yesterday, as in my another issue
#12
And after some time Addon Stop, and values freeze. If will be working multiple BMS, and some BMS lost connection, other BMS Addon must read, and unavailable BMS must have a status unavailable for entities.
Thank you.
graf

Connection problem (Method "WriteValue" with signature .., doesn't exist)

Hello,

I'm using DalyBMS and it works with this addon, but after some time (sometimes a few hours, sometimes few days) it has an error. Only workaround is to restart addon from HA. After that it is connecting to bms again and it works for a some time.

Is it possible to reconnect to bms if this error is detected? I have 2 BMSes connected and I can see that sometimes only one works, usually if this error happens, I cannot see a new data on entity:

ERROR    [sampling.py:125] daly1 error: [org.freedesktop.DBus.Error.UnknownObject] Method "WriteValue" with signature "aya{sv}" on interface "org.bluez.GattCharacteristic1" doesn't exist
INFO     [sampling.py:51] bms debug data: %s
ERROR    [main.py:85] Error (num 9) reading BMS: [org.freedesktop.DBus.Error.UnknownObject] Method "WriteValue" with signature "aya{sv}" on interface "org.bluez.GattCharacteristic1" doesn't exist
ERROR    [main.py:86] Stack: Traceback (most recent call last):
  File "/app/main.py", line 81, in fetch_loop
    await fn()
  File "/app/bmslib/sampling.py", line 47, in __call__
    return await self.sample()
  File "/app/bmslib/sampling.py", line 69, in sample
    sample = await bms.fetch()
  File "/app/bmslib/daly.py", line 124, in fetch
    status = await self._fetch_status()
  File "/app/bmslib/daly.py", line 150, in _fetch_status
    response_data = await self._q(0x93)
  File "/app/bmslib/daly.py", line 107, in _q
    await self.client.write_gatt_char(self.UUID_TX, msg)
  File "/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 945, in write_gatt_char
    assert_reply(reply)
  File "/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/utils.py", line 23, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.freedesktop.DBus.Error.UnknownObject] Method "WriteValue" with signature "aya{sv}" on interface "org.bluez.GattCharacteristic1" doesn't exist
ERROR    [sampling.py:125] DalyBMS24 error: [org.freedesktop.DBus.Error.UnknownObject] Method "WriteValue" with signature "aya{sv}" on interface "org.bluez.GattCharacteristic1" doesn't exist
INFO     [sampling.py:51] bms debug data: %s
ERROR    [main.py:85] Error (num 10) reading BMS: [org.freedesktop.DBus.Error.UnknownObject] Method "WriteValue" with signature "aya{sv}" on interface "org.bluez.GattCharacteristic1" doesn't exist
ERROR    [main.py:86] Stack: Traceback (most recent call last):
  File "/app/main.py", line 81, in fetch_loop
    await fn()
  File "/app/bmslib/sampling.py", line 47, in __call__
    return await self.sample()
  File "/app/bmslib/sampling.py", line 69, in sample
    sample = await bms.fetch()
  File "/app/bmslib/daly.py", line 124, in fetch
    status = await self._fetch_status()
  File "/app/bmslib/daly.py", line 150, in _fetch_status
    response_data = await self._q(0x93)
  File "/app/bmslib/daly.py", line 107, in _q
    await self.client.write_gatt_char(self.UUID_TX, msg)
  File "/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 945, in write_gatt_char
    assert_reply(reply)
  File "/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/utils.py", line 23, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.freedesktop.DBus.Error.UnknownObject] Method "WriteValue" with signature "aya{sv}" on interface "org.bluez.GattCharacteristic1" doesn't exist
ERROR    [sampling.py:125] daly1 error: [org.freedesktop.DBus.Error.UnknownObject] Method "WriteValue" with signature "aya{sv}" on interface "org.bluez.GattCharacteristic1" doesn't exist
INFO     [sampling.py:51] bms debug data: %s
ERROR    [main.py:85] Error (num 10) reading BMS: [org.freedesktop.DBus.Error.UnknownObject] Method "WriteValue" with signature "aya{sv}" on interface "org.bluez.GattCharacteristic1" doesn't exist
ERROR    [main.py:86] Stack: Traceback (most recent call last):
  File "/app/main.py", line 81, in fetch_loop
    await fn()
  File "/app/bmslib/sampling.py", line 47, in __call__
    return await self.sample()
  File "/app/bmslib/sampling.py", line 69, in sample
    sample = await bms.fetch()
  File "/app/bmslib/daly.py", line 124, in fetch
    status = await self._fetch_status()
  File "/app/bmslib/daly.py", line 150, in _fetch_status
    response_data = await self._q(0x93)
  File "/app/bmslib/daly.py", line 107, in _q
    await self.client.write_gatt_char(self.UUID_TX, msg)
  File "/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 945, in write_gatt_char
    assert_reply(reply)
  File "/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/utils.py", line 23, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.freedesktop.DBus.Error.UnknownObject] Method "WriteValue" with signature "aya{sv}" on interface "org.bluez.GattCharacteristic1" doesn't exist
ERROR    [sampling.py:125] DalyBMS24 error: [org.freedesktop.DBus.Error.UnknownObject] Method "WriteValue" with signature "aya{sv}" on interface "org.bluez.GattCharacteristic1" doesn't exist
INFO     [sampling.py:51] bms debug data: %s
ERROR    [main.py:85] Error (num 11) reading BMS: [org.freedesktop.DBus.Error.UnknownObject] Method "WriteValue" with signature "aya{sv}" on interface "org.bluez.GattCharacteristic1" doesn't exist
ERROR    [main.py:86] Stack: Traceback (most recent call last):
  File "/app/main.py", line 81, in fetch_loop
    await fn()
  File "/app/bmslib/sampling.py", line 47, in __call__
    return await self.sample()
  File "/app/bmslib/sampling.py", line 69, in sample
    sample = await bms.fetch()
  File "/app/bmslib/daly.py", line 124, in fetch
    status = await self._fetch_status()
  File "/app/bmslib/daly.py", line 150, in _fetch_status
    response_data = await self._q(0x93)
  File "/app/bmslib/daly.py", line 107, in _q
    await self.client.write_gatt_char(self.UUID_TX, msg)
  File "/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 945, in write_gatt_char
    assert_reply(reply)
  File "/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/utils.py", line 23, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.freedesktop.DBus.Error.UnknownObject] Method "WriteValue" with signature "aya{sv}" on interface "org.bluez.GattCharacteristic1" doesn't exist

JK-B2A24S20P connection probs

hi, im completely new to HA, github etc.

i have 2x JK-B2A24S20P bms's and i get this when trying to connect:

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
INFO [main.py:68] BT Discovery:
INFO [main.py:73] BT Device 61-24-07-A8-2D-6A address=61:24:07:A8:2D:6A
INFO [bt.py:126] BMS JKBt(C8:47:8C:E5:AB:CB) keep alive enabled
INFO [main.py:195] connecting mqtt @core-mosquitto
INFO [main.py:232] Fetching 1 BMS + 0 others serially, period=1.00s, keep_alive=True
INFO [sampling.py:61] connecting bms JKBt(C8:47:8C:E5:AB:CB)
INFO [main.py:106] mqtt watchdog loop started with timeout 120.0s
INFO [jikong.py:114] normal connect failed, connecting with scanner
WARNING [bt.py:18] BMS JKBt(C8:47:8C:E5:AB:CB) disconnected!
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
WARNING [bt.py:18] BMS JKBt(C8:47:8C:E5:AB:CB) disconnected!
INFO [jikong.py:114] normal connect failed, connecting with scanner
WARNING [bt.py:18] BMS JKBt(C8:47:8C:E5:AB:CB) disconnected!
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
WARNING [bt.py:18] BMS JKBt(C8:47:8C:E5:AB:CB) disconnected!
INFO [jikong.py:114] normal connect failed, connecting with scanner
WARNING [bt.py:18] BMS JKBt(C8:47:8C:E5:AB:CB) disconnected!
ERROR [main.py:120] MQTT never published a message after 120s, exit
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
WARNING [bt.py:18] BMS JKBt(C8:47:8C:E5:AB:CB) disconnected!
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner

my config file is:

  • address: C8:47:8C:E5:AB:CB
    type: jk
    alias: JK-B2A24S20P

im not sure if thats right, but what i have in alias is what shows up on the jk app or bluetooth discovery. the mac address is correct.

im not 100% sure i have mqqt setup correctly, as their didnt seem to be anywhere to create in a username and password? - do i even need one?

any help appriciated thanks :-)

Docker container

Installation requires HA addons. My HA system uses Docker container and it is impossible to use Addons installation. Could you provide instructions on installation with Docker system?

Keeping status of sensors not provided after unavailable BMS

First: really great project and relatively easy to install. Worked for me in 10 min! Thanks....
As the BMS goes in to sleep mode, all values get lost to "unknown".
In the changelog i can see, since v 0.45, the behavior should be different.
What´s the problem here?

BMS repeatedly becomes unavailable and fails to reconnect.

Thank you for this add-on, it's great, though I'm having some issues with stability.

I'm using a 4GB Rpi4, running Debian 11, with HA on top in docker (running some other docker images also to help with off-grid inverter things) and I cannot get the BMS to stay connected for long periods.

The Host is located within half a meter of the BMS, which is a JK 150a device.

The BMS entities will become "unavailable" and I have an automation to restart the add-on after 5mins of this, sometimes it's still not able to reconnect and you must wait longer.

There's nothing else connecting to the BMS that I'm aware of, the log shows this. The reconnect on its own but other times it will not. It disconnects regularly.

Watchdog is on, keep_alive is on, sample period is set to 1.

It will time out 120s trying to reconnect and then must be restarted again.

I can automate around this but would like to know why it fails and how to prevent it.

INFO [sampling.py:100] JKBt(3C:A5:51:86:02:84) times: connect=0.00s fetch=0.29s
INFO [sampling.py:68] 14kWh_Lifpo4 result@2022-12-13T13:04:32.725557 BmsSample(U=53.9V,I=18.04A,P=973W,q=191.8Ah/277.0,mos=29.1°C)
INFO [sampling.py:75] 14kWh_Lifpo4 volt=3364,3358,3390,3373,3378,3369,3353,3389,3358,3358,3372,3391,3385,3358,3351,3356 temp=[23.6, 22.5]
INFO [sampling.py:100] JKBt(3C:A5:51:86:02:84) times: connect=0.00s fetch=0.28s
WARNING [bt.py:19] BMS JKBt(3C:A5:51:86:02:84) disconnected!
INFO [sampling.py:41] connecting bms JKBt(3C:A5:51:86:02:84)
INFO [sampling.py:47] connected bms JKBt(3C:A5:51:86:02:84)!
INFO [sampling.py:68] 14kWh_Lifpo4 result@2022-12-13T13:04:38.282262 BmsSample(U=53.9V,I=17.83A,P=961W,q=191.8Ah/277.0,mos=29.1°C)
INFO [sampling.py:75] 14kWh_Lifpo4 volt=3367,3357,3389,3380,3370,3372,3352,3386,3363,3354,3375,3391,3383,3360,3349,3357

When it fails it looks like this until my automation kicks in.

INFO [sampling.py:75] 14kWh_Lifpo4 volt=3360,3360,3377,3380,3370,3363,3354,3373,3362,3354,3367,3404,3377,3357,3351,3352 temp=[24.1, 23.1]
INFO [sampling.py:100] JKBt(3C:A5:51:86:02:84) times: connect=0.00s fetch=0.30s
WARNING [bt.py:19] BMS JKBt(3C:A5:51:86:02:84) disconnected!
INFO [sampling.py:41] connecting bms JKBt(3C:A5:51:86:02:84)
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
ERROR [main.py:110] MQTT message publish timeout (last 120s ago), exit
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
INFO [jikong.py:114] normal connect failed, connecting with scanner
s6-rc: info: service legacy-services successfully started
INFO [main.py:68] BT Discovery:
INFO [main.py:71] - no devices found -
INFO [bt.py:91] BMS JKBt(3C:A5:51:86:02:84) keep alive enabled
INFO [main.py:178] connecting mqtt XXXX@core-mosquitto
INFO [main.py:201] Fetching 1 BMS + 0 others serially, period=1.00s, keep_alive=True
INFO [sampling.py:41] connecting bms JKBt(3C:A5:51:86:02:84)
INFO [main.py:99] mqtt watchdog loop started with timeout 120.0s
INFO [sampling.py:47] connected bms JKBt(3C:A5:51:86:02:84)!
INFO [sampling.py:64] 14kWh_Lifpo4 subscribing for {'charge': True, 'discharge': True} switch change
INFO [mqtt_util.py:297] subscribe homeassistant/switch/14kWh_Lifpo4/charge/set
INFO [mqtt_util.py:297] subscribe homeassistant/switch/14kWh_Lifpo4/discharge/set
INFO [sampling.py:68] 14kWh_Lifpo4 result@2022-12-13T13:28:35.218390 BmsSample(U=54.0V,I=20.35A,P=1099W,q=195.6Ah/277.0,mos=28.6°C)
INFO [sampling.py:75] 14kWh_Lifpo4 volt=3368,3363,3396,3383,3384,3372,3357,3393,3365,3360,3377,3422,3388,3363,3354,3358

Add-on not available?

I've added the repository, but there's no batmon in my list of available add-ons?

image

bms jk not work, does not connect

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
INFO [main.py:68] BT Discovery:
INFO [main.py:73] BT Device [TV] Samsung Q60 Series (55) address=B8:BC:5B:A9:98:AB
INFO [bt.py:91] BMS JKBt(C8:47:8C:E8:FF:73) keep alive enabled
INFO [main.py:178] connecting mqtt roman@core-mosquitto
INFO [main.py:201] Fetching 1 BMS + 0 others serially, period=10.00s, keep_alive=True
INFO [sampling.py:41] connecting bms JKBt(C8:47:8C:E8:FF:73)
INFO [main.py:99] mqtt watchdog loop started with timeout 120.0s
INFO [jikong.py:114] normal connect failed, connecting with scanner
ERROR [sampling.py:97] JK-BD6A20S10P error: Device C8:47:8C:E8:FF:73 not discovered ({'B8:BC:5B:A9:98:AB'})
ERROR [main.py:240] 1 exceptions occurred fetching BMSs
ERROR [main.py:85] Error (num 1) reading BMS: Device C8:47:8C:E8:FF:73 not discovered ({'B8:BC:5B:A9:98:AB'})
ERROR [main.py:86] Stack: Traceback (most recent call last):
File "/app/bmslib/jikong.py", line 112, in connect
await super().connect(timeout=4)
File "/app/bmslib/bt.py", line 22, in connect
await self.client.connect(timeout=timeout)
File "/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 198, in connect
raise BleakError(
bleak.exc.BleakError: Device with address C8:47:8C:E8:FF:73 was not found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/main.py", line 81, in fetch_loop
await fn()
File "/app/main.py", line 241, in fn
raise exceptions[0]
File "/app/main.py", line 236, in fn
await t
File "/app/bmslib/sampling.py", line 32, in call
return await self.sample()
File "/app/bmslib/sampling.py", line 45, in sample
async with bms:
File "/app/bmslib/bt.py", line 78, in aenter
await self.connect()
File "/app/bmslib/jikong.py", line 115, in connect
await self._connect_with_scanner(timeout=timeout)
File "/app/bmslib/bt.py", line 35, in _connect_with_scanner
raise Exception('Device %s not discovered (%s)' % (self.client.address, discovered))
Exception: Device C8:47:8C:E8:FF:73 not discovered ({'B8:BC:5B:A9:98:AB'})

Integration not working for me... attaching logs

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
Traceback (most recent call last):
File "/app/main.py", line 17, in
from bmslib.sampling import BmsSampler
File "/app/bmslib/sampling.py", line 6, in
from mqtt_util import publish_sample, publish_cell_voltages, publish_temperatures, publish_hass_discovery
File "/app/mqtt_util.py", line 7, in
from util import get_logger
ModuleNotFoundError: No module named 'util'
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

soc-current/soc_power are inverted

I would expect during discharge that the current and power would be negative (e.g, -3.5) and during charging they would be positive. But here they are reversed..

When I read the data using the iOS app that is the way they are shown. And when I read them in my own code (C# serial/rs485), they are correct as well.

Entity rounding

Hi, first of all thanks for your work, the plugin is great. At the same time, I would like to request from the rounding of values ​​in entities that sometimes, but not always, have a lot of decimal places added, as can be seen in the attached picture from the HA panel.
Please, can you round the values and fix their decimal places?
I have JK BMS and in the near time will be the second the same type.
Thank you very much.
round
round1

Paused command, have to cancel the command for it to go on.

Hi,

I do have a bit of an issue which I found no other instance here.

I configured the standalone version on a 1GB RAM La Frite using Armbian 22.08.6 Jammy with Linux 5.10.147-meson64.
Had to install bluez using apt-get install bluez before batmon-ha could use it.

Then executed all the standalone commands from https://github.com/fl4p/batmon-ha/blob/master/doc/Standalone.md

Also configured options.json like this. (Don't know why but the command seems to not read my options.json file inside the batmon-ha directory, as the standalone directions state so far. I read the log output and it was asking for it on /data/options.json):

ismael@lafrite:~/batmon-ha$ cat /data/options.json
{
  "devices": [
    {
      "address": "C8:47:8C:E8:4F:07",
      "type": "jk",
      "alias": "bateria-casa"
    },
    {
      "address": "DA:88:D3:60:A0:50",
      "type": "victron",
      "alias": "bateria-aires",
      "pin": "XXXXXX"
    }
  ],
  "mqtt_broker": "192.168.0.2",
  "mqtt_user": "user",
  "mqtt_password": "password",
  "concurrent_sampling": true,
  "keep_alive": false,
  "verbose_log": true,
  "sample_period": 10.0,
  "invert_current": true
}
ismael@lafrite:~/batmon-ha$

The command stays like this indefinitely (why I used the work "paused" 😄):
INFO [sampling.py:41] connecting bms JKBt(C8:47:8C:E8:4F:07)

I have to manually cancel it with Ctrl+C for it to begin stopping it and actually reads the BMSs and sends the data to via MQTT to the Home Assistant OS VM.

Code clip in question:

INFO     [main.py:201] Fetching 1 BMS + 1 others concurrently, period=10.00s, keep_alive=False
INFO     [sampling.py:41] connecting bms JKBt(C8:47:8C:E8:4F:07)
^CINFO     [main.py:263] exit signal handler...
INFO     [jikong.py:114] normal connect failed, connecting with scanner
ERROR    [base_events.py:1744] Task exception was never retrieved

Full log of the command execution and cancellation with Ctrl+C while I wrote this issue entry. It was paused for a good 5 minutes until I executed the cancel hotkey:

 _            _____     _ _
| |    __ _  |  ___| __(_) |_ ___
| |   / _` | | |_ | '__| | __/ _ \
| |__| (_| | |  _|| |  | | ||  __/
|_____\__,_| |_|  |_|  |_|\__\___|

Welcome to Armbian 22.08.6 Jammy with Linux 5.10.147-meson64

System load:   2%               Up time:       9:27
Memory usage:  22% of 926M      IP:            172.17.0.1 192.168.0.15
CPU temp:      45°C             Usage of /:    4% of 56G
RX today:      29.1 MiB

[ 0 security updates available, 1 updates total: apt upgrade ]
Last check: 2022-11-08 00:16

Last login: Tue Nov  8 00:16:47 2022 from 192.168.0.11
ismael@lafrite:~$ cd batmon-ha/
ismael@lafrite:~/batmon-ha$ python3 main.py
INFO     [main.py:68] BT Discovery:
INFO     [main.py:73] BT Device   bateria-casa   address=C8:47:8C:E8:4F:07
INFO     [main.py:73] BT Device   bateria-aires   address=DA:88:D3:60:A0:50
INFO     [main.py:73] BT Device   02-5D-39-58-42-5E   address=02:5D:39:58:42:5E
INFO     [main.py:73] BT Device   47-2F-1B-4C-56-42   address=47:2F:1B:4C:56:42
INFO     [main.py:73] BT Device   4A-B3-ED-39-9A-8F   address=4A:B3:ED:39:9A:8F
INFO     [main.py:73] BT Device   Core400s   address=78:E3:6D:AE:8E:FE
INFO     [main.py:136] Verbose logging enabled
INFO     [victron.py:63] Connecting None to pair
ERROR    [main.py:172] Error pairing victron device: Device with address None was not found.
INFO     [main.py:178] connecting mqtt [email protected]
INFO     [main.py:201] Fetching 1 BMS + 1 others concurrently, period=10.00s, keep_alive=False
INFO     [sampling.py:41] connecting bms JKBt(C8:47:8C:E8:4F:07)
^CINFO     [main.py:263] exit signal handler...
INFO     [jikong.py:114] normal connect failed, connecting with scanner
ERROR    [base_events.py:1744] Task exception was never retrieved
future: <Task finished name='Task-2' coro=<PairingAgentBlueZDBus.register() done, defined at /home/ismael/.local/lib/python3.10/site-packages/bleak/backends/bluezdbus/agent.py:72> exception=BrokenPipeError(32, 'Broken pipe')>
Traceback (most recent call last):
  File "/home/ismael/.local/lib/python3.10/site-packages/bleak/backends/bluezdbus/agent.py", line 85, in register
    bus = await MessageBus(bus_type=BusType.SYSTEM).connect()
  File "/home/ismael/.local/lib/python3.10/site-packages/dbus_next/aio/message_bus.py", line 149, in connect
    await self._authenticate()
  File "/home/ismael/.local/lib/python3.10/site-packages/dbus_next/aio/message_bus.py", line 392, in _authenticate
    await self._loop.sock_sendall(self._sock, Authenticator._format_line(response))
  File "/usr/lib/python3.10/asyncio/selector_events.py", line 441, in sock_sendall
    n = sock.send(data)
BrokenPipeError: [Errno 32] Broken pipe
INFO     [sampling.py:47] connected bms JKBt(C8:47:8C:E8:4F:07)!
INFO     [sampling.py:64] bateria-casa subscribing for {'charge': True, 'discharge': True} switch change
INFO     [mqtt_util.py:297] subscribe homeassistant/switch/bateria-casa/charge/set
INFO     [mqtt_util.py:297] subscribe homeassistant/switch/bateria-casa/discharge/set
INFO     [sampling.py:68] bateria-casa result@2022-11-08T09:57:06.224081 BmsSample(U=54.7V,I=45.06A,P=2467W,q=279.8Ah/380.0,mos=35.3°C)
INFO     [sampling.py:75] bateria-casa volt=3426,3420,3422,3423,3425,3420,3417,3425,3417,3421,3418,3422,3421,3420,3420,3425 temp=[28.7, 28.5]
INFO     [sampling.py:100] JKBt(C8:47:8C:E8:4F:07) times: connect=814.19s fetch=0.62s
INFO     [victron.py:63] Connecting DA:88:D3:60:A0:50 to pair
INFO     [main.py:249] Shutting down ...
INFO     [main.py:254] Disconnecting JKBt(C8:47:8C:E8:4F:07)
INFO     [main.py:263] exit signal handler...
ismael@lafrite:~/batmon-ha$

By the way, I always see this in the output althoug you see victron is configured with a valid address in the options.json:
ERROR [main.py:172] Error pairing victron device: Device with address None was not found.

asyncio.exceptions.TimeoutError when enable 2 or more jbd bms in configuration

ERROR [sampling.py:125] xiaoxiang_BMS_8KWT error: <class 'asyncio.exceptions.TimeoutError'>
INFO [sampling.py:51] bms debug data: %s
ERROR [sampling.py:125] xiaoxiang_BMS_11KWT error: <class 'asyncio.exceptions.TimeoutError'>
INFO [sampling.py:51] bms debug data: %s
ERROR [main.py:274] 2 exceptions occurred fetching BMSs
ERROR [main.py:85] Error (num 6) reading BMS:
ERROR [main.py:86] Stack: Traceback (most recent call last):
File "/usr/lib/python3.10/asyncio/tasks.py", line 456, 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/main.py", line 81, in fetch_loop
await fn()
File "/app/main.py", line 275, in fn
raise exceptions[0]
File "/app/main.py", line 270, in fn
await t
File "/app/bmslib/sampling.py", line 47, in call
return await self.sample()
File "/app/bmslib/sampling.py", line 69, in sample
sample = await bms.fetch()
File "/app/bmslib/jbd.py", line 75, in fetch
buf = await self._q(cmd=0x03)
File "/app/bmslib/jbd.py", line 69, in _q
return await self._fetch_futures.wait_for(cmd, self.TIMEOUT)
File "/app/bmslib/init.py", line 44, in wait_for
return await asyncio.wait_for(self._futures[name], timeout)
File "/usr/lib/python3.10/asyncio/tasks.py", line 458, in wait_for
raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError

Standalone JBD hangs on connect no response and no timeout

For some reason it seems like that the:
await self.client.connect(timeout=timeout)
hangs the process, if I ctrl-c it says connected after some time, and also it does not timeout after 20 sec or longer.

It's very weird because I had my own python code which talks with the bms also using Bleak, but found your implemtation more done and looked really mature.

Anyone who might have a clue how to prevent the connect to hang?

JK BMS connected but not all values correctly displayed in HA

Description:

I have a JK BMS that is successfully connected to Home Assistant, but I'm experiencing issues with the data being displayed. Specifically, only the values for "battery1 cell_voltages (x)" are correctly displayed, while all other values are either blank or incorrect, as can be seen in the attached screenshots.

I have checked the logs, but I can't find any visible errors. I have also tried restarting both the BMS and Home Assistant, but the issue persists.

Any suggestions on how to fix this issue or troubleshoot further would be greatly appreciated.

Steps to reproduce:

Connect the BMS to Home Assistant
Observe the displayed values in Home Assistant
Expected behavior:

All values from the BMS should be correctly displayed in Home Assistant.

Actual behavior:

Only the values for "battery1 cell_voltages (x)" are correctly displayed, while all other values are either blank or incorrect.

Screenshots:

https://gyazo.com/79408aead6b5664cced4d571f7ed2f0a
https://gyazo.com/9518a9b7cfde28ec956b6266d4c10b6e

Environment:

BMS model: JK_B2A8S20P; Firmware: 11.25H; Hardware: 11.XW
Home Assistant version: Home Assistant 2023.2.5
Operating system: [insert operating system here]
Logs:


INFO     [sampling.py:94] battery1 result@2023-02-26T15:33:11.288634 BmsSample(U=0.0V,I=-0.00A,P=-0W,q=15204.4Ah/0.0,mos=0.0°C)
DEBUG    [mqtt_util.py:102] topic battery1/meter/total_energy data not changed
DEBUG    [mqtt_util.py:102] topic battery1/meter/total_energy_discharge data not changed
DEBUG    [mqtt_util.py:102] topic battery1/meter/total_energy_charge data not changed
DEBUG    [mqtt_util.py:102] topic battery1/meter/total_charge data not changed
DEBUG    [mqtt_util.py:102] topic battery1/cell_voltages/1 data not changed
DEBUG    [client.py:2529] Sending PUBLISH (d0, q0, r0, m7507), 'b'battery1/cell_voltages/2'', ... (5 bytes)
DEBUG    [client.py:2529] Sending PUBLISH (d0, q0, r0, m7508), 'b'battery1/cell_voltages/3'', ... (5 bytes)
DEBUG    [mqtt_util.py:102] topic battery1/cell_voltages/4 data not changed
DEBUG    [mqtt_util.py:102] topic battery1/temperatures/1 data not changed
DEBUG    [mqtt_util.py:102] topic battery1/temperatures/2 data not changed
INFO     [sampling.py:103] battery1 volt=3335,3335,3335,3336 temp=[0.0, 0.0]
INFO     [sampling.py:128] JKBt(C8:47:8C:EA:BF:0D) times: connect=0.00s fetch=0.11s
DEBUG    [client.py:1123] received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_C8_47_8C_EA_BF_0D/service000e/char0011): ['org.bluez.GattCharacteristic1', {'Value': <dbus_next.signature.Variant ('ay', b"U\xaa\xeb\x90\x02S\x07\r\x07\r\x07\r\x08\r\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00\x07\r\x01\x00\x00\x02'\x00'\x00&\x00&\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")>}, []]
DEBUG    [jikong.py:72] header, clear buf bytearray(b'')
DEBUG    [jikong.py:77] bms msg(128) (buf128): 55 aa eb 90 2 53 7 d 7 d 7 d 8 d 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 f 0 0 0 7 d 1 0 0 2 27 0 27 0 26 0 26 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DEBUG    [client.py:1123] received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_C8_47_8C_EA_BF_0D/service000e/char0011): ['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\xe8\x00\x00\x00\x00\x00')>}, []]
DEBUG    [jikong.py:77] bms msg(22) (buf150): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 e8 0 0 0 0 0
DEBUG    [client.py:1123] received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_C8_47_8C_EA_BF_0D/service000e/char0011): ['org.bluez.GattCharacteristic1', {'Value': <dbus_next.signature.Variant ('ay', b"\x1c4\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc7\x00\xc5\x00\x00\x00\x00\x00\x00\x00\x00a\x02%\x04\x00\xc0E\x04\x00\x05\x00\x00\x00J\x04\x18\x00d\x00\x00\x00K\x8c'\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x01\x00\x00\x00\x9d\x03\x00\x00\x00\x00:\xccA@\x00\x00\x00\x006\x05\x00\x00\x00\x01\x00\x01\x00\x05\x00\x00Z\x03\n\x00\x00\x00\x00\x00\xe8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")>}, []]
DEBUG    [jikong.py:77] bms msg(128) (buf278): 1c 34 0 0 0 0 0 0 0 0 0 0 c7 0 c5 0 0 0 0 0 0 0 0 61 2 25 4 0 c0 45 4 0 5 0 0 0 4a 4 18 0 64 0 0 0 4b 8c 27 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ff 0 1 0 0 0 9d 3 0 0 0 0 3a cc 41 40 0 0 0 0 36 5 0 0 0 1 0 1 0 5 0 0 5a 3 a 0 0 0 0 0 e8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DEBUG    [client.py:1123] received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_C8_47_8C_EA_BF_0D/service000e/char0011): ['org.bluez.GattCharacteristic1', {'Value': <dbus_next.signature.Variant ('ay', b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfe\xff\x7f\xdc/\x01\x01\x01\x00\x00\x00\x00J')>}, []]
DEBUG    [jikong.py:77] bms msg(22) (buf300): 0 0 0 0 0 0 0 0 0 fe ff 7f dc 2f 1 1 1 0 0 0 0 4a
DEBUG    [jikong.py:99] got response 2 (len300)
DEBUG    [client.py:1123] received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_C8_47_8C_EA_BF_0D/service000e/char0011): ['org.bluez.GattCharacteristic1', {'Value': <dbus_next.signature.Variant ('ay', b"U\xaa\xeb\x90\x02T\x07\r\x07\r\x07\r\x07\r\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00\x07\r\x01\x00\x00\x02'\x00'\x00&\x00&\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")>}, []]
DEBUG    [jikong.py:72] header, clear buf bytearray(b'')
DEBUG    [jikong.py:77] bms msg(128) (buf128): 55 aa eb 90 2 54 7 d 7 d 7 d 7 d 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 f 0 0 0 7 d 1 0 0 2 27 0 27 0 26 0 26 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DEBUG    [client.py:1123] received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_C8_47_8C_EA_BF_0D/service000e/char0011): ['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\xe8\x00\x00\x00\x00\x00')>}, []]
DEBUG    [jikong.py:77] bms msg(22) (buf150): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 e8 0 0 0 0 0
DEBUG    [client.py:1123] received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_C8_47_8C_EA_BF_0D/service000e/char0011): ['org.bluez.GattCharacteristic1', {'Value': <dbus_next.signature.Variant ('ay', b"\x1c4\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc7\x00\xc5\x00\x00\x00\x00\x00\x00\x00\x00a\x02%\x04\x00\xc0E\x04\x00\x05\x00\x00\x00J\x04\x18\x00d\x00\x00\x00L\x8c'\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x01\x00\x00\x00\x9d\x03\x00\x00\x00\x00:\xccA@\x00\x00\x00\x006\x05\x00\x00\x00\x01\x00\x01\x00\x05\x00\x00_\x03\n\x00\x00\x00\x00\x00\xe8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")>}, []]
DEBUG    [jikong.py:77] bms msg(128) (buf278): 1c 34 0 0 0 0 0 0 0 0 0 0 c7 0 c5 0 0 0 0 0 0 0 0 61 2 25 4 0 c0 45 4 0 5 0 0 0 4a 4 18 0 64 0 0 0 4c 8c 27 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ff 0 1 0 0 0 9d 3 0 0 0 0 3a cc 41 40 0 0 0 0 36 5 0 0 0 1 0 1 0 5 0 0 5f 3 a 0 0 0 0 0 e8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DEBUG    [client.py:1123] received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_C8_47_8C_EA_BF_0D/service000e/char0011): ['org.bluez.GattCharacteristic1', {'Value': <dbus_next.signature.Variant ('ay', b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfe\xff\x7f\xdc/\x01\x01\x01\x00\x00\x00\x00P')>}, []]
DEBUG    [jikong.py:77] bms msg(22) (buf300): 0 0 0 0 0 0 0 0 0 fe ff 7f dc 2f 1 1 1 0 0 0 0 50
DEBUG    [jikong.py:99] got response 2 (len300)
INFO     [sampling.py:128] JKBt(C8:47:8C:EA:BF:0D) times: connect=0.00s fetch=0.06s

Not work "charge" and "discharge" switch

I have Daly Smart BMS connected over BT.
MQTT commands send to programm correct, MQTT status temporary changed, but switch command "charge" and "discarge" status not sent to BMS. Over timeout switch status return old status.

Daly BMS Error

Hi There,

Thank you for creating this project. It is exactly what I was looking for :).

I'm attempting to connect to a new Daly BMS that arrived about a week ago. I was initially receiving an error stating "BleakError: Client is already connected." After turning the loggin up I can see that the actual error (as deep into the code that I can see) is "reading BMS: Characteristic with UUID 17 could not be found!"

This occurs at line 'await self.client.start_notify(self.UUID_RX, self._notification_callback)' in bmslib/daly.py

I can see that the UUID 17 is defined further up that file but that's as far as I have got so far.

Any help would be appreciated. I'm trying to research how you determine those values.

Thanks, Alex

esphome bluetooth proxy?

Been trying to get a remote daly to show up to a working HA batmon. I can see and pull data just fine when the HA computer is close, but when they're separated and have an esphome proxy attempting to forward connections - no device found. Am I being stupid here? or should this setup work?

I can see the device in the proxy logs, just fine

Two the same JK BMS B2A24S150P not working at the same time

Hi, today I trying add the second BMS and it not working.
Config:
devices:

  • address: C8:47:8C:E4:51:FA
    type: jk
    alias: battery1
    pin: "2580"
  • address: C2:6C:77:DD:4A:C7
    type: jk
    alias: battery2
    pin: "2580"
    mqtt_user: jkbms
    mqtt_password: mypassword
    mqtt_broker: core-mosquitto
    concurrent_sampling: true
    keep_alive: true
    verbose_log: true
    sample_period: 1

Log:
s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
INFO [main.py:76] BT Discovery:
INFO [main.py:79] - no devices found -
INFO [main.py:119] Verbose logging enabled
INFO [bt.py:53] BMS JKBt(C8:47:8C:E4:51:FA) keep alive enabled
INFO [bt.py:53] BMS JKBt(C2:6C:77:DD:4A:C7) keep alive enabled
INFO [main.py:160] connecting mqtt jkbms@core-mosquitto
DEBUG [client.py:2529] Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b''
INFO [sampling.py:33] connecting bms JKBt(C8:47:8C:E4:51:FA)
DEBUG [jikong.py:94] starting scan
DEBUG [scanner.py:132] cached devices: {'/org/bluez/hci0/dev_C8_47_8C_E4_51_FA': {'Address': 'C8:47:8C:E4:51:FA', 'AddressType': 'public', 'Name': 'Bat1', 'Alias': 'Bat1', 'Paired': False, 'Trusted': False, 'Blocked': False, 'LegacyPairing': False, 'RSSI': -92, 'Connected': True, 'UUIDs': ['00001800-0000-1000-8000-00805f9b34fb', '00001801-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', '0000180f-0000-1000-8000-00805f9b34fb', '0000ffe0-0000-1000-8000-00805f9b34fb', 'f000ffc0-0451-4000-b000-000000000000'], 'Modalias': 'usb:v045Ep0040d0300', 'Adapter': '/org/bluez/hci0', 'ManufacturerData': {2917: b'\x88\xa0\xc8G\x8c\xe4Q\xfa'}, 'ServicesResolved': True}}
DEBUG [scanner.py:282] received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0): ['org.bluez.Adapter1', {'Discovering': <dbus_next.signature.Variant ('b', True)>}, []]
DEBUG [client.py:507] Disconnecting (None)
DEBUG [client.py:513] already disconnected (None)
DEBUG [jikong.py:110] retry after error Device C8:47:8C:E4:51:FA not discovered (set())
DEBUG [client.py:507] Disconnecting (None)
DEBUG [client.py:513] already disconnected (None)
DEBUG [jikong.py:110] retry after error Device C8:47:8C:E4:51:FA not discovered (set())
DEBUG [client.py:507] Disconnecting (None)
DEBUG [client.py:513] already disconnected (None)
DEBUG [jikong.py:110] retry after error Device C8:47:8C:E4:51:FA not discovered (set())
DEBUG [client.py:507] Disconnecting (None)
DEBUG [client.py:513] already disconnected (None)
DEBUG [jikong.py:110] retry after error Device C8:47:8C:E4:51:FA not discovered (set())
DEBUG [client.py:507] Disconnecting (None)
DEBUG [client.py:513] already disconnected (None)
DEBUG [jikong.py:110] retry after error Device C8:47:8C:E4:51:FA not discovered (set())

High CPU usage, no readings

Apparently all of the connections are OK, but there is no battery info.

JK BMS: JK_BD4A8S4P
HomeAssistant on Odriod-C2 with Edimax Bluetooth USB dongle

  • Home Assistant 2022.12.8
  • Supervisor 2022.12.1
  • Operating System 9.4
  • Frontend 20221213.1 - latest

batmon log:

INFO [main.py:178] connecting mqtt batmon@core-mosquitto
DEBUG [client.py:2529] Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b''
INFO [main.py:201] Fetching 1 BMS + 0 others serially, period=1.00s, keep_alive=False
INFO [sampling.py:41] connecting bms JKBt(20:22:08:11:0A:35)
DEBUG [client.py:181] Connecting to device @ 20:22:08:11:0A:35 with hci0
DEBUG [client.py:2529] Received CONNACK (0, 0)
DEBUG [client.py:2529] Sending PINGREQ
DEBUG [client.py:2529] Received PINGRESP
DEBUG [client.py:2529] Sending PINGREQ
...the last two lines repeat indefinitely

Supervisor log:

23-01-02 21:16:57 INFO (SyncWorker_2) [supervisor.docker.addon] Starting Docker add-on 2af0a32d/aarch64-addon-batmon with version 0.0.46
23-01-02 21:17:04 INFO (MainThread) [supervisor.auth] Auth request from 'core_mosquitto' for 'batmon'
23-01-02 21:17:04 INFO (MainThread) [supervisor.auth] Successful login for 'batmon'

Devices/batmon:

Sensors (updating live)

  • CPU percent 23.98%
  • Memory percent 1.11%
  • Newest version 0.0.46
  • Running Running
  • Version 0.0.46

And that's it - no battery info.
Did the MQTT not auto-configure? I don't see autoconfigure messages while listening to # in MQTT
Is 25% CPU usage normal?

Error in mqtt auto configuration

From HA logs:

2022-11-23 23:18:59.551 ERROR (MainThread) [homeassistant.util.logging] Exception in async_discover when dispatching 'mqtt_discovery_new_binary_sensor_mqtt': ({'unique_id': 'battery1__switch_charge', 'name': 'battery1 charge switch', 'device_class': 'outlet', 'json_attributes_topic': 'battery1/charge', 'expire_after': 40, 'device': {'identifiers': ['battery1'], 'name': 'battery1'}, 'state_topic': 'battery1/switch/charge', 'command_topic': 'homeassistant/switch/battery1/charge/set', 'platform': 'mqtt'},)
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/mqtt/mixins.py", line 327, in async_discover
config: DiscoveryInfoType = discovery_schema(discovery_payload)
File "/usr/local/lib/python3.10/site-packages/voluptuous/schema_builder.py", line 272, in call
return self._compiled([], data)
File "/usr/local/lib/python3.10/site-packages/voluptuous/schema_builder.py", line 595, in validate_dict
return base_validate(path, iteritems(data), out)
File "/usr/local/lib/python3.10/site-packages/voluptuous/schema_builder.py", line 433, in validate_mapping
raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: expected BinarySensorDeviceClass or one of 'battery', 'battery_charging', 'carbon_monoxide', 'cold', 'connectivity', 'door', 'garage_door', 'gas', 'heat', 'light', 'lock', 'moisture', 'motion', 'moving', 'occupancy', 'opening', 'plug', 'power', 'presence', 'problem', 'running', 'safety', 'smoke', 'sound', 'tamper', 'update', 'vibration', 'window' for dictionary value @ data['device_class']

'device_class': 'outlet' is not in BinarySensorDeviceClass. Change to 'plug' maybe.

Error Warnings

Hello, i'm trying to connect with your Batmon-ha, but i've some errors, and i don't know if the error are from configuration or from the connection to the bms or Victron.
Could you check it
WARNING [mqtt_util.py:102] mqtt publish battery1/temperatures/1 failed: 4 (4, 1319) INFO [sampling.py:68] battery1 volt=3288,3291,3291,3291,3291,3290,3290,3288,3289,3290,3292,3289,3287,3287,3297,3686 temp=[22] INFO [sampling.py:93] DalyBt(40:16:09:01:58:4D) times: connect=0.00s fetch=0.92s WARNING [mqtt_util.py:102] mqtt publish battery1/soc/total_voltage failed: 4 (4, 1320) WARNING [mqtt_util.py:102] mqtt publish battery1/soc/current failed: 4 (4, 1321) WARNING [mqtt_util.py:102] mqtt publish battery1/soc/balance_current failed: 4 (4, 1322) WARNING [mqtt_util.py:102] mqtt publish battery1/soc/soc_percent failed: 4 (4, 1323) WARNING [mqtt_util.py:102] mqtt publish battery1/soc/power failed: 4 (4, 1324) WARNING [mqtt_util.py:102] mqtt publish battery1/soc/capacity failed: 4 (4, 1325) WARNING [mqtt_util.py:102] mqtt publish battery1/soc/cycle_capacity failed: 4 (4, 1326) WARNING [mqtt_util.py:102] mqtt publish battery1/mosfet_status/capacity_ah failed: 4 (4, 1327) WARNING [mqtt_util.py:102] mqtt publish battery1/mosfet_status/temperature failed: 4 (4, 1328) INFO [sampling.py:61] battery1 result@2022-11-01T16:23:38.028242 BmsSample(U=52.6V,I=0.00A,P=0W,q=230.0Ah/230.0,mos=nan°C) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/1 failed: 4 (4, 1329) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/2 failed: 4 (4, 1330) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/3 failed: 4 (4, 1331) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/4 failed: 4 (4, 1332) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/5 failed: 4 (4, 1333) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/6 failed: 4 (4, 1334) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/7 failed: 4 (4, 1335) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/8 failed: 4 (4, 1336) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/9 failed: 4 (4, 1337) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/10 failed: 4 (4, 1338) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/11 failed: 4 (4, 1339) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/12 failed: 4 (4, 1340) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/13 failed: 4 (4, 1341) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/14 failed: 4 (4, 1342) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/15 failed: 4 (4, 1343) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/16 failed: 4 (4, 1344) WARNING [mqtt_util.py:102] mqtt publish battery1/temperatures/1 failed: 4 (4, 1345) INFO [sampling.py:68] battery1 volt=3288,3290,3290,3290,3290,3290,3290,3288,3288,3290,3288,3288,3286,3286,3296,3280 temp=[22] INFO [sampling.py:93] DalyBt(40:16:09:01:58:4D) times: connect=0.00s fetch=0.93s WARNING [mqtt_util.py:102] mqtt publish battery1/soc/total_voltage failed: 4 (4, 1346) WARNING [mqtt_util.py:102] mqtt publish battery1/soc/current failed: 4 (4, 1347) WARNING [mqtt_util.py:102] mqtt publish battery1/soc/balance_current failed: 4 (4, 1348) WARNING [mqtt_util.py:102] mqtt publish battery1/soc/soc_percent failed: 4 (4, 1349) WARNING [mqtt_util.py:102] mqtt publish battery1/soc/power failed: 4 (4, 1350) WARNING [mqtt_util.py:102] mqtt publish battery1/soc/capacity failed: 4 (4, 1351) WARNING [mqtt_util.py:102] mqtt publish battery1/soc/cycle_capacity failed: 4 (4, 1352) WARNING [mqtt_util.py:102] mqtt publish battery1/mosfet_status/capacity_ah failed: 4 (4, 1353) WARNING [mqtt_util.py:102] mqtt publish battery1/mosfet_status/temperature failed: 4 (4, 1354) INFO [sampling.py:61] battery1 result@2022-11-01T16:23:39.964636 BmsSample(U=53.1V,I=0.00A,P=0W,q=230.0Ah/230.0,mos=nan°C) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/1 failed: 4 (4, 1355) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/2 failed: 4 (4, 1356) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/3 failed: 4 (4, 1357) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/4 failed: 4 (4, 1358) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/5 failed: 4 (4, 1359) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/6 failed: 4 (4, 1360) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/7 failed: 4 (4, 1361) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/8 failed: 4 (4, 1362) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/9 failed: 4 (4, 1363) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/10 failed: 4 (4, 1364) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/11 failed: 4 (4, 1365) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/12 failed: 4 (4, 1366) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/13 failed: 4 (4, 1367) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/14 failed: 4 (4, 1368) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/15 failed: 4 (4, 1369) WARNING [mqtt_util.py:102] mqtt publish battery1/cell_voltages/16 failed: 4 (4, 1370) WARNING [mqtt_util.py:102] mqtt publish battery1/temperatures/1 failed: 4 (4, 1371) INFO [sampling.py:68] battery1 volt=3289,3291,3291,3291,3291,3291,3291,3289,3289,3291,3293,3289,3287,3287,3297,3836 temp=[22] INFO [sampling.py:93] DalyBt(40:16:09:01:58:4D) times: connect=0.00s fetch=0.93s WARNING [mqtt_util.py:102] mqtt publish battery1/soc/total_voltage failed: 4 (4, 1372) WARNING [mqtt_util.py:102] mqtt publish battery1/soc/current failed: 4 (4, 1373) WARNING [mqtt_util.py:102] mqtt publish battery1/soc/balance_current failed: 4 (4, 1374) WARNING [mqtt_util.py:102] mqtt publish battery1/soc/soc_percent failed: 4 (4, 1375) WARNING [mqtt_util.py:102] mqtt publish battery1/soc/power failed: 4 (4, 1376) WARNING [mqtt_util.py:102] mqtt publish battery1/soc/capacity failed: 4 (4, 1377) WARNING [mqtt_util.py:102] mqtt publish battery1/soc/cycle_capacity failed: 4 (4, 1378) WARNING [mqtt_util.py:102] mqtt publish battery1/mosfet_status/capacity_ah failed: 4 (4, 1379) WARNING [mqtt_util.py:102] mqtt publish battery1/mosfet_status/temperature failed: 4 (4, 1380) INFO [sampling.py:61] battery1 result@2022-11-01T16:23:41.897866

Charge/Discharge switches problem

Thanks a lot for this sw BATMON rel. 50. It works quite well with hassio, running on Raspi 3 B.
I use it on 3 JBD BMS with 3 batteries packs
48V (1 x LIFEPO4 and 2 x Lion), but it has one major problem: the two charge/discharge switches don't work especially switching from off to on, i.e. it appears as they don't receive immediate confirmation from the MQTT/ BMS 'hardware (halo around the button) then after a couple if secs the switch returns off.
My setup for 3 BMS is: sample_period 5 secs, publish_period 60 secs, concurrent_sampling on, keep_alive on, expire_after 120 secs.
I must say that the Android APP also has this difficulty, but with the APP after a few attempts the switch is successful, while with BATMON almost never. Has anyone had the same problem? Any suggestion? Thank You.

Adding more Informations to JKBMS readout

Hi,

I use the BatMon Addon in HA since 2 weeks! Great addon!!!

Before, I used the MPP-Solar Script, runing in Background. With this, I got some more Informations from the JKBMS (JK-B2A24S20P)
I got the Average Cell Voltage, the cell difference voltage, the cell resistance, the mbs Uptime, ...
So, maybe you can add these informations also the the Batmon addon?

Kind regards
Sebastian

reading BMS: float division by zero

Hi,
I added the addon to HA and have weird issue in log.

My configuration is:

devices:
  - address: C8:47:8C:EA:BF:0D
    type: jk
    alias: battery1
mqtt_user: user
mqtt_password: passwd
mqtt_broker: core-mosquitto
concurrent_sampling: false
keep_alive: false
verbose_log: false
sample_period: 5
invert_current: false
watchdog: true
pin: 1234

and error in logs:

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
INFO     [main.py:68] BT Discovery:
INFO     [main.py:73] BT Device   JK_B2A8S20P   address=C8:47:8C:EA:BF:0D
INFO     [main.py:178] connecting mqtt user@core-mosquitto
INFO     [main.py:201] Fetching 1 BMS + 0 others serially, period=5.00s, keep_alive=False
INFO     [sampling.py:41] connecting bms JKBt(C8:47:8C:EA:BF:0D)
INFO     [main.py:99] mqtt watchdog loop started with timeout 120.0s
INFO     [sampling.py:47] connected bms JKBt(C8:47:8C:EA:BF:0D)!
ERROR    [sampling.py:97] battery1 error: float division by zero
ERROR    [main.py:240] 1 exceptions occurred fetching BMSs
ERROR    [main.py:85] Error (num 1) reading BMS: float division by zero
ERROR    [main.py:86] Stack: Traceback (most recent call last):
  File "/app/main.py", line 81, in fetch_loop
    await fn()
  File "/app/main.py", line 241, in fn
    raise exceptions[0]
  File "/app/main.py", line 236, in fn
    await t
  File "/app/bmslib/sampling.py", line 32, in __call__
    return await self.sample()
  File "/app/bmslib/sampling.py", line 49, in sample
    sample = await bms.fetch()
  File "/app/bmslib/jikong.py", line 176, in fetch
    return BmsSample(
  File "/app/bmslib/bms.py", line 52, in __init__
    soc = round(charge / capacity * 100, 2)
ZeroDivisionError: float division by zero

Could you help me with it?
Thank you very much!

Remote PI - HA configuraiton

Once I have the remote PI feeding in the MQTT messages, how do I setup the local HA configuration. Its not talking to the bluetooth address, so what do you use?

Error on install

"The command '/bin/ash -o pipefail -c apk add --no-cache python3 bluez py-pip git' returned a non-zero code: 4"

Any clues on how to get this to work? Rpi4, Twister OS, HA Supervised

(Also, thanks for making this, super handy!)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.