Talking to a 79 zł DIN-rail energy meter over RS-485
Moved from the old blog in October 2026.
I wanted to know where the electricity in the flat goes, with better resolution than the monthly bill and the app of the energy company, which shows one number per hour a day later. So: a single-phase DIN-rail meter with RS-485, bought on Allegro for 79 zł. No brand on it, “Modbus RTU” printed on the front, a manual of one A5 sheet.
A note before anything else: the meter sits in the distribution board after the main breaker. A friend who is an electrician installed it. If you don’t know what you are doing with 230 V, don’t do this part yourself. The RS-485 side is low voltage and isolated in the meter.
The hardware
About 6 m of one CAT5 pair from the hallway to the closet where the Pi lives.
- Raspberry Pi Zero 2 W that was already doing other things.
- USB to RS-485 dongle with CH340 and MAX485, 17 zł. It has its own 120 Ω termination resistor. With one terminator at each end and 6 m of cable that is fine in theory, but my dongle’s resistor is next to the connector and the “end” of the bus is ambiguous anyway, so I removed it and put one resistor at the meter.
- One pair of an old CAT5 cable. No ground wire, the meter has no ground terminal for RS-485. Officially there should be a common reference. In a flat with everything on one phase it works without.
What the manual said and what was true
The manual: 9600 baud, 8N1, address 1, “registers as standard”. Result with these settings: no answer at all.
Things that can be wrong on RS-485: baud rate, parity, address, A/B swapped, or the meter needs something before it talks. I swapped A and B first, because every manufacturer labels them differently. Still nothing. Then a small scanner that tries every combination and sends a request for register 0 (voltage) to address 1:
import serial, struct
def crc16(data):
crc = 0xFFFF
for b in data:
crc ^= b
for _ in range(8):
crc = (crc >> 1) ^ 0xA001 if crc & 1 else crc >> 1
return crc
def request(addr, func, reg, count):
pdu = struct.pack(">BBHH", addr, func, reg, count)
return pdu + struct.pack("<H", crc16(pdu))
for baud in (1200, 2400, 4800, 9600, 19200):
for parity in "NEO":
with serial.Serial("/dev/ttyUSB0", baud, parity=parity, timeout=0.5) as s:
s.write(request(1, 0x04, 0x0000, 2))
r = s.read(9)
print(baud, parity, r.hex(" ") if r else "-")
$ python3 scan.py
1200 N -
1200 E -
1200 O -
2400 N 01 04 04 43 66 33 33 5a fa
2400 E -
2400 O -
4800 N -
...
2400 8N1. The reply decodes as a 32-bit big-endian float: 43 66 33 33 is 230.2. Voltage. Good.
Byte by byte, for anyone who has not seen Modbus RTU before:
| Bytes | Meaning |
|---|---|
01 |
slave address |
04 |
function: read input registers |
00 00 |
first register |
00 02 |
number of registers (one float = two 16-bit registers) |
71 CB |
CRC-16, low byte first |
The reply is address, function, byte count (04), four data bytes, CRC.
The register map
The register list in the manual looked like the one of the well-known Eastron meters, so I assumed this is a clone and tried those addresses. Most of them work:
| Register | Value | Check against | Result |
|---|---|---|---|
| 0x0000 | voltage | UT61E+ at the socket | 230.2 V vs 230.6 V |
| 0x0006 | current | clamp meter | 9.26 A vs 9.3 A (kettle) |
| 0x000C | active power | kettle rated 2000–2200 W | 2131 W |
| 0x001E | power factor | 1.00 kettle, 0.62 fridge | |
| 0x0046 | frequency | 49.98–50.02 Hz | |
| 0x0048 | import energy | the meter’s own LCD | same |
| 0x0156 | total energy | exception 02 |
Three quirks I found the hard way:
- Only two registers per request. Ask for 4 or 16 registers in one go and there is no answer at all, not even an exception. So you can’t read everything in one frame, it’s one request per value.
- Total energy at 0x0156 doesn’t exist. The reply is
01 84 02 C2 C1, exception 02, illegal data address. Import energy at 0x0048 is the same number for me, because I don’t export anything. - It needs a pause. If the next request comes less than about 50 ms after the previous reply, every second request is ignored. With 60 ms it is reliable.
At 2400 baud one request-reply takes about 110 ms including the meter’s thinking time. Six values plus pauses, around one second. I read every 10 s, more than enough.
The logger
import serial, sqlite3, struct, time
REGS = [("v", 0x0000), ("i", 0x0006), ("p", 0x000C),
("pf", 0x001E), ("f", 0x0046), ("kwh", 0x0048)]
def read_float(ser, reg):
ser.reset_input_buffer()
ser.write(request(1, 0x04, reg, 2))
r = ser.read(9) # 9 bytes for a float, 5 for an exception
if len(r) >= 5 and r[1] == 0x84:
raise IOError("exception %d at 0x%04x" % (r[2], reg))
if len(r) != 9 or crc16(r[:7]) != int.from_bytes(r[7:], "little"):
raise IOError("bad reply: " + r.hex(" "))
return struct.unpack(">f", r[3:7])[0]
ser = serial.Serial("/dev/ttyUSB0", 2400, timeout=0.3)
db = sqlite3.connect("/home/pi/meter.db")
db.execute("create table if not exists m (ts int, v real, i real, p real, pf real, f real, kwh real)")
while True:
t0 = time.time()
try:
row = []
for name, reg in REGS:
row.append(read_float(ser, reg))
time.sleep(0.06)
db.execute("insert into m values (?,?,?,?,?,?,?)", (int(t0), *row))
db.commit()
except IOError as e:
print(time.strftime("%H:%M:%S"), e)
time.sleep(max(0, 10 - (time.time() - t0)))
(crc16 and request are the same as in the scanner.) It runs as a systemd service. In the first week there were 11 bad replies out of about 360 000 requests, all of them at moments when the washing machine motor was switching. That’s acceptable for me.
One day
Sunday 17 Nov 2024. The night base is about 80 W, the fridge adds 70 W when it runs.
Some things I learned from the first week, besides the obvious kettle:
- Base load is about 80 W, all night. Router, the Pi, two phone chargers, TV in standby, the boiler controller, the fridge’s electronics. 80 W × 8760 h is 700 kWh a year, more than I expected. A smart plug with measurement found 9 W for the TV “standby” with the quick-start option on. Off now.
- The fridge runs about 20 minutes of every hour at 70 W. That’s only about 0.6 kWh per day, better than I thought for its age.
- The washing machine heats with 2 kW for the first 15 minutes, then the motor is only 150–350 W.
- The induction hob doesn’t take constant power at a middle setting. It switches between about 1300 W and 420 W every minute or two, that is the thick band at 18:30.
The whole Sunday was 5.76 kWh. Next step: a simple page with the daily totals, and a second meter for the circuit with the lab room, because I want to know what the soldering station and the scope cost per month. I suspect: not much, compared with the kettle.
Questions or corrections: marek@peplow-labs.info. There are no comments here, but I read the mail.