Package: smeterd
smeterdRead P1 smart meter packets in Pythoninstallationsmeterdis fully python 3.6+ compatible.It is highly recommended to use virtualenv for this.
After having your virtualenv installed and activated run the following command to install
thesmeterdpackage directly from pypi (using pip):$ pip install smeterdAlternatively you can manually clonesmeterdand run setupttoolssetup.py:$ git clone https://github.com/nrocco/smeterd.git
$ cd smeterd
$ python setup.py installThis will install the needed python libraries (in this case only pyserial)
which are needed to start reading P1 packets.If you don't want to installsmeterdas a package you can run it directly
from the root directory of the git repository using the following command but
you are responsible for manually installing dependencies:$ python -m smeterdusage as a cli applicationTo get an idea of the available functionality see thehelpoutput:$ smeterd -hTo makesmeterdoutput more verbose use the-voption on any of the
following commands. You can repeat the option to increase verbosity:$ smeterd -vvvTo get help for a specific subcommand use the-hor--helpafter
having typed the subcommand:$ smeterd {subcommand} -hRead one packet from your meter using the following command:$ smeterd read-meter
Time                      2013-08-25 10:10:45.337563
Total kWh High consumed   651038
Total kWh Low consumed    546115
Total gas consumed        963498
Current kWh tariff        1
Gas Measured At           1516562094By default theread-metercommands spits out the current date, total kwh1,
total kwh2, total gas amounts and current kWh tariff on multiple lines.You can make it print the same values as a tab seperated list:$ smeterd read-meter --tsv
2013-05-04 22:22:32.224929	331557	199339	749169	1	1516562094By piping the output of theread-meter --tsvcommand to a bash script you can fully
customize what you want to do with the data:IFS='{tab}'
while read date kwh1 kwh2 gas tariff gas_measured_at; do
  mysql my_database -e "INSERT INTO data VALUES ('$date', $kwh1, $kwh2, $gas, $tariff, $gas_measured_at);"
done < /dev/stdinTypically you run this command fromcronevery x minutes (e.g. 5 minutes):*/5 * * * * /path/to/venv/bin/smeterd read-meter | save_to_mysql_script.shIf you need to use another serial port then the default/dev/ttyUSB0you can
use the above command with the--serial-portoption:$ smeterd read-meter --serial-port /dev/ttyS0Currently only kwh1, kwh2 and gas usage are read. If you specify the--rawcommand line option you will see the raw packet from the smart meter:$ smeterd read-meter --raw
/ISk5\2ME382-1004

0-0:96.1.1(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)
1-0:1.8.1(00331.476*kWh)
1-0:1.8.2(00199.339*kWh)
1-0:2.8.1(00000.000*kWh)
1-0:2.8.2(00000.000*kWh)
0-0:96.14.0(0001)
1-0:1.7.0(0000.13*kW)
1-0:2.7.0(0000.00*kW)
0-0:17.0.0(0999.00*kW)
0-0:96.3.10(1)
0-0:96.13.1()
0-0:96.13.0()
0-1:24.1.0(3)
0-1:96.1.0(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)
0-1:24.3.0(130504210000)(00)(60)(1)(0-1:24.2.1)(m3)
(00749.123)
0-1:24.4.0(1)
!usage as a python moduleIf usingsmeterdas a cli application you will find that its functionality
is quite limited. You can use thesmeterdpackage as a regular python module
so you can integrate the reading of P1 packets into your own solutions.First initiate a new SmartMeter object:>>> from smeterd.meter import SmartMeter
>>> meter = SmartMeter('/dev/ttyS0')Now to read one packet from the meter:>>> packet = meter.read_one_packet()
>>> print packetDo not forget to close the connection to the serial port:>>> meter.disconnect()TheSmartMeter.meter.read_one_packet()function will return an instance of
thesmeterd.meter.P1Packetclass.contributeFork itCreate your feature branch (git checkout -b my-new-feature)Commit your changes (git commit -am 'Add some feature')Make sure that tests pass (make test)Push to the branch (git push origin my-new-feature)Create new Pull Request