Skip to main content

Collect data from Hichi Smartmeter and expose it via MQTT

Project description

pysmartmeter

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

Collect data from Hichi Smartmeter aka volkszaehler.org (USB Version) and expose it via MQTT.

In the end it can looks like the following Home Assistant dashboard screenshot, using MQTT integration:

2022-11-21_13-47.png

With my "eBZ DD3" energy meterby eBZ GmbH the values update live every second ;)

quickstart

Install minimum requirements, e.g.:

~$ sudo apt install make python3-venv

Clone sources and install project:

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

The output of ./cli.py --help looks like:

Usage: ./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 and show coverage.                                               │
│ debug-settings              Display (anonymized) MQTT server username and password               │
│ debug-systemd-service       Just print the systemd service file content                          │
│ detect-serial               Just print the detected serial port instance                         │
│ dump                        Just dump serial output                                              │
│ fix-code-style              Fix code style of all pysmartmeter source code files via darker      │
│ install                     Run pip-sync and install 'pysmartmeter' via pip as editable.         │
│ mypy                        Run Mypy (configured in pyproject.toml)                              │
│ publish                     Build and upload this project to PyPi                                │
│ publish-loop                Publish current data via MQTT (endless loop)                         │
│ safety                      Run safety check against current requirements files                  │
│ setup-systemd-service       Setup PySmartMeter systemd services and starts it.                   │
│ store-settings              Store MQTT server settings.                                          │
│ systemd-restart             Restart PySmartMeter systemd services                                │
│ systemd-status              Call systemd status of PySmartMeter services                         │
│ systemd-stop                Stop PySmartMeter systemd services                                   │
│ 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                                               │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯

Test if you Hichi Smartmeter with CP2102 USB to UART Bridge Controller will be found, e.g.:

~/pysmartmeter$ ./cli.py detect-serial

Maybe you didn't have permissions to access the port, e.g.:

~/pysmartmeter$ ./cli.py dump
...
try: /dev/ttyUSB0 CP2102 USB to UART Bridge Controller - CP2102 USB to UART Bridge Controller USB VID:PID=10C4:EA60
/dev/ttyUSB0 file mode: 0o20660
/dev/ttyUSB0 user ID: 0
/dev/ttyUSB0 user group ID: 20
/dev/ttyUSB0 user group: 'dialout'
ERROR: [Errno 13] could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0'
...

Fix fiy by add the user to the group, e.g.:

sudo usermod -a -G dialout $USER

publish smartmeter data via MQTT

You have to store your MQTT settings (host, port, username, password) one time, e.g.:

~/pysmartmeter$ ./cli.py store-settings

This will create a JSON file here: ~/.pysmartmeter

You can test reading this settings file with:

~/pysmartmeter$ ./cli.py debug-settings

Setup systemd service:

~/pysmartmeter$ sudo ./cli.py setup-systemd-service

This will create a systemd service that automaticly starts on every boot.

Check if service is running:

~/pysmartmeter$ sudo ./cli.py systemd-status

If everything is fine: Go to your Home Assistant and check the MQTT integration The device discovery will be made automaticly.

Backwards-incompatible changes

v0.2.x -> v0.3.x

Packages changes:

  • We switched from poetry to pip-tools
  • Makefile was removed
  • "Renamed" cli.sh to cli.py

The Makefile is no longer needed, because "Bootstrapping" will be made, just by call cli.py

To migrate, just remove the existing .venv and create a fresh one, e.g.:

~$ cd pysmartmeter
~/pysmartmeter$ git pull origin main
~/pysmartmeter$ rm -Rf .venv
~/pysmartmeter$ ./cli.py --help

various links

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

pysmartmeter-0.3.1rc0.tar.gz (34.5 kB view details)

Uploaded Source

Built Distribution

pysmartmeter-0.3.1rc0-py3-none-any.whl (38.9 kB view details)

Uploaded Python 3

File details

Details for the file pysmartmeter-0.3.1rc0.tar.gz.

File metadata

  • Download URL: pysmartmeter-0.3.1rc0.tar.gz
  • Upload date:
  • Size: 34.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for pysmartmeter-0.3.1rc0.tar.gz
Algorithm Hash digest
SHA256 ec044ea899a02c95ee0e53f2b553d691e6fde62a73d3d3c055a650274cd081ed
MD5 d4836d511b343fb70092be67fdf666ce
BLAKE2b-256 abc6dcaae263ce5d1a2ffaf79b54b3e345dec8adda78ae3ab820d7110d7d7e99

See more details on using hashes here.

File details

Details for the file pysmartmeter-0.3.1rc0-py3-none-any.whl.

File metadata

File hashes

Hashes for pysmartmeter-0.3.1rc0-py3-none-any.whl
Algorithm Hash digest
SHA256 b67ee291ec3f14bf70e399691de7bfe605bea6b51acf0b1f2054c35dc323c473
MD5 702bfdc2ab3f94a4883e64b4ca56a4fd
BLAKE2b-256 dbca2252d7aa9785d96326df9a0e41f75291c7b5822f15a5ae9f3b18b0d5794f

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