Reading Power consumption of the Electricity meter with the IR interface

As a data nerd I wanted to know how much power I am consuming or feeding-in with my solar inverter. In Germany the old Ferraris Electricity meter are being replaced to electronic versions, but unfortunately not all of them are smart. However most of them have an infra-red interface and this tutorial describes how you can read it using a IR head and a raspberry pi.

Hardware you need:

  • verify you have the IR interface on your Electricity meter
  • a raspberry pi close to your Electricity meter with Wifi access to your home network and SSH running. I guess there are enough tutorials around how to set it up.
  • a IR read/write head with USB (Optohead). I bought this one for ~45 EUR, but you could build them yourself as well (here a instruction in German)

Once you plug the USB part into your raspi and put the IR head onto your Electricity meter, your ready to go.

First you can test it, using this instructions:
Open one SSH terminal and enter:

stty -F /dev/ttyUSB0 300 -parodd cs7 -cstopb parenb -ixoff -crtscts -hupcl -ixon -opost -onlcr -isig -icanon -iexten -echo -echoe -echoctl -echoke
cat /dev/ttyUSB0

Open a second SSH terminal and enter within 2 minutes:

echo -n -e '\x2F\x3F\x21\x0D\x0A' > /dev/ttyUSB0
echo -n -e '\x06\x30\x30\x30\x0D\x0A' > /dev/ttyUSB0

If it works, you should ge an output similar to this:

/?!
/LOG4LK13BD202035
C.1.0(0xxxxxx)
0.0.0(001LOG000xxxxx)
F.F(0000)
1.8.0(011021.857*kWh)
2.8.0(011614.452*kWh)
C.7.1(00000002)
C.7.2(00000003)
C.7.3(00000002)

Interesting for us is the value 1.8.0 (the power being supplied) and - if you produce power - the value 2.8.0 (the power you feed-in).

There are different ways to make use of these values, e.g. there is a node-red module you could use. My way is to have a small python script on the raspberry pi which runs every 5 min, posting the values via MQTT:


#!/usr/bin/env python
import time
import sys
import serial
import re
import paho.mqtt.client as mqtt

broker_address="namibia"
client = mqtt.Client("P1") #create new instance
client.connect(broker_address) #connect to broker


ser = serial.Serial(
 port='/dev/ttyUSB0', baudrate = 300,
 parity=serial.PARITY_EVEN, stopbits=serial.STOPBITS_ONE,
 bytesize=serial.SEVENBITS, xonxoff =False,
 rtscts  = False, dsrdtr  = False, timeout=1)
print(ser.name)         # check which port was really used
ser.write(b'\x2F\x3F\x21\x0D\x0A')     # write a string
ret=ser.readlines(5)
print (ret)
time.sleep(1)
ser.write(b'\x06\x30\x30\x30\x0D\x0A')
ret=str(ser.readlines(150))
m = re.search('1.8.0\((.+?)\*', ret)
if m:
  supply=m.group(1)
  print (supply) #kWh
  client.publish("power/supply",supply) #publish kWh taken from power provider
  time.sleep(1)
m = re.search('2.8.0\((.+?)\*', ret)
if m:
  feedin=m.group(1)
  print (feedin) #kWh
  client.publish("power/feed",feedin) #publish kWh feeded in to  power provider

ser.close()

On your raspberry you need pyserial and paho-mqtt to be installed (pip install…). In your openhab setup you need to have a MQTT broker up and running - there are various tutorials around how to set this up.

Then you can come up with something like…

…in your thing file (if you setup your MQTT broker via files):

...
Thing topic sensoren {  
    Channels:
        Type number : power_supply "Strombezug" [ stateTopic="power/supply", retained=true]

…and in your item file:

Number Power_Supply "Strombezug [%.1f kWh]" <energy> (gUG) { channel = "mqtt:topic:brokerhome:sensoren:power_supply" }

I integrated the items into a influxdb persistence - there is as well a great tutorial on how to set this up.

That’s it in a nutshell. Let me know if something is missing.

3 Likes

Thanks for posting this.

I’d never even thought about it.

It turns out that the electricity meter my house had installed nearly 20 years ago, has the port !!! :smile:

Landis Gyr E470

Is this the kind of DIY project that could keep us amused while we have to stay at home?

https://learn.sparkfun.com/tutorials/ir-communication/all

Or would this 38Khz Dongle do the trick?

https://www.aliexpress.com/item/4000219140520.html

Short Lived adventure

Well, as normal, the UK market isn’t quite as open as we’re led to believe…

Hardly the behaviour of self appointed world leaders

each meter manufacturer creates their own internal software and are unlikely to make it accessible to the general population. We know that Landis and Gyr won’t allow their version of software out and British Gas don’t have access to it.

In my case it’s a Logarex LK13BD and on their homepage you can find infos to the protocols they use (RS 232, RS 485). In your case the manufacturer doesn’t say so much, so either you give it a shot and hope they use a standard protocol or investigate into the Zigbee interface.

Probably not, I wouldn’t even know how to attache it. The head from Wiedmann I have is magnetic and sticks to the interface (see picture, by the way they deliver to UK as well :wink:).

1 Like

For the adventurous among us; I managed to have it done with a split TCRT5000 as used in line follower boards (like mine VMA326). Wired up to an usb-rs232-ttl or if you prefer an arduino nano or other.
front view-small side view-small vma326_front

3 Likes

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.