Skip to main content

Get values from modbus energy meter to MQTT / HomeAssistant

Project description

energymeter2mqtt

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

Get values from modbus energy meter to MQTT / HomeAssistant

Energy Meter -> modbus -> RS485-USB-Adapter -> energymeter2mqtt -> MQTT -> Home Assistant

The current focus is on the energy meter "Saia PCD ALD1D5FD" However, the code is kept flexible, so that similar meters can be quickly put into operation.

Quick start

Overview:

  • Clone the sources
  • Create your config: ./cli.py edit-settings
  • Test: ./cli.py print-values
  • Setup and start MQTT publishing: sudo ./cli.py systemd-setup

Note: It's a good idea to use the /dev/serial/by-id/{your-device-id} path as serial port, instead of /dev/ttyUSB1 Call udevadm info -n /dev/ttyUSB* to get information about all USB serial devices and ls -l /dev/serial/by-id/ to see the existing links.

~$ git clone https://github.com/jedie/energymeter2mqtt.git
~$ cd energymeter2mqtt
~/energymeter2mqtt$ ./dev-cli.py --help
usage: ./cli.py [-h]
                {debug-settings,edit-settings,print-definitions,print-registers,print-values,probe-usb-ports,publish-l
oop,systemd-debug,systemd-remove,systemd-setup,systemd-status,systemd-stop,version}



╭─ options ──────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ -h, --help        show this help message and exit                                                                  │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ subcommands ──────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ {debug-settings,edit-settings,print-definitions,print-registers,print-values,probe-usb-ports,publish-loop,systemd- │
│ debug,systemd-remove,systemd-setup,systemd-status,systemd-stop,version}                                            │
│     debug-settings                                                                                                 │
│                   Display (anonymized) MQTT server username and password                                           │
│     edit-settings                                                                                                  │
│                   Edit the settings file. On first call: Create the default one.                                   │
│     print-definitions                                                                                              │
│                   Print RAW modbus register data                                                                   │
│     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                                                                           │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

start development

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

dev CLI

usage: ./dev-cli.py [-h]
                    {check-code-style,coverage,create-default-settings,fix-code-style,install,mypy,nox,pip-audit,publi
sh,test,update,update-test-snapshot-files,version}



╭─ options ──────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ -h, --help        show this help message and exit                                                                  │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ subcommands ──────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ {check-code-style,coverage,create-default-settings,fix-code-style,install,mypy,nox,pip-audit,publish,test,update,u │
│ pdate-test-snapshot-files,version}                                                                                 │
│     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 energymeter2mqtt source code files via darker                              │
│     install       Install requirements and 'energymeter2mqtt' via pip as editable.                                 │
│     mypy          Run Mypy (configured in pyproject.toml)                                                          │
│     nox           Run nox                                                                                          │
│     pip-audit     Run pip-audit check against current requirements files                                           │
│     publish       Build and upload this project to PyPi                                                            │
│     test          Run unittests                                                                                    │
│     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                                                                           │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

History

  • v0.6.0
    • 2025-04-22 - Update ha-services from v0.6 to v2.10
  • v0.5.0
    • 2025-04-22 - Switch pip-tools to uv
    • 2024-09-06 - Update requirements
  • v0.4.0
    • 2024-09-04 - "retry_on_empty" -> "retries"
    • 2024-09-04 - update project via manageprojects
  • v0.3.0
    • 2024-07-12 - bugfix packaging
    • 2024-07-12 - Bugfix wrong path loading definitions
    • 2024-07-12 - Update requirements adn split CLI code
    • 2024-02-22 - Update requirements
    • 2024-01-01 - Update README.md
Expand older history entries ...
  • v0.2.0
    • 2023-08-29 - NEW command "probe-usb-ports"
    • 2023-08-29 - update requirements
    • 2023-08-29 - Remove nonsens doc string
  • v0.1.2
    • 2023-08-10 - adjust scale factor for double registers
    • 2023-06-27 - fix: adjust scale factor for double registers
  • v0.1.1
  • v0.1.0
    • 2023-05-21 - fix README example
    • 2023-05-21 - README
    • 2023-05-21 - Bugfix unit of "Power Factor (cos phi)"
    • 2023-05-21 - Bugfix systemd config
    • 2023-05-21 - Add logging to get_ha_values()
    • 2023-05-21 - fix wait
    • 2023-05-21 - Bugfix endless loop prints
    • 2023-05-21 - Bugfix voltage scale
    • 2023-05-21 - Publish all values via MQTT to Home Assistant in a endless loop.
    • 2023-05-21 - Fix CI
    • 2023-05-21 - More info in README
    • 2023-05-21 - Split commands
    • 2023-05-21 - Split CLI and use toml settings for energy meter modbus info
    • 2023-05-21 - Working "serial-test" with Saia PCD ALD1D5FD
    • 2023-04-28 - WIP: Test Serial connection
    • 2023-04-30 - Update README.md
    • 2023-04-28 - first commit

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

energymeter2mqtt-0.6.0.tar.gz (82.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

energymeter2mqtt-0.6.0-py3-none-any.whl (24.8 kB view details)

Uploaded Python 3

File details

Details for the file energymeter2mqtt-0.6.0.tar.gz.

File metadata

  • Download URL: energymeter2mqtt-0.6.0.tar.gz
  • Upload date:
  • Size: 82.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for energymeter2mqtt-0.6.0.tar.gz
Algorithm Hash digest
SHA256 91d3653e0fa4f89d03c2c011e400c89035d25875d56a98e96d9c21489500bfa5
MD5 2daa59b814d6dc19f8ad88331b72a039
BLAKE2b-256 bef66099d564e99ccda3670409432246b045a06f9ecd8583e6ea99a8f96e84a3

See more details on using hashes here.

File details

Details for the file energymeter2mqtt-0.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for energymeter2mqtt-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ea9f76ca9dd2461f321be2645e4da9f06a99483754be1d95ae346e1f48c2069c
MD5 a6230ee7e5d78994a666ef0be4b49726
BLAKE2b-256 45c935b6278b2c0e8b7a94d5cdb60e9c725b707147b864088e995024364afc6e

See more details on using hashes here.

Supported by

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