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

start development

~$ 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                                               │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯

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.4.0.tar.gz (53.0 kB view hashes)

Uploaded Source

Built Distribution

energymeter2mqtt-0.4.0-py3-none-any.whl (22.7 kB view hashes)

Uploaded Python 3

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