Smart meter with vzlogger/live energy use as a sensor

When I recently had to do some rewiring of my “official”, dumb electricity meter anyway, I had the opportunity and space to put in another, smart meter I bought myself directly next to it. My self-bought meter basically gives me the opportunity to get a live feed of my electricity use, split up by the 3 phases.

I’ll try to describe how I connected this to HA, because the techniques can be useful for many smart meters, not only self bought ones, but also ones supplied from the utility.

The meter I bought is an EasyMeter Q3D, because this can be fitted interchangeably with the old mechanical meters, and I had a free spot for one of those. At a cost of EUR 120 it was not that expensive either for a calibrated meter. It is readily available at Conrad

One core aspect in choosing this meter was support by vzlogger, a software component of the
volkszähler.org project. vzlogger/volkszaehler supports many electricity, gas and water meters. Unfortunately most of the website and documentation is in German. Meter types are focused on German/continental european types, but many of the standards of these things are international, so many more types should work.

To link my meter to vzlogger I needed an interface to link up my meter to a raspberry pi. Many meters have RS485 output, which is cheap and easy even on a raspberry pi, some have the very simple “S0” interface, which works too, and others have optical interfaces, like my Q3D: You need an optoelectrical reading head (basically half an optocoupler, the other one is in the meter) to get a signal to a serial line. One benefit is that thiis signal can be read out without touching any dangerous parts. I bought the Allnet ALL3688, but there are many other options, and circuit diagrams to wire up a phototransistor and a few censts wort of parts to do the same thing are floating around.

The Allnet ALL3688 works well, but it has one drawback, it needs a 12V supply. I hooked an old 8.2V phone charger: Close enough.There is a data sheet with a pinout: RJ-45 Pin1, 5 : GND, Pin 7,8 +12V, Pin3 : ser. RX. GND and Pin 3 is can be connected to a serial adapter, I have not checked the voltage, maybe even directyl to the internal Raspi serial port ttyAMA0.

To check the hardware setup I used picocom, 9600 baud, even parity, 7 data bits and got something like the following:

/ESY5Q3DA1004 V3.04

1-0:0.0.0*255(1ESY1160437500)
1-081.8.0*255(00000023,7246460*kWh)
1-0:21.7.0*255(000071.27*W)
1-0:41.7.0*255(000013.81*W)
1-0:61.7.0*255(000156.27*W)
1-0:1.7.0*255(000241.35*W)
1-0:96.5,5*255(80)
0-0:96.1.255*255(1ESY1160437500)
!
/ESY5Q3DA1004 V3.04

1-080.0.0*255(1ESY1160037500)
1-0:1.8.0*255(00000023.7247795*kWh)
1-0:21.7.0*255 000071.16*W)
1-0:01.7.0*255(000013.88*W)
1-0:61.7.0*255( 00155.09*W)
1-0:1.7.0*255(000240.13*W)
1-0:96.5.5*255(80!
0-0:96.1.255*255 1ESY1160437500)
!

one of these stanzas is sent every other second. This format could in principle parsed directly, but using vzlogger is so much nicer. vzlogger takes this format from the serial port, and makes JSON available to be chewed up by the home assistant Rest sensor. Added benefit: My meter can be read remotely over the (WiFi) network and not only over cumbersome serial cables. To do this, vzlogger needs a configuration file that describes the meter. For my Q3D this looks like:

// Meter configuration
"meters": [
    {
        "enabled": true,               // disabled meters will be ignored (default)
        "skip": false,                  // errors when opening meter may be ignored if enabled
        "protocol": "d0",               // meter protocol, see 'vzlogger -h' for full list
        "device": "/dev/ttyUSB0",       // meter device
        "dump_file": "/var/log/d0.txt", // detailed log file for all received/transmitted data (optional)
        "parity": "7E1",                // Serial parity, 7E1 or 8N1
        "baudrate": 9600,               // Serial baud rate, typically 9600 or 300
        "interval": 0,                  // Wartezeit in Sekunden bis neue Werte in die middleware übertragen werden
        "channels": [{
            "uuid": "aaaaaaaa-bbbb-cccc-dddd-eeeeeee0",
            "identifier": "1-0:1.8.0"   // OBIS identifier
        }, {
            "uuid": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeea",
            "identifier": "1-0:1.7.0"   // OBIS identifier
        }, {
            "uuid": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeb",
            "identifier": "1-0:21.7.0"   // OBIS identifier
        }, {
            "uuid": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeec",
            "identifier": "1-0:41.7.0"   // OBIS identifier
        }, {
            "uuid": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeed",
            "identifier": "1-0:61.7.0"   // OBIS identifier
        } ]
    }
]

The uuids are choosen arbitrarily. This gives the following JSON output:

{ "version": "0.6.0", "generator": "vzlogger", "data": [ { "uuid": "aaaaaaaa-bbbb-cccc-dddd-eeeeeee0", "last": 1469974831127, "interval": 0, "protocol": "d0", "tuples": [ [ 1469974831127, 42.678551 ] ] }, { "uuid": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeea", "last": 1469974831247, "interval": 0, "protocol": "d0", "tuples": [ [ 1469974831247, 533.130000 ] ] }, { "uuid": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeb", "last": 1469974831157, "interval": 0, "protocol": "d0", "tuples": [ [ 1469974831157, 342.950000 ] ] }, { "uuid": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeec", "last": 1469974831188, "interval": 0, "protocol": "d0", "tuples": [ [ 1469974831188, 52.140000 ] ] }, { "uuid": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeed", "last": 1469974831218, "interval": 0, "protocol": "d0", "tuples": [ [ 1469974831218, 138.040000 ] ] } ] }

and to parse this a template can be used (only the first sensor shown):

  - platform: rest
    resource: http://meter.local:80
    value_template: > 
      {% for i in value_json.data %}
         {% if i.uuid == "aaaaaaaa-bbbb-cccc-dddd-eeeeeee0" %}
           {{ i.tuples[0][1] }}
         {% endif %}
      {% endfor %}

    method: GET
    name: ges
    unit_of:measurement: "kWh"

I don’t know if this can be solved better without the “for”, but this works for me.
meter.local is the hostname of the host vzlogger runs on (a raspberry pi next to the meter)

This setup gives me almost realitme display in Home Assistant (when I switch on my oven, the additional current shows up after about 10s on the HA web interface).

“ges” is total kWh, L1, L2, L3 is the power used on the 3 phases (in Watts), P is total power in Watts.
I’ll post a few photos of the hardware in the next days.

4 Likes

Thank you for this post. I’m also interested it realizing this. How is yours running? Is there any changing in your setup, now after 4 years?

Acutally it is running very well. The raspberry pi was never touched since I posted this here, and the setup proved very reliable after an alignment problem within the first days. The head was not fixed in the right position, so it lost signal sometimes. I solved this by glueing a steel washer to the meter, where the head would be fixed more precisely (it has a strong magnet, my meter is plastic though, so I needed the washer)

Live display in history, peaks are washing machine and the oven:

Photos (the blue box holds the raspberry pi with an serial adapter. The pink cable is a serial interface to the readout head).



Recently I learned of another solution to parse the format of the meters, I will try to find it again and post it here. I do not have any need for an alternative, because my solution runs fine without any problem, and vzlogger was basically painless.

1 Like

Thank you mate! My plan was to run vzlogger on a esp32, but I can’t find anything about this in the internet. Running just volkzähler on my raspberry is a bit oversized, since my home assistant is running on my Synology :slight_smile:

A raspberry is probably oversized for vzlogger. It has practically no load (loadaverage of 0.02 or so. Never tried vzlogger on an esp32 though.

I have an electricity meter from Logarex which only sends when requested. With the IR meter from Weidmann, I get a response from the meter in OBIS protocol via the test tool. My problem now arises as I get the data in Home Assistant, which also runs on a Raspberry. The IR meter is also connected to the USB interface of the Raspberry. Actually, that’s an ideal basic function. Unfortunately, due to my knowledge, it is not possible to get the meter data in Home Assistance. Ideally, I also have the InfluxDB database running in the Docker of a NAS. The data from the electricity meter should then enter here. Maybe someone can help me to get the data in Home Assistant at all?

my vzlogger runs at a seperate Raspberry with this Image:
https://wiki.volkszaehler.org/howto/raspberry_pi_image

Home Assistant runs at other Raspi and with this instruction it works fine:

but I miss some points:

  • presentation in table (weekly, monthly consumption)
  • actual consumption in Watt

I am actually using a shell script to collect the data of the Smart Meter and forward via RestApi to Home Assistant and InfluxDB. The Smart Meter is also connect via USB Port directly at the Raspberry. All works on one Raspberry. At present it works fine for me. I could share the script ASAP.

This would be great if you can share your configuration and script.

I am also interested in the script to capture my Smartmeter data via IR reader (Weidmann) directly on the device where HA is running. Currently I have Volkszaehler running but it seems that the integration to HA is a little buggy as I get “entity not available” errors from time to time. All in all VZ might be oversized and also seems old fashioned to me at least for my use case.

@nuki47 @Jim_Tonic I have test the script for a short time and it seems to run without any problems. Please refer to the project site for downloading and testing on your own.

1 Like

@Cavekeeper many thanks for the sricpt. I do have exactly the same setup as you have and I installed the script but no sensor is being created. I opened an issue on your github project site. Would be great if you can have a look.

@nuki47 & @Jim_Tonic did you also install the script? Did it work for you?

I have a different energy meter (eBZ) so I guess I need to dig a little deeper into @Cavekeepers script (e.g. find the proper stty settings). Will keep you posted.

Hi, I also setup vzlogger with home assistant. I am using a USB IR dongle that I bought. Software-side I

  • created a Docker with the newest vzlogger (see pull request https://github.com/volkszaehler/vzlogger/pull/448 ). This is helpful to avoid having all dependencies and scatter install files in my Raspi, so I can run it along my other docker stuff.

  • used MQTT to pass data to the Mosquitto Broker Addon and from there pulled it directly into Homeassistant.

(before that I used http push -> Node Red -> MQTT -> homeassistant auto discover, but it is easier to go directly to MQTT and avoid http completely).

Basically this is what is needed in the vzlogger.config, take a look at the mqtt section. You can also (in the meters) specify aggregation intervals (mean or max) to avoid sending too much unneeded data.

And in Homeassistant the usual setup, google: homeassistant mqtt sensor

I also (using statistics) have a 24h difference computation, to see how much power I use each day.
Am pretty happy with this setup.

Hey @Highwind,
thanks for this great idea.
Actually, I try to run the same but have several problems and questions:

  • are you running the vzlogger docker on the same raspi as your homeassistant ?
  • do I need to configure middleware or how can I deactivate?
  • What UUIDs do I use? Just create some randomly?
  • Can you please post or send your complete config again? It is somehow cut here in the forum
    Thanks a lot,
    Michael

Hi @MichiW1 ,

  • yes, running on the same raspi. But since it pushes via MQTT it can be anywhere I guess.
  • no middleware, just run vzlogger with the config as above. Don’t install middleware at all.
  • UUID whatever you want
  • There is a link underneath the file “show original” which will show the complete config.

One thing: For me vzlogger frequently hangs and I don’t know why. Simply restarting fixes it. Could be my hardware sensors are not working nicely with it. Not sure.

Also I was trying to create an HomeAssistant AddOn Docker. That would mean it will run on the same raspy but the advantage is, when it hangs one could automatically restart the add-on. I did not get it to work yet, but will post here if I ever do.

Hey guys,
I got the homeassistant Add-on working. It runs a vzlogger on the same machine (so your IR readers need to be installed on the same computer). Here is the link for the repository in Supervisor:

just add it and you can then install the vzlogger2mqtt addon. Currently, not all Arch compile due to problems with Alpine time , but I am working on it. ARM works (so raspi should work). Using a multi-stage docker file I was able to create a really small docker image.

2 Likes

Amazing! thank you so much for this. it is exactly what I was looking for and I’m so glad someone’s already done this and shared it.

can some of you post here what IR reader i need to buy? I would love to build it. I have the pretty common Landis+Gyr E450.