跳转到主要内容

从Victron Energy智能设备通过victron-ble发射MQTT事件

项目描述

victron_ble2mqtt

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

通过victron-ble从Victron Energy智能设备发射MQTT事件

测试与

Home Assistant屏幕截图

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

更多截图在此处: https://github.com/jedie/jedie.github.io/blob/master/screenshots/victron-ble2mqtt/README.md

用法

准备

victron_ble 使用 Bleak,Bleak的Linux后端通过DBus与BlueZ通信。因此,您需要安装此软件,例如。

~$ sudo apt install bluez

引导

克隆源代码,只需调用CLI创建Python虚拟环境,例如。

~$ git clone https://github.com/jedie/victron-ble2mqtt.git
~$ cd victron-ble2mqtt
~/victron-ble2mqtt$ ./cli.py --help

应用程序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                                                       │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯

开发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                                               │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯

设置设备

首先检测您的设备,例如。

~/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)

设备密钥

您需要监控的所有Victron Energy智能设备的设备密钥。

获取密钥的最简单方法:安装官方Victron智能手机应用程序并复制粘贴密钥

  • 点击您的设备
  • 转到关于SmartSolar蓝牙接口的详细页面
  • 通过蓝牙即时读取 / 加密数据处点击显示
  • 通过点击密钥复制连接密钥

(我通过Signal作为“我的笔记”发送密钥,并使用桌面Signal应用程序在我的计算机上接收密钥)

另请参阅: https://community.victronenergy.com/questions/187303/victron-bluetooth-advertising-protocol.html

设置

只需调用edit-settings命令,例如。

~/victron-ble2mqtt$ ./cli.py edit-settings

至少插入您的MQTT设置和所有设备密钥。

测试

启动发布MQTT无限查找,只需调用publish-loop命令,例如。

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

设置systemd服务

检查systemd设置

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

设置服务

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

在此之后,MQTT发布将运行,并在启动时启动。

检查服务

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

不兼容的更改

0.4.0

您必须编辑您的设置

  • device_address(设备MAC地址)已被删除
  • device_key已被device_keys(设备密钥列表)所替代

只需插入您想监控的所有Victron Energy智能设备的密钥。

项目详情


下载文件

下载您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

victron_ble2mqtt-0.5.0.tar.gz (75.6 kB 查看哈希值)

上传时间:

构建分布

victron_ble2mqtt-0.5.0-py3-none-any.whl (26.2 kB 查看哈希值)

上传时间: Python 3

由支持