Skip to main content

Collect data from Hichi Smartmeter and expose it via MQTT

Project description

pysmartmeter

Collect data from Hichi Smartmeter aka volkszaehler.org (USB Version) and expose it via MQTT. tests codecov pysmartmeter @ PyPi Python Versions License GPL-3.0-or-later

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$ make install-poetry
~/pysmartmeter$ make install
~/pysmartmeter$ ./cli.sh --help
+ exec .venv/bin/python -m pysmartmeter --help
PySmartMeter v0.1.0

 Usage: python -m pysmartmeter [OPTIONS] COMMAND [ARGS]...

╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────╮
│ --install-completion        [bash|zsh|fish|powershell|pwsh]  Install completion for the specified │
│                                                              shell.                               │
│                                                              [default: None]                      │
│ --show-completion           [bash|zsh|fish|powershell|pwsh]  Show completion for the specified    │
│                                                              shell, to copy it or customize the   │
│                                                              installation.                        │
│                                                              [default: None]                      │
│ --help                                                       Show this message and exit.          │
╰───────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ────────────────────────────────────────────────────────────────────────────────────────╮
│ check-code-style                                                                                  │
│ 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 via darker                                            │
│ mypy                         Run Mypy (configured in pyproject.toml)                              │
│ publish-loop                 Publish current data via MQTT (endless loop)                         │
│ setup-systemd-service        Setup PySmartMeter systemd services and starts it.                   │
│ store-settings               Store MQTT server settings.                                          │
│ systemd-status               Call systemd status of PySmartMeter services                         │
│ systemd-stop                 Stop PySmartMeter systemd services                                   │
│ test                         Run unittests                                                        │
╰───────────────────────────────────────────────────────────────────────────────────────────────────╯

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

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

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

~/pysmartmeter$ ./cli.sh 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.sh store-settings

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

You can test reading this settings file with:

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

Setup systemd service:

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

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

Check if service is running:

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

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

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.2.1rc0.tar.gz (33.4 kB view details)

Uploaded Source

Built Distribution

pysmartmeter-0.2.1rc0-py3-none-any.whl (40.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pysmartmeter-0.2.1rc0.tar.gz
Algorithm Hash digest
SHA256 a0d9bdfa9d7151299c9707c46dbee8f32a750ec7124d4939489fd05e557e21f1
MD5 db48f0bb4e60cadc644e48b6e9a983bf
BLAKE2b-256 5aa0d0b8566c095d3d5789b2a375bab49d715135ec214102fb4d0fd59c64e81d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pysmartmeter-0.2.1rc0-py3-none-any.whl
Algorithm Hash digest
SHA256 e7a07ac8c498cd1a48cfd1f8dfe8b2f27590a2326fc378324494e74715440bb7
MD5 642b0380fe7a72ba580e685282c16e7f
BLAKE2b-256 1795f97e916f0c6a8d6f5b304f43750e902e54305db504648a6e94bc9b1c74a6

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