Emit MQTT events from victron-ble
Project description
victron_ble2mqtt
Emit MQTT events from Victron Energy Solar Charger via victron-ble
Tested with:
- Solar Charger: SmartSolar MPPT 100/20
- Raspberry Pi Zero 2 W with Raspberry Pi OS Lite
- Mosquitto MQTT Broker
- Home Assistant MQTT integration
Usage
preperation
victron_ble
used Bleak and the Linux backend of Bleak communicates with BlueZ over DBus. So you have to install this, e.g.:
~$ sudo apt install bluez
Bootstrap
Clone the sources and just call the CLI to create a Python Virtualenv, e.g.:
~$ git clone https://github.com/jedie/victron-ble2mqtt.git
~$ cd victron-ble2mqtt
~/victron-ble2mqtt$ ./cli.py --help
app CLI
Usage: ./cli.py [OPTIONS] COMMAND [ARGS]...
╭─ Options ────────────────────────────────────────────────────────────────────────────────────────╮
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────╮
│ debug-read Read data from specified devices and print them. MAC / KEY are used from config │
│ file, if not given. │
│ discover Discover Victron devices with Instant Readout │
│ edit-settings Edit the settings file. On first call: Create the default one. │
│ print-settings Display (anonymized) MQTT server username and password │
│ publish-loop Publish MQTT messages in endless loop (Entrypoint from systemd) │
│ systemd-debug Print Systemd service template + context + rendered file content. │
│ systemd-remove Remove Systemd service file. (May need sudo) │
│ systemd-setup Write Systemd service file, enable it and (re-)start the service. (May need │
│ sudo) │
│ systemd-status Display status of systemd service. (May need sudo) │
│ systemd-stop Stops the systemd service. (May need sudo) │
│ version Print version and exit │
│ wifi-info Just display the WiFi info │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
dev CLI
Usage: ./dev-cli.py [OPTIONS] COMMAND [ARGS]...
╭─ Options ────────────────────────────────────────────────────────────────────────────────────────╮
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────╮
│ check-code-style Check code style by calling darker + flake8 │
│ coverage Run tests and show coverage report. │
│ fix-code-style Fix code style of all cli_base source code files via darker │
│ install Run pip-sync and install 'cli_base' via pip as editable. │
│ mypy Run Mypy (configured in pyproject.toml) │
│ pip-audit Run pip-audit check against current requirements files │
│ publish Build and upload this project to PyPi │
│ test Run unittests │
│ tox Run tox │
│ update Update "requirements*.txt" dependencies files │
│ update-test-snapshot-files Update all test snapshot files (by remove and recreate all snapshot │
│ files) │
│ version Print version and exit │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
Setup Device
Detect your device first, e.g.:
~/victron-ble2mqtt$ ./cli.py discover
...
{
'name': 'SmartSolar HQ2248AM79D',
'address': 'E7:37:97:XX:XX:XX',
'details': {
'path': '/org/bluez/hci0/dev_E7_37_97_XX_XX_XX',
'props': {
'Address': 'E7:37:97:XX:XX:XX',
'AddressType': 'random',
'Name': 'SmartSolar HQ2248AM79D',
'Alias': 'SmartSolar HQ2248AM79D',
'Paired': False,
'Trusted': False,
'Blocked': False,
'LegacyPairing': False,
'RSSI': -89,
'Connected': False,
'UUIDs': [],
'Adapter': '/org/bluez/hci0',
'ManufacturerData': {737: bytearray(b'...')},
'ServicesResolved': False
}
}
}
...
(Hit Ctrl-C to abort)
Device Key
You need the Device MAC address and the key.
The easiest way to get the device key: Install the official Victron Smartphone and and copy&paste the key:
- Click on your SmartSolar device
- Go to detail page about the
SmartSolar Bluetooth Interface
- Click on
SHOW
atInstant readout via Bluetooth
/Encryption data
- Copy the Connectionkey by click on the key
(I send the key via Signal as "my note" and use the Desktop Signal app to receive the key on my Computer)
See also: https://community.victronenergy.com/questions/187303/victron-bluetooth-advertising-protocol.html
setting
Just call edit-settings
command, e.g.:
~/victron-ble2mqtt$ ./cli.py edit-settings
At least insert your MQTT settings and the device MAC and key.
Test
Start publish MQTT endless look, just call publish-loop
command, e.g.:
~/victron-ble2mqtt$ ./cli.py publish-loop
setup systemd services
Check systemd setup:
~/victron-ble2mqtt$ ./cli.py systemd-debug
Setup services:
~/victron-ble2mqtt$ ./cli.py systemd-setup
Check the services:
~/victron-ble2mqtt$ ./cli.py systemd-status
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file victron_ble2mqtt-0.3.0.tar.gz
.
File metadata
- Download URL: victron_ble2mqtt-0.3.0.tar.gz
- Upload date:
- Size: 65.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df56157470d9abbd731a8e95c8622de58c7d4e64a0655471ad692241b6bf7a30 |
|
MD5 | b41d92336529c18f86b9c8bf32f0a2fe |
|
BLAKE2b-256 | 9004ff22d095d56f2afd821c1643fee2d28f814271dc26c3898adc80745ac4c0 |
File details
Details for the file victron_ble2mqtt-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: victron_ble2mqtt-0.3.0-py3-none-any.whl
- Upload date:
- Size: 23.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 150a568eb2018fcf53eb464c0bd84052025fbb10124449918fa1a3dc2eeb8115 |
|
MD5 | 254c5b44bdce766a37365be6bfb1daa7 |
|
BLAKE2b-256 | e6fe7701f30ab2ea3cab7b38d3abcbf8afd9733f82872c0994b9c69f3144cadd |