Energy metering / smart metering

hello,

I would like to add an energy meter to my openhab setup.
My electrician proposes a hager ECA380D

https://www.hager.be/producten-e-catalogus/energieverdeling/bediening-signalisatie-en-meting/bediening-signalisatie-en-meting/energietellers/eca380d/139144.htm

if I look at the documentation I see it supports IEC 62053-21 / 23, IEC 61557-12

I’m a little confused what is the difference between an energy meter and a smart meter.
Am I correct to assume that Smart meters are used if they talk back to your energy supplier?
Or is this more?

I see that SmartMeter binding supports an older hager devices
EHZ 361Z5 and EHZ 161L5

And these use the IEC 62056-21 protocol

Yet I can’t find these devices (No idea if they are still available)

so I wonder is the device that is propose to me very different and is that something that could be supported by the smart metering binding. (No idea if it’s still maintained)

These define how these meters do their measurements, not which protocols they must use with their ports. But the Hager device supports Modbus, why not using that.

If you tend to use SML (which is quite common, e.g. in Germany), be aware that manufacturers sometimes use special “dialects”. So the compatibility list of the smart meter binding will be

1 Like

Thanks.

These define how these meters do their measurements, not which protocols they must use with their ports.

That makes sense.

he Hager device supports Modbus, why not using that.

Sounds like a better solution.
Although this also more complex, aka a lot to figure out what is coming out.
The device that was proposed, indeed talks modbus

Do I correct assume, then I could “just” listen to the correct port on the ip adres of that device and I will be able to read / query the data? (once I figure out it’s dialect.)

That’s the way.
Modbus is an essentially very simple protocol. The target device exposes a number of “registers” (just binary values) to enquiries and/or for writing.
A “Master” (openHAB) polls the registers it has been configured to, usually fairly frequently.
That’s it.

Modbus can be used over a simple serial interface or over TCP/IP LAN.

1 Like

Hi,

I thought about this over the last days and there are some things you have to consider for yourself and how to do it.

Hardware

Be sure to get the correct one. I checked the model on Hager’s German site: The ECA380D has a so called “Agardio” interface. Seems like something proprietary that Hager uses with his home automation systems.
The “real” modbus version is the ECR380D. Again, this is for Germany, but be sure to double check.

But why using this meter? Sure, Hager makes good and reliable meters. But they’re also expensive. I searched for an alternative meter with comparable specs. You can find some models from China - but as there will flow some current inside this, I didn’t want the all cheap way.
Looking for some European models, I found the Orno OR-WE-516. It has a Modbus RTU interface (see below) and is MID approved. Simplified the latter means, that it measures precisely enough that power companies may use them.

I’ve been wanting my own Modbus reading (independent from my power company) for a long time. So I ordered one of these guys this weekend. :wink:

Protocol

The Hager and Orno meters use Modbus RTU. Physically, that is RS-485, a serial protocol.

There is a variant of Modbus over IP, indeed. But these cheap devices usually don’t implement that.

You may find more details on Wikipedia.

Adapter

You have to use an adapter not to burn your computer when connecting RS-485. There are models for USB, like this one. From the comments, the device should work with Linux.

I’m going to use a Raspberry Pi and bought a HAT from Linker Kit. Linksprite also sells a HAT which should work the same way - looking at the pictures, it could even be the same device. Both expose the RPi’s serial UART but shift the voltage levels.

Software

A small tool called ModBus Measurement Daemon is maintained under the Volkszähler project. It supports the above mentioned Orno meters - that’s what led me to buying this one.
What’s nice about this software is that it exposes the read out data via several APIs. I’m planning to use plain MQTT. Maybe, the Homie API is somewhat more comfortable to use with OpenHAB. I can’t tell, maybe some users can shed some light on this one.

Conclusion

In the end, I think this will be the easiest and most robust way to include a modbus meter. I’ll keep you updated.

These RS485 dongles are so cheap, get two. That way the spare can be used on a laptop e.g. for configuring. (Many modbus slaves can be configured from factory defaults over the Modbus, this is one-time work suited to a Modbus diagnostic tool, not openHAB)

1 Like

I can totally agree. My meter arrived yesterday. I didn’t buy a USB adapter (yet) and debugging was no fun.
My test setup works as planned. Measurements are published to MQTT and an OpenHAB item fetches them. I will post details when finished.

I got it up and running now. As mentioned above, I have a spare RPi which I use to collect Modbus data and send them to a Mosquitto MQTT broker running on a seperate virtual machine.
I first tried plain MQTT. But I discovered, that only the Homie implementation of MBMD sends state messages of all configured meatures, which might become handy.

My MBMD configuration file (/etc/mbmd.yaml) looks like follows:

api: 127.0.0.1:8080
rate: 60s

mqtt:
  broker: my-mqtt-broker:1883
  topic: mbmd
  user: <mqttuser>
  password: <secretpassword>
  qos: 1
  homie: homie

adapters:
- device: /dev/ttyAMA0
  baudrate: 2400
  comset: "8E1"

devices:
- name: orno3p1-1
  type: orno3p
  id: 1
  adapter: /dev/ttyAMA0

Be aware that default baudrate is 9600. I had to lower it because of stability issues. Haven’t figured out that completely yet. I’m waiting for some STP cable - and some bus termination resistors will hopefully help alot. Until then (and as there’s only one meter on the bus), this setup works.

I also changed the template systemd unit a bit as the RPi didn’t manage to load the service immediately after boot.

[Unit]
Description=ModBus Meter Daemon
After=syslog.target

[Service]
User=metering
Group=dialout
ExecStartPre=/bin/sleep 60
ExecStart=/opt/mbmd/mbmd run
Restart=always
RestartSec=20

[Install]
WantedBy=multi-user.target

The rest could be done via PaperUI, as Homie supports autodiscovery. I’m more familiar with textual configuration, so here’s the content of my thing file for those who are interested:

Bridge mqtt:broker:my-mqtt-broker {
    Thing topic orno3p1 "Main Power Meter" {
        Channels:
            Type string : Device_State [ stateTopic = "homie/orno3p1-1/$state" ]
            Type number : Frequency [ stateTopic = "homie/orno3p1-1/meter/frequency" ]
            Type number : Power [ stateTopic = "homie/orno3p1-1/meter/power" ]
            Type number : Energy [ stateTopic = "homie/orno3p1-1/meter/sum" ]
            Type number : Reactive_Power [ stateTopic = "homie/orno3p1-1/meter/reactivepower" ]
            Type number : Apparent_Power [ stateTopic = "homie/orno3p1-1/meter/apparentpower" ]
            Type number : Cos_Phi [ stateTopic = "homie/orno3p1-1/meter/cosphi" ]

            Type number : Voltage_L1 [ stateTopic = "homie/orno3p1-1/meter/voltagel1" ]
            Type number : Current_L1 [ stateTopic = "homie/orno3p1-1/meter/currentl1" ]
            Type number : Power_L1 [ stateTopic = "homie/orno3p1-1/meter/powerl1" ]
            Type number : Energy_L1 [ stateTopic = "homie/orno3p1-1/meter/suml1" ]
            Type number : Reactive_Power_L1 [ stateTopic = "homie/orno3p1-1/meter/reactivepowerl1" ]
            Type number : Apparent_Power_L1 [ stateTopic = "homie/orno3p1-1/meter/apparentpowerl1" ]
            Type number : Cos_Phi_L1 [ stateTopic = "homie/orno3p1-1/meter/cosphil1" ]

            Type number : Voltage_L2 [ stateTopic = "homie/orno3p1-1/meter/voltagel2" ]
            Type number : Current_L2 [ stateTopic = "homie/orno3p1-1/meter/currentl2" ]
            Type number : Power_L2 [ stateTopic = "homie/orno3p1-1/meter/powerl2" ]
            Type number : Energy_L2 [ stateTopic = "homie/orno3p1-1/meter/suml2" ]
            Type number : Reactive_Power_L2 [ stateTopic = "homie/orno3p1-1/meter/reactivepowerl2" ]
            Type number : Apparent_Power_L2 [ stateTopic = "homie/orno3p1-1/meter/apparentpowerl2" ]
            Type number : Cos_Phi_L2 [ stateTopic = "homie/orno3p1-1/meter/cosphil2" ]

            Type number : Voltage_L3 [ stateTopic = "homie/orno3p1-1/meter/voltagel3" ]
            Type number : Current_L3 [ stateTopic = "homie/orno3p1-1/meter/currentl3" ]
            Type number : Power_L3 [ stateTopic = "homie/orno3p1-1/meter/powerl3" ]
            Type number : Energy_L3 [ stateTopic = "homie/orno3p1-1/meter/suml3" ]
            Type number : Reactive_Power_L3 [ stateTopic = "homie/orno3p1-1/meter/reactivepowerl3" ]
            Type number : Apparent_Power_L3 [ stateTopic = "homie/orno3p1-1/meter/apparentpowerl3" ]
            Type number : Cos_Phi_L3 [ stateTopic = "homie/orno3p1-1/meter/cosphil3" ]
    }
}

And the items’ configuration:

Number:Power Main_Power_Meter_Power "Power [%d W]" {channel="mqtt:topic:my-mqtt-broker:orno3p1:Power"}
Number:Power Main_Power_Meter_Reactive_Power "Reactive Power [%d VAr]" {channel="mqtt:topic:my-mqtt-broker:orno3p1:Reactive_Power"}
Number:Power Main_Power_Meter_Apparent_Power "Apparent Power L1 [%d VA]" {channel="mqtt:topic:my-mqtt-broker:orno3p1:Apparent_Power"}
Number:Energy Main_Power_Meter_Energy "Energy [%.2f kWh]" {channel="mqtt:topic:my-mqtt-broker:orno3p1:Energy"}
Number:Frequency Main_Power_Meter_Frequenz "Frequency [%.2f Hz]" {channel="mqtt:topic:my-mqtt-broker:orno3p1:Frequency"}
Number:Dimensionless Main_Power_Meter_Cos_Phi "cos(φ) [%.2f]" {channel="mqtt:topic:my-mqtt-broker:orno3p1:Cos_Phi"}

Number:ElectricPotential Main_Power_Meter_Voltage_L1 "Voltage L1 [%.1f V]" {channel="mqtt:topic:my-mqtt-broker:orno3p1:Voltage_L1"}
Number:ElectricCurrent Main_Power_Meter_Current_L1 "Current L1 [%.2f A]" {channel="mqtt:topic:my-mqtt-broker:orno3p1:Current_L1"}
Number:Power Main_Power_Meter_Power_L1 "Power L1 [%d W]" {channel="mqtt:topic:my-mqtt-broker:orno3p1:Power_L1"}
Number:Energy Main_Power_Meter_Energy_L1 "Energy L1 [%.2f kWh]" {channel="mqtt:topic:my-mqtt-broker:orno3p1:Energy_L1"}
Number:Power Main_Power_Meter_Reactive_Power_L1 "Reactive Power L1 [%d VAr]" {channel="mqtt:topic:my-mqtt-broker:orno3p1:Reactive_Power_L1"}
Number:Power Main_Power_Meter_Apparent_Power_L1 "Apparent Power L1 [%d VA]" {channel="mqtt:topic:my-mqtt-broker:orno3p1:Apparent_Power_L1"}

(Repeat for phases L2 and L3)

If you read carefully, you see that there’s no thing for the device state. I still have to figure out all that state strings, their meaning and how I’ll use them in OH.

Happy tinkering. :wink:

The solution with MBMD works flawlessly so far. I’m still waiting for my STP cable and thinking about some optimisation.
MBMD polls quite many registers - 59 in total.I’m using 24 of them atm. So why wasting ressources of my RPi (1st gen Model B) and spamming the MQTT broker?
What’s more, I’m planning to add at least two more meters to the bus, so I’d like to tweak performance on the field bus, too.

I got ser2net up and running on the RPi and I can connect from Windows, e.g. with the Orno programming tool. But I’ve no clue how to configure a virtual COM port on linux to use the OH Modbus binding.
socat /dev/ttyS2,b9600,raw,echo=0 TCP4:<ip-address>:7000 tells me E tcgetattr(5, 0x7ffee39e9a80): Input/output error.

Any help (or alternative ways) appreciated.

There are gateway boxes for Modbus-TCP (net) <-> Modbus-RTU (serial)

I would like to stick to TCP, as on the place where we will install the meter, there is not much room for other devices.

I checked the model on Hager’s German site: The ECA380D has a so called “Agardio” interface. Seems >like something proprietary that Hager uses with his home automation systems.
The “real” modbus version is the ECR380D. Again, this is for Germany, but be sure to double check.

I’m a little confused. Has the ECR380D also an utp connector?
I’ can’t find that info on the product sheet, yet I can’t find it on the ECA380D product sheet, yet from that I know it has.

The manual shows a two port connector for Modbus RTU.

The manual shows a two port connector for Modbus RTU.
Manual from which device.

yes i see the modbus RTU, I don’t see if it supports UTP, Like I said I want to use modbus over tcp (as I understand modbus supports that, yet I don’t know if the/both devices does supports that.)

UTP is a type of cable, that doesn’t tell you much about the service carried over the cable.

UTP cable is commonly used for serial RS485 Modbus-RTU connections, like shown above.

UTP cable is also used for ethernet LAN connections, which can be used for Modbus-TCP. Nothing related to that is shown above. They’re completely incompatible.

Gateway devices are available which can support both an ethernet and a serial connection, and convert Modbus-TCP to Modbus-RTU

1 Like

UTP is a type of cable, that doesn’t tell you much about the service carried over the cable.

yes I know

UTP cable is commonly used for serial RS485 Modbus-RTU connections, like shown above.

That is new to me. Thank you brun

UTP cable is also used for ethernet LAN connections,

that I knew
which can be used for Modbus-TCP. Nothing related to that is shown above. They’re completely incompatible.

Gateway devices are available which can support both an ethernet and a serial connection, and convert >Modbus-TCP to Modbus-RTU

That makes it sound like it’s a connection issue, yet you said they were incompatible, so I guess there was my misunderstanding.

Thanks the extra info made it a lot clearer.

If I understand, if I want to work modbus-tcp, I have two options:

  • I need to find an energy meter that supports modbus-tcp.
  • I can work with both energy meters now selected and add a device that allows to translate
    modbus-RTU to modbus-TCP

Yes, that’s it.

The other option is to add serial to your host, a USB RS485 dongle say, and cable it to your meter directly. Using UTP cable you can up to 1km.

1 Like

yeah I thought about that, yet one of the places (the garage) where I can install one, I have no multiple UTP cables.
We do have a small switch and one UTP cable to the house, so only an option to us an UTP cable as TCP…

What is your experience now with Mbmd. Is it reliable? Do you think that it can be installed together with OH3 on the same Raspberry? Thanks

I don’t even know what that is. I think you meant this for @grizzle , who should now be tagged.

It depends on your RPi. I run it on an old RPi Rev. 2 (512MB RAM version) and everything seems fine:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
metering  8886  0.5  3.4 808220 16848 ?        Ssl  Jan05  38:18 /opt/mbmd/mbmd run

I have no newer model at hand to tell how much resources OH consumes, but I guess that’d work.

Once it’s setup, Mbmd runs perfectly stable.