Code Monkey home page Code Monkey logo

bluetti_mqtt's People

Contributors

burpen avatar jretz avatar lbossle avatar ray0711 avatar slash5k1 avatar warhammerkid 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bluetti_mqtt's Issues

Data just from one power station

When I try to use your script with multiple power stations by providing (in my case 2) MAC-Addresses, only one is read. If I restart the service that's responsible for your script multible times, sometimes i get data from the other power station. The data of both power stations is read maby every 10 restarts for one cycle.

Akku Pack Holding Register Addresses?

Hi Fellows!
Does someone know the addresses of the separate akku pack properties/values?
I've a AC300 with two B300 and I can't find any meaningful values for
ie:
'cell_voltages' at address 0x0069, all 16 values are zero.
I scanned the whole range for meaningful values.
Are they on a different "page"?

And on the screen (pic) the packs are on position 2 and 3 despite on which socket they are connected.

IMG_20230410_175321

EP500P DC input current 1 shows 6553,5A in Home Assistant

Sometimes the input current gets the value 6553,5A messing up the history graph in home assitant. It seems like this happens when the EP500P does not consume power from the solar cells, means early in the morning or when the battery is full.

Any ideas?

Anyways big thank you for doing that project.

mqtt sensors not belonging to bluetti device in HA

in HA with mqtt auto discovery i have a bluetti device with nearly no sensors and i have a lot of sensors without device.
It would be nice to have all sensors belonging to bluetti device after discovery rather then need to add them manually.

I dont know the exact circumstances, but for my thermostats with another topic structure the sensors belong to the respective devices.

Bluetti topics:
bluetti/state/ac200_device_id/detail
homeassistant /sensor/device_id_detail_name

Thermostat topics:
thermostat/room/detail
homeassistant/sensor/device_id/detail_name
https://github.com/zewelor/bt-mqtt-gateway

Units of measure for AC200MAX with incorrect factors

Hi, first of all great project, thanks!

Monitoring data for my AC200MAX following jumped into my eye:

  • dc_input_voltage1 too small by factor 10
  • dc_input_power1 too large by factor 10
  • dc_input_current1 too large by factor 10

I corrected it "the dirty way" in file mqtt_client.py and tested successfully:

       if 'internal_dc_input_voltage' in msg.parsed:
            await client.publish(
                topic_prefix + 'dc_input_voltage1',
                payload=str(10*msg.parsed['internal_dc_input_voltage']).encode()
            )
        if 'internal_dc_input_power' in msg.parsed:
            await client.publish(
                topic_prefix + 'dc_input_power1',
                payload=str(msg.parsed['internal_dc_input_power']/10).encode()
            )
        if 'internal_dc_input_current' in msg.parsed:
            await client.publish(
                topic_prefix + 'dc_input_current1',
                payload=str(msg.parsed['internal_dc_input_current']/10).encode()
            )

Add ability too see cell voltage.

I think it would be a great addition to be able to see and track individual cell voltages,

On my ep500p i can see this in the logs

{'pack_num_max': 1, 'pack_voltage': Decimal('53.8'), 'pack_battery_percent': 96, 'pack_num': 1, 'cell_voltages': [Decimal('3.35'), Decimal('3.36'), Decimal('3.35'), Decimal('3.35'), Decimal('3.36'), Decimal('3.35'), Decimal('3.35'), Decimal('3.35'), Decimal('3.35'), Decimal('3.35'), Decimal('3.35'), Decimal('3.36'), Decimal('3.36'), Decimal('3.35'), Decimal('3.35'), Decimal('3.35')]}

Scan / initial connection failing 99/100 times? Timeout

To begin : this may entirely be an issue with my setup. However wanted to see if there were any others with the issue, or tricks to resolve the issue.

upon init of this software/script, I’m having issues reliably connecting to Bluetooth via Ac200MAX. The box running this software is a raspberry pi 4b with home assistant.

mid i time it just right, a few times I can get it to connect and work if I reboot the ac200max and restart this script at the exact same time. Other (most) times it fails sequentially several times over before stopping from working any longer.

many ideas or logging of things to try? This machine does connect, just not reliably after reboots and the like.

Scanning does mention the bt Mac that is correct of the ac200max.

esp32 poe

Hi ,

i have running on HA ESPHome and when I try Bluetti-mqtt --scan I become
CleanShot 2022-10-21 at 11 52 07
No Bluetooth adapters found , has anyone an idea ?

Get Error AC200MAX and Python 3.10 on Windows10

Hi warhammerkid,

at first, thanks for your work!!!!

I'm not a programmer and my english is terribel :-)

At first I used the "bluetti-logger --scan" options and get an Error:

PS C:\Users\fluch> bluetti-logger --scan

Scanning....
Traceback (most recent call last):
File "C:\Users\fluch\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\fluch\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in run_code
exec(code, run_globals)
File "C:\Users\fluch\AppData\Local\Programs\Python\Python310\Scripts\bluetti-logger.exe_main
.py", line 7, in
File "C:\Users\fluch\AppData\Local\Programs\Python\Python310\lib\site-packages\bluetti_mqtt\logger_cli.py", line 119, in main
asyncio.run(scan())
File "C:\Users\fluch\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\fluch\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete
return future.result()
File "C:\Users\fluch\AppData\Local\Programs\Python\Python310\lib\site-packages\bluetti_mqtt\logger_cli.py", line 24, in scan
bluetti_devices = [d for d in devices if prefix.match(d.name)]
File "C:\Users\fluch\AppData\Local\Programs\Python\Python310\lib\site-packages\bluetti_mqtt\logger_cli.py", line 24, in
bluetti_devices = [d for d in devices if prefix.match(d.name)]
TypeError: expected string or bytes-like object

I changed the Code in logger_cli.py at line 24 and I dont get any error now:

bluetti_devices = [d for d in devices if d.name and prefix.match(d.name)]

I think some bluetooth devices has no name and we must check this.

PS C:\Users\fluch\bluetti> bluetti-logger --scan
Scanning....
Found AC200M214200020XXXX: address 00:15:83:8A:F4:71

In the next step I used the "bluetti-logger--log" option and get an Error:

PS C:\Users\fluch\bluetti> bluetti-logger --log test.log 00:15:83:8A:F4:71
Connecting to 00:15:83:8A:F4:71
Waiting for connection...
Task exception was never retrieved
future: <Task finished name='Task-2' coro=<BluetoothClient.run() done, defined at C:\Users\fluch\AppData\Local\Programs\Python\Python310\lib\site-packages\bluetti_mqtt\bluetooth\client.py:36> exception=TimeoutError()>
Traceback (most recent call last):
File "C:\Users\fluch\AppData\Local\Programs\Python\Python310\lib\asyncio\locks.py", line 214, in wait
await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\fluch\AppData\Local\Programs\Python\Python310\lib\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 "C:\Users\fluch\AppData\Local\Programs\Python\Python310\lib\site-packages\bluetti_mqtt\bluetooth\client.py", line 51, in run
await self.client.disconnect()
File "C:\Users\fluch\AppData\Local\Programs\Python\Python310\lib\site-packages\bleak\backends\winrt\client.py", line 314, in disconnect
await asyncio.wait_for(event.wait(), timeout=10)
File "C:\Users\fluch\AppData\Local\Programs\Python\Python310\lib\asyncio\tasks.py", line 458, in wait_for
raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError

When I use the "bluetti-mqtt" I get this error:

PS C:\Users\fluch\bluetti> bluetti-mqtt --broker 192.168.188.204 --username Mqtt --password test 00:15:83:8A:F4:71
INFO:root:Connecting to clients: {'00:15:83:8A:F4:71'}
INFO:root:Starting to poll clients...
INFO:root:Connecting to MQTT broker...
Traceback (most recent call last):
File "C:\Users\fluch\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\fluch\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in run_code
exec(code, run_globals)
File "C:\Users\fluch\AppData\Local\Programs\Python\Python310\Scripts\bluetti-mqtt.exe_main
.py", line 7, in
File "C:\Users\fluch\AppData\Local\Programs\Python\Python310\lib\site-packages\bluetti_mqtt\server_cli.py", line 116, in main
cli.execute()
File "C:\Users\fluch\AppData\Local\Programs\Python\Python310\lib\site-packages\bluetti_mqtt\server_cli.py", line 58, in execute
asyncio.run(self.start(args))
File "C:\Users\fluch\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\fluch\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete
return future.result()
File "C:\Users\fluch\AppData\Local\Programs\Python\Python310\lib\site-packages\bluetti_mqtt\server_cli.py", line 88, in start
signals = (signal.SIGHUP, signal.SIGTERM, signal.SIGINT)
AttributeError: module 'signal' has no attribute 'SIGHUP'

I don't now, is the error in bluetti-mqtt or in the MQTT-Broker. The MQTT-Broker is runing as Mosquito MQTT on a Home Assistant Raspberry 4.

So, I hope you can help :-)

Thanks so lot!!!

Cell and System temperatures

Hey,

this is really great work. I use my AC200MAX in my camper and I finally have a great solution for my energy management which is quite important when you stay offroad without a constant electricity source.

Last year I ran into some temperature issues that even led to a replacement of my device because it ran into ntc error all the time.

Therefore I am a little bit concerned about the temperature sensor readings of the device and want to track them.

I was wondering if there are more values delivered from the device via Bluetooth that haven´t been integrated yet? Especially temperatures.

In this video https://www.youtube.com/watch?v=hYgJl9m6eZg you can see temperature values and individual cell voltages in the Bluetti Device UI.

Thank you in advance! Greetings from Germany

Scan Error

I have installed bluetti_mqtt in ubuntu virtual machine on a Intel NUC in vmware ESXi. After succesfull install the command --scan get an error:
`
~/.local/bin$ ./bluetti-mqtt --scan
Scanning....
Traceback (most recent call last):
File "/home/rico/.local/bin/./bluetti-mqtt", line 8, in
sys.exit(main())
File "/home/rico/.local/lib/python3.10/site-packages/bluetti_mqtt/server_cli.py", line 123, in main
cli.execute()
File "/home/rico/.local/lib/python3.10/site-packages/bluetti_mqtt/server_cli.py", line 62, in execute
asyncio.run(scan_devices())
File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
return future.result()
File "/home/rico/.local/lib/python3.10/site-packages/bluetti_mqtt/bluetooth/init.py", line 17, in scan_devices
devices = await BleakScanner.discover()
File "/usr/local/lib/python3.10/dist-packages/bleak/backends/scanner.py", line 123, in discover
async with cls(**kwargs) as scanner:
File "/usr/local/lib/python3.10/dist-packages/bleak/backends/scanner.py", line 103, in aenter
await self.start()
File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/scanner.py", line 133, in start
manager = await get_global_bluez_manager()
File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/manager.py", line 856, in get_global_bluez_manager
await instance.async_init()
File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/manager.py", line 231, in async_init
assert_reply(reply)
File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/utils.py", line 22, in assert_reply
raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.freedesktop.DBus.Error.ServiceUnknown] The name org.bluez was not provided by any .service files

`
Is there any solution?

EOFError crashes bluetti-mqtt

I'm running bluetti-mqtt to connect to my AC500. Every once and a while I get this stack trace that crashes the app:

2023-03-01 08:48:49 ERROR    Error connecting to device xx:xx:xx:xx:xx:xx:
Traceback (most recent call last):
  File "/home/iandees/bluetti-venv/lib/python3.8/site-packages/bluetti_mqtt/bluetooth/client.py", line 40, in run
    await self.client.connect()
  File "/home/iandees/bluetti-venv/lib/python3.8/site-packages/bleak/__init__.py", line 471, in connect
    return await self._backend.connect(**kwargs)
  File "/home/iandees/bluetti-venv/lib/python3.8/site-packages/bleak/backends/bluezdbus/client.py", line 172, in connect
    reply = await self._bus.call(
  File "/home/iandees/bluetti-venv/lib/python3.8/site-packages/dbus_fast/aio/message_bus.py", line 370, in call
    await future
  File "/home/iandees/bluetti-venv/lib/python3.8/site-packages/dbus_fast/aio/message_reader.py", line 24, in _message_reader
    message = unmarshaller._unmarshall()
  File "/home/iandees/bluetti-venv/lib/python3.8/site-packages/dbus_fast/_private/unmarshaller.py", line 641, in _unmarshall
    self._read_header()
  File "/home/iandees/bluetti-venv/lib/python3.8/site-packages/dbus_fast/_private/unmarshaller.py", line 524, in _read_header
    self._read_to_pos(HEADER_SIGNATURE_SIZE)
  File "/home/iandees/bluetti-venv/lib/python3.8/site-packages/dbus_fast/_private/unmarshaller.py", line 276, in _read_to_pos
    raise EOFError()
EOFError

Get an Error on Asustor NAS

Hello,

I will try run Bluetti-Mqtt in my Asustor NAS AS6604. Blutooth is with an Bluetooth-dongle. The installation is gone without Error. But when i start Bluetti-Mqtt --scan i get the following error:

root@HT730-NASSERVER:/volume1/.@root # bluetti-mqtt --scan
Scanning....
Traceback (most recent call last):
File "/opt/bin/bluetti-mqtt", line 8, in
sys.exit(main())
File "/opt/lib/python3.10/site-packages/bluetti_mqtt/server_cli.py", line 123, in main
cli.execute()
File "/opt/lib/python3.10/site-packages/bluetti_mqtt/server_cli.py", line 62, in execute
asyncio.run(scan_devices())
File "/opt/lib/python3.10/asyncio/runners.py", line 44, in run
File "/opt/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
File "/opt/lib/python3.10/site-packages/bluetti_mqtt/bluetooth/init.py", line 17, in scan_devices
devices = await BleakScanner.discover()
File "/opt/lib/python3.10/site-packages/bleak/backends/scanner.py", line 117, in discover
async with cls(**kwargs) as scanner:
File "/opt/lib/python3.10/site-packages/bleak/backends/scanner.py", line 97, in aenter
await self.start()
File "/opt/lib/python3.10/site-packages/bleak/backends/bluezdbus/scanner.py", line 129, in start manager = await get_global_bluez_manager()
File "/opt/lib/python3.10/site-packages/bleak/backends/bluezdbus/manager.py", line 783, in get_global_bluez_manager
await instance.async_init()
File "/opt/lib/python3.10/site-packages/bleak/backends/bluezdbus/manager.py", line 225, in async_init
assert_reply(reply)
File "/opt/lib/python3.10/site-packages/bleak/backends/bluezdbus/utils.py", line 22, in assert_reply
raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.freedesktop.DBus.Error.UnknownMethod] Method "GetManagedObjects" with signature "" on interface "org.freedesktop.DBus.ObjectManager" doesn't exist

I'm not shure, is the Error from Bluetti-Mqtt or from my NAS?

Thanks for your help.

General Question About DATA TRANSFER

In general: Is this project virtualizing the app-layer ?
Is it sending signals directly to the device in local network or does it sent, like app probably is ( ? ), to a middleman server from bluetti and only then back to the device in the home ?

Hope my questions make sense.

Thank you

Crash when adjusting "Battery Range End"

From HA, if one adjusts "Battery Range End" slider an unhandled exception is thrown (v0.11.0 - EP500P)
2022-11-22 13:19:25 ERROR Crashing with uncaught exception:
Traceback (most recent call last):
File "/home/user/.local/lib/python3.10/site-packages/bluetti_mqtt/device_handler.py", line 31, in run
await asyncio.gather((polling_tasks + pack_polling_tasks + [manager_task]))
File "/home/user/.local/lib/python3.10/site-packages/bluetti_mqtt/bluetooth/manager.py", line 19, in run
await asyncio.gather(
[c.run() for c in self.clients.values()])
File "/home/user/.local/lib/python3.10/site-packages/bluetti_mqtt/bluetooth/client.py", line 53, in run
await self._perform_commands(self.client)
File "/home/user/.local/lib/python3.10/site-packages/bluetti_mqtt/bluetooth/client.py", line 77, in _perform_commands
bytes(self.current_command))
TypeError: cannot convert 'NoneType' object to bytes
2022-11-22 13:19:25 INFO Shutting down...

Unable to power_off AC200M

In the mobile app I have the option of turning off the unit completely and yet there is no implementation for it in the AC200M device file.

Looking through the code I can see this control defined for eb3a:
self.struct.add_bool_field('power_off', 0x0B, 0xF4)

Added this to the ac200m device file and can confirm when I publish "power_off" to the command topic the unit turns off! :)

For completeness can I suggest that each device is updated to include this control command. - assuming all devices support the power_off command?

Scan does not working

Hi i have installed with pip command but weh i will mache a scan for my devices i get the following error.

Traceback (most recent call last):
File "/home/mwende/.local/bin/bluetti-mqtt", line 8, in
sys.exit(main())
File "/home/mwende/.local/lib/python3.8/site-packages/bluetti_mqtt/server_cli.py", line 123, in main
cli.execute()
File "/home/mwende/.local/lib/python3.8/site-packages/bluetti_mqtt/server_cli.py", line 62, in execute
asyncio.run(scan_devices())
File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "/home/mwende/.local/lib/python3.8/site-packages/bluetti_mqtt/bluetooth/init.py", line 80, in scan_devices
devices = await BleakScanner.discover()
File "/usr/local/lib/python3.8/dist-packages/bleak/backends/scanner.py", line 116, in discover
async with cls(**kwargs) as scanner:
File "/usr/local/lib/python3.8/dist-packages/bleak/backends/scanner.py", line 96, in aenter
await self.start()
File "/usr/local/lib/python3.8/dist-packages/bleak/backends/bluezdbus/scanner.py", line 128, in start
manager = await get_global_bluez_manager()
File "/usr/local/lib/python3.8/dist-packages/bleak/backends/bluezdbus/manager.py", line 812, in get_global_bluez_manager
await instance.async_init()
File "/usr/local/lib/python3.8/dist-packages/bleak/backends/bluezdbus/manager.py", line 294, in async_init
bus = MessageBus(bus_type=BusType.SYSTEM)
File "/usr/local/lib/python3.8/dist-packages/dbus_next/aio/message_bus.py", line 122, in init
super().init(bus_address, bus_type, ProxyObject)
File "/usr/local/lib/python3.8/dist-packages/dbus_next/message_bus.py", line 85, in init
self._setup_socket()
File "/usr/local/lib/python3.8/dist-packages/dbus_next/message_bus.py", line 575, in _setup_socket
raise err
File "/usr/local/lib/python3.8/dist-packages/dbus_next/message_bus.py", line 548, in _setup_socket
self._sock.connect(filename)
FileNotFoundError: [Errno 2] No such file or directory

Can you tell me whats is wrong...

Are the new EB3A entities supported in Home Assistant?

I have an EB3A that I've been using since version 0.9.0 and it has the following entities in Home Assistant (edit: also, AC input power, not pictured):

Screenshot_2022-11-12_12-55-31

In the 0.9.2 release, the EB3A config was updated to include additional functionality (eco mode, charging mode, etc.). The problem I have is that even after upgrading to 0.9.2 and beyond (currently running 0.10.0), Home Assistant still only lists the entities shown in the screenshot above. I do see the additional entities if I examine the bluetti topic using MQTT Explorer:

Screenshot_2022-11-12_13-08-54

I assume HA is somehow stuck with a stale autodiscovery manifest, and I'm not sure how to force rediscovery to happen. I have tried stopping bluetti_mqtt, deleting the device in HA, then restarting bluetti_mqtt, to no change. Perhaps this is a Home Assistant problem more than a bluetti_mqtt problem.

On a related note, is the readme's list of supported sensors and switches up to date? I'm not sure if I should take it to mean that anything beyond what's listed there will require some additional development. If that's the case then what I'm seeing may be expected behavior.

Feature Request: Logging

Could a loggin option be added?

I always turn off the AC200M at night, after a few failed BT connections the application shuts down.

2023-01-01 18:38:19 ERROR    Error connecting to device 04:7F:0E:AD:X:X:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/bluetti_mqtt/bluetooth/client.py", line 40, in run
    await self.client.connect()
  File "/usr/local/lib/python3.10/dist-packages/bleak/__init__.py", line 471, in connect
    return await self._backend.connect(**kwargs)
  File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/client.py", line 190, in connect
    assert_reply(reply)
  File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/utils.py", line 20, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.Failed] br-connection-canceled
2023-01-01 18:38:20 INFO     Retrying connection to 04:7F:0E:AD:X:X
2023-01-01 18:38:20 ERROR    Error connecting to device 04:7F:0E:AD:X:X:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/bluetti_mqtt/bluetooth/client.py", line 40, in run
    await self.client.connect()
  File "/usr/local/lib/python3.10/dist-packages/bleak/__init__.py", line 471, in connect
    return await self._backend.connect(**kwargs)
  File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/client.py", line 190, in connect
    assert_reply(reply)
  File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/utils.py", line 20, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.Failed] Operation already in progress
2023-01-01 18:38:21 INFO     Retrying connection to 04:7F:0E:AD:X:X
2023-01-01 18:38:21 ERROR    Error connecting to device 04:7F:0E:AD:X:X:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/bluetti_mqtt/bluetooth/client.py", line 40, in run
    await self.client.connect()
  File "/usr/local/lib/python3.10/dist-packages/bleak/__init__.py", line 471, in connect
    return await self._backend.connect(**kwargs)
  File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/client.py", line 190, in connect
    assert_reply(reply)
  File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/utils.py", line 20, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.Failed] br-connection-canceled
2023-01-01 18:38:22 INFO     Retrying connection to 04:7F:0E:AD:X:X
2023-01-01 18:38:22 ERROR    Error connecting to device 04:7F:0E:AD:X:X:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/bluetti_mqtt/bluetooth/client.py", line 40, in run
    await self.client.connect()
  File "/usr/local/lib/python3.10/dist-packages/bleak/__init__.py", line 471, in connect
    return await self._backend.connect(**kwargs)
  File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/client.py", line 190, in connect
    assert_reply(reply)
  File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/utils.py", line 20, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.Failed] Operation already in progress
2023-01-01 18:38:23 INFO     Retrying connection to 04:7F:0E:AD:X:X
2023-01-01 18:38:23 ERROR    Error connecting to device 04:7F:0E:AD:X:X:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/bluetti_mqtt/bluetooth/client.py", line 40, in run
    await self.client.connect()
  File "/usr/local/lib/python3.10/dist-packages/bleak/__init__.py", line 471, in connect
    return await self._backend.connect(**kwargs)
  File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/client.py", line 190, in connect
    assert_reply(reply)
  File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/utils.py", line 20, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.Failed] br-connection-canceled
^C2023-01-01 18:38:23 INFO     Shutting down...

When systemd then restarts, sometimes no Bluetooth connection is established.

How is it possible to prevent the shutdown?

Error log clearing command?

Hi there,

Awesome work so far on all the protocol reverse-engineering - going to be nice to actually have the ability to track charge level metrics and PV output over time.

Had a quick question for you:

I've got an unusual setup of a new Bluetti system - pair of AC300/B300s configured as a split phase output via a Fusion Box running an off-grid 240V well-pump for irrigation.

I've got a Starlink setup running for remote monitoring via WiFi / the Bluetti app.

Right now - I'm running into stability issues where the split phase setup fails sporadically and requires a manual reset of the error log on the device before it will start functioning again.

It's unfortunately a 60 minute round trip drive every time I have to go reset the damn thing.

Just wanted to ask whether you had come across anything related to the error log / device fault log and any potential commands for remote reset of it in your work so far before I go down the rabbit hole of trying to find a workaround myself.

There's no reset functionality within the app that I've been able to discern - so I'm not sure what procedure you've been using or might recommend for figuring out potential commands without any explicit trigger you can trace with WireShark etc.

The bluetti_mqtt does not work over the ESPHome bluetooth proxy

Hello warhammerkid.

Thanks for your great Home Assistant integration for Bluetti powerstations.
I am currently integrating the AC200Max into my Home Assistant system.
Since I don't want to use the battery near the Home Assistant Raspberry Pi in different places, I have loaded the ESPHome Bluetooth Proxy on an ESP32. However, I can't get a connection to the Bluetti via this. Link: https://esphome.github.io/bluetooth-proxies/
When I load the Bluetooth Proxy's diagosis information from the Home Assistant's device list, I see that the Bluetooth Proxy has found the Bluetti. However, the bluetti_MQTT integration only seems to access the Bluetooth of the Raspberry Pi.
Is it possible to activate the Bluetooth Proxy in your bluetti_MQTT?

-mqtt sometimes crashing

sometimes I get following crash:

2022-11-23 12:53:10 ERROR Crashing with uncaught exception: Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/bluetti_mqtt/device_handler.py", line 31, in run await asyncio.gather(*(polling_tasks + pack_polling_tasks + [manager_task])) File "/usr/local/lib/python3.10/site-packages/bluetti_mqtt/bluetooth/manager.py", line 19, in run await asyncio.gather(*[c.run() for c in self.clients.values()]) File "/usr/local/lib/python3.10/site-packages/bluetti_mqtt/bluetooth/client.py", line 50, in run await self.client.start_notify( File "/usr/local/lib/python3.10/site-packages/bleak/__init__.py", line 649, in start_notify await self._backend.start_notify(characteristic, wrapped_callback, **kwargs) File "/usr/local/lib/python3.10/site-packages/bleak/backends/corebluetooth/client.py", line 360, in start_notify await self._delegate.start_notifications(characteristic.obj, callback) File "/usr/local/lib/python3.10/site-packages/bleak/backends/corebluetooth/PeripheralDelegate.py", line 212, in start_notifications raise ValueError("Characteristic notifications already started") ValueError: Characteristic notifications already started 2022-11-23 12:53:10 INFO Shutting down...

while reading from blutet ac200max.
Reason: unknown
Version istalled a few days ago with pip on MacOS 12.6 Monterey

Add device state notifications

To better facilitate automations, we should create a new EventBus message for connect/disconnect. This can be rigged up to MQTT and Home Assistant can then monitor it as part of its availability APIs. Ideally it should use the "will" feature on connect to ensure that the value is correct even in the event of a crash.

Batterypack Details

Hi there,

this is not really an issue, just the question about extended function. I'm using AC200MAX extended with two batterypacks.
Currently there is only the total_battery_percent delivered to Homeassitant.
I just seen via MQTT explorer that the Battery details are already read out and available via MQTT:

pack_details2 = {"percent":58,"voltages":[3.37,3.37,3.37,3.37,3.37,3.37,3.37,3.37,3.37,3.37,3.37,3.37,3.37,3.37,3.37,3.37]}
pack_details3 = {"percent":53,"voltages":[3.38,3.38,3.38,3.38,3.38,3.38,3.38,3.38,3.38,3.38,3.38,3.38,3.38,3.38,3.38,3.38]}
pack_details1 = {"percent":35,"voltages":[3.38,3.38,3.38,3.38,3.38,3.38,3.38,3.38,3.38,3.38,3.38,3.38,3.38,3.38,3.38,3.38]}

I there a possibility to have the charging percentage of each Battery also available within Homeassistant?

Regards and greetings from Germany
Michael

PS: Great work so far and very useful tool for all HA and Bluetti useres.

Service did not find device although Bluetti AC200max was found during scanning (valid MAC)

Using home assistant:
...
Add-on: Bluetti to MQTT
MQTT bridge between Bluetti and Home Assistant

Add-on version: 1.2.0
You are running the latest version of this add-on.
System: Home Assistant OS 9.5 (aarch64 / raspberrypi4-64)
Home Assistant Core: 2023.2.5
Home Assistant Supervisor: 2023.01.1
...

Service does not start, although MAC adressed scanned was configured. Default mosquitto intgration was used (all field were left empty). Any ideas to solve this issue?

...
'org.bluez.Device1': {'Address': 'xx:xx:xx:xx:xx:xx', 'AddressType': 'public', 'Name': 'AC200Mxxxxxxxxxxxxx', 'Alias': 'AC200M2236008116154', 'Paired': False, 'Trusted': False, 'Blocked': False, 'LegacyPairing': False, 'RSSI': -77, 'Connected': True,
...
2023-02-20 19:45:24 DEBUG Found devices: []
2023-02-20 19:45:24 DEBUG Shut down completed
Could not find the given devices to connect to
2023-02-20 19:45:24 ERROR Crashing with uncaught exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/bluetti_mqtt/server_cli.py", line 87, in start
loop.run_forever()
File "/usr/local/lib/python3.10/asyncio/base_events.py", line 600, in run_forever
self._run_once()
File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1896, in _run_once
handle._run()
File "/usr/local/lib/python3.10/asyncio/events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "/usr/local/lib/python3.10/site-packages/bluetti_mqtt/server_cli.py", line 100, in run
sys.exit('Could not find the given devices to connect to')
SystemExit: Could not find the given devices to connect to
2023-02-20 19:45:24 ERROR Unhandled error in exception handler
context: {'message': 'Task exception was never retrieved', 'exception': SystemExit('Could not find the given devices to connect to'), 'future': <Task finished name='Task-1' coro=<CommandLineHandler.run() done, defined at /usr/local/lib/python3.10/site-packages/bluetti_mqtt/server_cli.py:92> exception=SystemExit('Could not find the given devices to connect to')>}
Traceback (most recent call last):
File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1781, in call_exception_handler
self._exception_handler(self, context)
File "/usr/local/lib/python3.10/site-packages/bluetti_mqtt/server_cli.py", line 136, in handle_global_exception
asyncio.create_task(shutdown(loop))
File "/usr/local/lib/python3.10/asyncio/tasks.py", line 336, in create_task
loop = events.get_running_loop()
RuntimeError: no running event loop
...
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

Could not determine BlueZ version, bluetoothctl not available, assuming 5.51+

I get this error when I launch Bluetti to MQTT. How to fix it ?
Here is the log:
cont-init: info: /etc/cont-init.d/00-banner.sh exited 0
cont-init: info: running /etc/cont-init.d/01-log-level.sh
cont-init: info: /etc/cont-init.d/01-log-level.sh exited 0
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
[20:35:25] INFO: Reading configuration settings...
[20:35:28] INFO: Starting bluetti-mqtt...
2023-03-06 20:35:37 INFO Connecting to MQTT broker...
2023-03-06 20:35:37 INFO Starting to poll clients...
2023-03-06 20:35:37 INFO Connecting to clients: ['04:7F:0E:A4:08:54']
2023-03-06 20:35:37 WARNING Could not determine BlueZ version, bluetoothctl not available, assuming 5.51+
2023-03-06 20:35:37 INFO Connected to MQTT broker
2023-03-06 20:35:37 INFO Sent discovery message of AC200M-2227000041902 to Home Assistant
2023-03-06 20:35:37 WARNING filtered_messages() is deprecated and will be removed in a future version. Use messages() together with Topic.matches() instead.
2023-03-06 20:35:38 ERROR Error connecting to device 04:7F:0E:A4:08:54:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/bluetti_mqtt/bluetooth/client.py", line 40, in run
await self.client.connect()
File "/usr/local/lib/python3.10/site-packages/bleak/init.py", line 471, in connect
return await self._backend.connect(**kwargs)
File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 190, in connect
assert_reply(reply)
File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/utils.py", line 20, in assert_reply
raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.Failed] le-connection-abort-by-local
2023-03-06 20:35:39 INFO Retrying connection to 04:7F:0E:A4:08:54
2023-03-06 20:35:39 ERROR Error connecting to device 04:7F:0E:A4:08:54:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/bluetti_mqtt/bluetooth/client.py", line 40, in run
await self.client.connect()
File "/usr/local/lib/python3.10/site-packages/bleak/init.py", line 471, in connect
return await self._backend.connect(**kwargs)
File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 190, in connect
assert_reply(reply)
File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/utils.py", line 20, in assert_reply
raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.Failed] le-connection-abort-by-local

It's MODBUS!

I don't know why it took me so long to realize this, but the command/response API is just MODBUS over Bluetooth (and MODBUS over MQTT for the cloud support over WiFi). The internal API should be reworked to use standard terminology, as well as proper exception handling.

Error on EP500

Hello,

I tried bluetti-logger for EP500 but got this error:

➜ bluetti-logger --scan                                                 
Scanning....
Found EP5002204000017278: address 346F6730-082F-B776-9A09-70C5CBC8C6AD
➜ bluetti-logger --log log-file.log 346F6730-082F-B776-9A09-70C5CBC8C6AD
Connecting to 346F6730-082F-B776-9A09-70C5CBC8C6AD
Waiting for connection...
/_virtual_envs/bluetti/lib/python3.7/site-packages/bleak/backends/corebluetooth/client.py:318: UninitializedDeallocWarning: leaking an uninitialized object of type _NSPlaceholderData
value = NSData.alloc().initWithBytes_length_(data, len(data))
Task exception was never retrieved
future: <Task finished coro=<BluetoothClient.run() done, defined at /_virtual_envs/bluetti/lib/python3.7/site-packages/bluetti_mqtt/bluetooth/client.py:36> exception=TypeError("object of type 'QueryRangeCommand' has no len()")>
Traceback (most recent call last):
File "/_virtual_envs/bluetti/lib/python3.7/site-packages/bluetti_mqtt/bluetooth/client.py", line 43, in run
await self._perform_commands(self.client)
File "/_virtual_envs/bluetti/lib/python3.7/site-packages/bluetti_mqtt/bluetooth/client.py", line 67, in _perform_commands
self.current_command)
File "/_virtual_envs/bluetti/lib/python3.7/site-packages/bleak/backends/corebluetooth/client.py", line 318, in write_gatt_char
value = NSData.alloc().initWithBytes_length_(data, len(data))
TypeError: object of type 'QueryRangeCommand' has no len()

I checked also bluetooth connection from iPhone and Bluetti App via Packetlogger and your results from https://diysolarforum.com/threads/monitoring-bluetti-systems.37870/ are the same for EP500.
I am only wondering about the address. Not a typical mac address, but my magic mouse and other bl devices are also shown with this type of address. I tried it also with the mac from the Packetlogger but no Connection.
I'm working on MacBook Pro M1 with PyCharm and use buildin BL. Any idea what's wrong and this error happened?

request for EP600

Hello Warhammerkid,

I have a EP600 with 2 EP500, can you this device?

thanks a lot!

Alex

Crashes if single device not found when using multiple bluetti devices

When setup for multiple devices, it works fine as long as all devices are able to be connected to at runtime. If any device goes missing after that time, it continues to log the other devices and retries to connect to the failed device. That works great.

An issue arises if any one of the Bluetti's is not able to be connected to during initial execution. The script will just error out and you don't get any logging for the devices it could connect to.

Is there a possible fix for this? It would be good if it could mimic the first behavior descried and log the devices it can connect to and retry connecting periodically to the failed device(s).

Thank you!

dc_input_power has multiple values

This is an amazing piece of work, thank you.

I am using a raspberry pi 400, homeassistant on a Synology nas and a Bluetti AC200max. Everything works well except one problem with the dc_input_power mqtt message. I am using a 15 second interval and there appears to be two mqtt messages. The first one is the correct value, but immediately afterwards the value is resent as in integer ten times the value. I have checked this with MQTT explorer on my PC, so it is not a problem with homeassistant.

I guess I may have set up something incorrectly, as I am far from an expert, but it does seem odd.

Does not find AC200MAX on raspberry

Hello

I installed the bluetti_mqtt in order to connect my AC200MAX to Jeedom

Installation ran well using sudo pip3 install bluetti_mqtt

then when i try to connect using bluetti-mqtt --scan , it fails 0 devices found
here is example :
pi-/home/pi> hcitool dev
Devices:
hci0 00:01:95:7C:01:18
pi-/home/pi> lsusb | grep -i bluetooth
Bus 001 Device 004: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
pi-/home/pi> bluetti-mqtt --scan
Scanning....
0 devices found - something probably went wrong

BT Dongle is well known, at RPI can see the devices, and the AC200MAX is in the list :
image

BT is ok on the AC200MAX : i can connect with android app
the AC200MAX is close to the RPI

if you have any idea of what's wrong with me,
thank you for your help

Here is my stuff :
Raspberry pi 3B running rasbian 11 bullseye
Bluetooth dongle : SENA UD100-G03
AC200MAX :
ARM version : v4008,03
DSP version : v4005,07
BMS version : v1017,02

Add verbose mode

Hi
would it be possible to add verbose mode to get some log message from the service?

Getting Started Guide

First off, thank you for putting this project together, @warhammerkid.

I've been experimenting with using this library -- possibly in order to integrate it into my Home Assistant setup. However, in trying to get a POC stood up, I ran into some blocking issues. I think it'd be useful for either the README or a second document to contain a tutorial which makes no assumptions and helps people get up and running. I'm happy to take a pass at this ... just as soon as I can get my POC working.

My issue, assuming I'm even proceeding down the right track, has to do with the library interfacing with my MQTT broker. I'm able to detect and connect to my Bluetti devices without issue but the library isn't able to connect to the broker and reports, "Operation timed out" in an infinite loop. I've tried using a basic (no config aside from username and password) RabbitMQ broker in a Docker container and I see the following error in its logs when this library tries to connect:

mq_1  | 2022-12-13 15:09:12.354104+00:00 [info] <0.794.0> accepting AMQP connection <0.794.0> (172.29.0.1:33010 -> 172.29.0.2:5672)
mq_1  | 2022-12-13 15:09:12.354292+00:00 [error] <0.794.0> closing AMQP connection <0.794.0> (172.29.0.1:33010 -> 172.29.0.2:5672):
mq_1  | 2022-12-13 15:09:12.354292+00:00 [error] <0.794.0> {bad_header,<<16,54,0,4,77,81,84,84>>}

Should this work or is there more configuration on the RabbitMQ side that I need to do? Alternatively, is there a preferred MQTT backend?

Lost connection?

Hi,

I read in the forum (https://diysolarforum.com/threads/monitoring-bluetti-systems.37870/post-592765) that Bluetti-MQTT seems to lose the connection and the broker does not receive any new data. The process (Bluetti-MQTT runs on Ubuntu in a VirtualBox.) is still running, my guess is that the service loses the Bluetooth connection and cannot reconnect. I'm not using IOBrocker, I'm running Home Assistant with MosquitoMQTT, but I'm having the same problem. After restarting the Bluetti-MQTT process, the connection is back and current data is received. Unfortunately, I don't have any other log entries because I couldn't find any that explain the problem.
BluettiLostConnection (2)

Support EB3A

In theory basic support should be as simple as updating my device name regex to recognize this device. I don’t own one currently, though, so I have no way to test for sure. Also, without bluetooth captures of the app, I don’t have any way to discover how device-specific functionality (for example the light) works.

Support for AC60

I have both a pre-production AC60 and a B80 expansion battery for it and would love to kick-start support for it. I've run bluetti-discovery --log on it and zipped up the log file and attached it. I've attached it - no personal data in it.
ac60-discovery.zip. Did I do it right?

bluetti-logger fails on EB3A when parsing pack_num_max result

Running bluetti-logger on an EB3A results in the process failing with a traceback:

$ venv/bin/bluetti-logger --log eb3a.log xx:xx:xx:xx:xx:xx
Connecting to xx:xx:xx:xx:xx:xx
Waiting for connection...
Traceback (most recent call last):
  File "/home/jimmy/bluetti/venv/bin/bluetti-logger", line 8, in <module>
    sys.exit(main())
  File "/home/jimmy/bluetti_mqtt/bluetti_mqtt/logger_cli.py", line 117, in main
    asyncio.run(log(args.address, args.log))
  File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/home/jimmy/bluetti_mqtt/bluetti_mqtt/logger_cli.py", line 69, in log
    pack_max = device.parse(0x00, 0x5B, result[3:-2])['pack_num_max']
KeyError: 'pack_num_max'

More values

Hello,
First of all thanks for the great project!
I've had an AC200MAX for about 6 weeks.
Since then it has been running on a RaspberryPi and sends to FHEM via mqtt :-)
Yesterday my B230 extension battery arrived and of course I connected it right away =)
With the AC200MAX and in the app I can see the status of the batteries individually (installed and extended) in percentage.
Unfortunately, no further information arrives in the MQTT device.
Here comes only the percent and total_battery_percent, both equal to total percent value of AC200MAX.
Can you extend bluetti_mqtt to that effect?

Regards

Christoph

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.