endrebjorsvik / kaifa-meter

Read and decode serial data from Kaifa electricity meters
GNU General Public License v3.0
3 stars 1 forks source link

kaifa-meter

Introduction

This is a Python package that reads and decodes serial data from the HAN port of a few Kaifa electricity meters. It may be used as a Python library or as a standalone CLI.

Serial data frame decoding is fairly naive and based on inspiration from roarfred and Per Erik Nordbø. It uses the Construct library to parse messages in a simple and straight-forward manner that is easily understood and maintainable.

The CLI writes decoded data to either:

Feedback and improvement suggestions are welcome.

Tested and supported meters

Untested meters (but should work)

Installation

This package requires Python 3.6+. It depends on several third party packages, so I recommend installing it in a virtualenv. It is packaged to be installed through pip from GitHub.

$ pip install git+https://github.com/endrebjorsvik/kaifa-meter.git

Usage

Connect the electricity meter to a computer using a M-Bus-to-USB converter. It shall appear as a serial port (e.g. /dev/ttyUSB0 or COM3). To print decoded data to your terminal, run

$ kaifa_meter serial /dev/ttyUSB0

To save decoded data to file, run

$ kaifa_meter serial /dev/ttyUSB0 -o /path/to/outfile.txt

It is also possible to dump all data to a PostgreSQL database. To test the database setup, run

$ kaifa_meter initdb --dbname=<name of database> --dbuser=<name of database user> --dbtable=<table to create in database>

You can then dump data directly to the database by

$ kaifa_meter serial /dev/ttyUSB0 --dbname=db --dbuser=user --dbtable=table

Tested platforms

Hardware

The package is tested on a Kaifa MA105H2E meter that is connected to a computer through the following cabling: