Skip to main content

Emit MQTT events from victron-ble

Project description

victron_ble2mqtt

tests codecov victron_ble2mqtt @ PyPi Python Versions License GPL-3.0-or-later

Emit MQTT events from Victron Energy Smart Devices via victron-ble

Tested with:

Scrrenshot from Home Assistant:

2024-09-24 victron-ble2mqtt v0.4.0 Home Assistant 1.png

More screenshots here: https://github.com/jedie/jedie.github.io/blob/master/screenshots/victron-ble2mqtt/README.md

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 devices and print them. Device keys 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 Keys

You need the device keys of all Victron Energy Smart Devices you want to monitor.

The easiest way to get the keys: Install the official Victron Smartphone App and copy&paste the keys:

  • Click on your device
  • Go to detail page about the SmartSolar Bluetooth Interface
  • Click on SHOW at Instant 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 all devices keys.

Test

Start publish MQTT endless look, just call publish-loop command, e.g.:

~/victron-ble2mqtt$ ./cli.py publish-loop -vv

setup systemd services

Check systemd setup:

~/victron-ble2mqtt$ ./cli.py systemd-debug

Setup services:

~/victron-ble2mqtt$ ./cli.py systemd-setup

After this the MQTT publising runs and will be started on boot.

Check the services:

~/victron-ble2mqtt$ ./cli.py systemd-status

Backwards-incompatible changes

0.4.0

You must edit your settings:

  • device_address (The Device MAC address) was removed
  • device_key is replaced by device_keys a list of device keys

Just insert the keys of all Victron Energy Smart Devices you want to monitor.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

victron_ble2mqtt-0.4.0.tar.gz (75.3 kB view details)

Uploaded Source

Built Distribution

victron_ble2mqtt-0.4.0-py3-none-any.whl (25.9 kB view details)

Uploaded Python 3

File details

Details for the file victron_ble2mqtt-0.4.0.tar.gz.

File metadata

  • Download URL: victron_ble2mqtt-0.4.0.tar.gz
  • Upload date:
  • Size: 75.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for victron_ble2mqtt-0.4.0.tar.gz
Algorithm Hash digest
SHA256 d8d40c7f662b5fd35e36e5dc37412376a05da3f03dc41b2ef2ce3eea2d4da2b1
MD5 36c0ab7052cb70a06b3f3a34901c01f2
BLAKE2b-256 40cb79121a720aac070f3e66d186e5ee5e52641288562621a4b5031aef437375

See more details on using hashes here.

File details

Details for the file victron_ble2mqtt-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for victron_ble2mqtt-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 42371a500ec417718d0ae478138ec177238628f8a9ff09c355b99ca7afcd9f63
MD5 2544e8fa6bc874242460f71557d42d78
BLAKE2b-256 7f6035834259ec5cdb9c6f17094c24d0dcbf5a1b3474a0ede37df6cbb4262d78

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page