跳转到主要内容

从modbus能源计量器获取值到MQTT / HomeAssistant

项目描述

energymeter2mqtt

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

从modbus能源计量器获取值到MQTT / HomeAssistant

能源计量器 -> modbus -> RS485-USB-适配器 -> energymeter2mqtt -> MQTT -> Home Assistant

当前重点是能源计量器 "Saia PCD ALD1D5FD"。然而,代码保持灵活,因此可以快速将类似计量器投入使用。

快速开始

概述

  • 克隆源代码
  • 创建你的配置: ./cli.py edit-settings
  • 测试: ./cli.py print-values
  • 设置并启动MQTT发布: sudo ./cli.py systemd-setup

注意:建议使用/dev/serial/by-id/{your-device-id}路径作为串行端口,而不是/dev/ttyUSB1。调用udevadm info -n /dev/ttyUSB*以获取所有USB串行设备的信息,并调用ls -l /dev/serial/by-id/以查看现有的链接。

~$ git clone https://github.com/jedie/energymeter2mqtt.git
~$ cd energymeter2mqtt
~/energymeter2mqtt$ ./dev-cli.py --help
Usage: ./cli.py [OPTIONS] COMMAND [ARGS]...

╭─ Options ────────────────────────────────────────────────────────────────────────────────────────╮
│ --help      Show this message and exit.                                                          │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────╮
│ debug-settings   Display (anonymized) MQTT server username and password                          │
│ edit-settings    Edit the settings file. On first call: Create the default one.                  │
│ print-registers  Print RAW modbus register data                                                  │
│ print-values     Print all values from the definition in endless loop                            │
│ probe-usb-ports  Probe through the USB ports and print the values from definition                │
│ publish-loop     Publish all values via MQTT to Home Assistant in a endless loop.                │
│ systemd-debug    Print Systemd service template + context + rendered file content.               │
│ systemd-remove   Stops the systemd service and removed the 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                                                          │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯

开始开发

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

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.                                  │
│ create-default-settings     Create a default user settings file. (Used by CI pipeline ;)         │
│ 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                                               │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯

项目细节


下载文件

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

源代码分发

energymeter2mqtt-0.4.0.tar.gz (53.0 kB 查看哈希值)

上传时间: 源代码

构建分发

energymeter2mqtt-0.4.0-py3-none-any.whl (22.7 kB 查看哈希值)

上传于 Python 3

由以下提供支持