Smartmeter problems

Hello,
I have two smartmeters and I failed to properly integrate either one with the smartmeter binding or the IEC binding.
The first one is a EMH ITZ which according to the manual is a mode C compatible with 300, 1 200, 2 400 or 4 800 baud. Smartmeter-readout works a little bit in that it can read the meter:

./smartmeter-readout -d /dev/ttyUSB0
DEBUG: Opening /dev/ttyUSB0
DEBUG: Sending sign-on
DEBUG: Reading identification
DEBUG: Read on serial port: `/?!..'
DEBUG: Identification received: `/?!..'
DEBUG: Sending sign-on
DEBUG: Reading identification
DEBUG: Read on serial port: `/?!..'
DEBUG: Identification received: `/?!..'
DEBUG: Sending sign-on
DEBUG: Reading identification
DEBUG: Read on serial port: `/?!../EMH4\@--ITZ-G003VE..'
DEBUG: Identification received: `/?!..'
DEBUG: Sending sign-on
DEBUG: Reading identification
DEBUG: Identification received: `/EMH4\@--ITZ-G003VE..'
DEBUG: Upgrading to 4800 bps.
DEBUG: Receiving telegram.
DEBUG: Read on serial port: `/?!...040..'
DEBUG: Received `/?!..'.
DEBUG: Received `.040..'.
DEBUG: Read on serial port: `.F.F(00000000)..0.0.0(08033086)..0.0.1(08033086)..0.0.2(08033086)..0.1.0(03)..0.1.2*03(190601000000)..0.1.2*02(190501000000)..0.1.2*01(190408110211)..0.1.2*00(000000000000)..0.1.2*99(000000000000)..0.1.2*98(000000000000)..0.1.2*97(000000000000)..0.1.2*96('
DEBUG: Received `.F.F(00000000)..'.
DEBUG: Received `0.0.0(08033086)..'.
DEBUG: Received `0.0.1(08033086)..'.
DEBUG: Received `0.0.2(08033086)..'.
DEBUG: Received `0.1.0(03)..'.

But in continous mode even that failed after the 4th reading.

DEBUG: Sending sign-on
DEBUG: Reading identification
DEBUG: Read on serial port: `/?!..'
DEBUG: Identification received: `/?!..'
DEBUG: Sending sign-on
DEBUG: Reading identification
DEBUG: Read on serial port: `/?!..'
DEBUG: Identification received: `/?!..'
DEBUG: Sending sign-on
DEBUG: Reading identification
DEBUG: Read on serial port: `/?!..'
DEBUG: Identification received: `/?!..'
DEBUG: Sending sign-on
DEBUG: Reading identification
DEBUG: Read on serial port: `/AI.  .--ITZ-G003VE..'
DEBUG: Identification received: `/AI.  .--ITZ-G003VE..'
DEBUG: Sending sign-on
DEBUG: Reading identification
DEBUG: Read on serial port: `/?!..'
DEBUG: Identification received: `/?!..'
DEBUG: Sending sign-on
DEBUG: Reading identification
DEBUG: Read on serial port: `/?!..'
DEBUG: Identification received: `/?!..'
Unable to get values, No identification message received from meter..

The other meter is a Logarex LK13B and it appears to be sending automatically, and I am able to read it with the serial binding and some rules at 9600baud. This works very well, but even that I can’t get to work with the smartmeter binding.

For both I use theWeidmann Elektronik Stromzähler, Smart Meter IR reader. I am running OH 2.4 on a raspberry pi B+. For either one I get the following message:

Failed to read: The source did not signal an event for 30 seconds and has been terminated.. Closing connection and trying again in 2 seconds...; smartmeter:meter:power

java.util.concurrent.TimeoutException: The source did not signal an event for 30 seconds and has been terminated.

	at io.reactivex.internal.operators.flowable.FlowableTimeoutTimed$TimeoutSubscriber.onTimeout(FlowableTimeoutTimed.java:139) [266:org.openhab.binding.smartmeter:2.4.0]

	at io.reactivex.internal.operators.flowable.FlowableTimeoutTimed$TimeoutTask.run(FlowableTimeoutTimed.java:170) [266:org.openhab.binding.smartmeter:2.4.0]

	at io.reactivex.internal.schedulers.ExecutorScheduler$ExecutorWorker$BooleanRunnable.run(ExecutorScheduler.java:260) [266:org.openhab.binding.smartmeter:2.4.0]

	at io.reactivex.internal.schedulers.ExecutorScheduler$ExecutorWorker.run(ExecutorScheduler.java:225) [266:org.openhab.binding.smartmeter:2.4.0]

	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]

Any tips for debugging this?
I tried all kind of variations (mode, baudrateChangeDelay, with and without initMessage etc) for the thing:

//smartmeter:meter:power [port="/dev/ttyUSB1", baudrateChangeDelay=250, refresh=60, mode="SML"]
//smartmeter:meter:powerHeatPump [port="/dev/ttyUSB0", baudrateChangeDelay=250, refresh=10, mode="ABC", baudRate=300, initMessage="2F3F210D0A"]

For the EMH I hacked together a quick script that appears to be working:

# -*- coding: ISO-8859-1 -*-

import serial
import time
import re
from urllib import request, parse
import multiprocessing

SERIALPORT = "/dev/ttyUSB0"
INITAL_BAUDRATE = 300

def postUdpate(item, value):
    req =  request.Request("http://localhost:8080/rest/items/"+item+"/state", data=str(value).encode('utf-8'))
    req.add_header('Content-Type', 'text/plain')
    req.get_method = lambda: 'PUT'
    resp = request.urlopen(req)
    if resp.status!=202 :
        print("Response was %s %s" % (resp.status, resp.reason))

def startQuery():
    ser.baudrate = INITAL_BAUDRATE
    time.sleep(0.3)
    sendtxta = "/?!\r\n"
    ser.write(sendtxta.encode())
    ser.flush()
    response=ser.readline()
    #print(response) #this is the echo
    response=ser.readline()
    #print(response)
    sendtxta = "\x06040\r\n"
    ser.write(sendtxta.encode())
    ser.flush()
    time.sleep(0.3)
    ser.baudrate = 4800
    #print("Switching to {}".format(ser.baudrate))

def startQueryLoop():
    startQuery()
    while True:
        response=ser.readline()
        #print(response)
        regexMatch = re.search('1.8.0\((.*)\*kWh\).*', response.decode("UTF-8"))
        if regexMatch:
            power = regexMatch.group(1)
            print("Power found {}".format(float(power)))
            postUdpate("energyHeatpumpTotal", power)
        if (response==b'!\r\n'):
            #print("Switching to {}".format(INITAL_BAUDRATE))
            ser.baudrate = INITAL_BAUDRATE
            time.sleep(0.3)
            return None

ser = serial.Serial(SERIALPORT, INITAL_BAUDRATE, serial.SEVENBITS, serial.PARITY_EVEN,serial.STOPBITS_ONE)

while True:
    p = multiprocessing.Process(target=startQueryLoop)
    p.start()

    # Wait for 10 seconds or until process finishes
    p.join(10)

    # If thread is still active
    if p.is_alive():
        print("running... let's kill it...")
        # Terminate
        p.terminate()
        p.join()

It appears as if there is an occasional glitch in the communication that breaks the process.

Hi,

did you get the Logarex to work with openhab?

I use the same setup as yours and do also got problems with timeout.

The short answer is, that I didn’t get either one to work with the included bindings. So I am using python scripts which post to the REST API. They work very well. Here are my both scripts:

# -*- coding: ISO-8859-1 -*-

import serial
import time
import faulthandler, signal, os, traceback
from datetime import datetime
import re
from urllib import request, parse
import multiprocessing

SERIALPORT = "/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_AH0694UP-if00-port0"
INITAL_BAUDRATE = 300

def postUdpate(item, value):
    req =  request.Request("http://localhost:8080/rest/items/"+item+"/state", data=str(value).encode('utf-8'))
    req.add_header('Content-Type', 'text/plain')
    req.get_method = lambda: 'PUT'
    resp = request.urlopen(req)
    if resp.status!=202 :
        print("Response was %s %s" % (resp.status, resp.reason))

def startQuery():
    ser.baudrate = INITAL_BAUDRATE
    if (ser.in_waiting != 0): #ensure we are not reading garbage and the buffer is empty
        ser.read(ser.in_waiting)
    time.sleep(0.3)
    sendtxta = "/?!\r\n"
    ser.write(sendtxta.encode())
    ser.flush()
    response=ser.readline()
    #print(response) #this is the echo
    response=ser.readline()
    #print(response)
    sendtxta = "\x06040\r\n"
    ser.write(sendtxta.encode())
    ser.flush()
    time.sleep(0.3)
    ser.baudrate = 4800
    #print("Switching to {}".format(ser.baudrate))

def usr1_handler(signum,frame):
    traceback.print_stack()


def startQueryLoop():
    signal.signal(signal.SIGUSR1,usr1_handler)
    startQuery()
    while True:
        response=ser.readline()
        #print(response)
        regexMatch = re.search('1.8.0\((.*)\*kWh\).*', response.decode("UTF-8"))
        if regexMatch:
            power = regexMatch.group(1)
            print(".", end='', flush=True)
            postUdpate("energyHeatpumpTotal", power)
        if (response==b'!\r\n'):
            #print("Switching to {}".format(INITAL_BAUDRATE))
            ser.baudrate = INITAL_BAUDRATE
            time.sleep(0.3)
            return None

def usr1_handler(signum,frame):
    traceback.print_stack()

def usr1_handler_main(signum, frame):
    os.kill(p.pid, signal.SIGUSR1)

signal.signal(signal.SIGUSR1,usr1_handler_main)

ser = serial.Serial(SERIALPORT, INITAL_BAUDRATE, serial.SEVENBITS, serial.PARITY_EVEN,serial.STOPBITS_ONE)
p=None

while True:
    p = multiprocessing.Process(target=startQueryLoop)
    p.start()

    # Wait for 10 seconds or until process finishes
    p.join(10)

    # If thread is still active
    if p.is_alive():
        print("\n{} Timeout, restart of process".format(datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
        # Terminate
        p.terminate()
        p.join()

This is for the Logarex:

# -*- coding: ISO-8859-1 -*-

import serial
import time
import faulthandler, signal, os, traceback
from datetime import datetime
import re
from urllib import request, parse
import multiprocessing

SERIALPORT = "/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_AH0694V2-if00-port0"
INITAL_BAUDRATE = 9600

def postUdpate(item, value):
    req =  request.Request("http://localhost:8080/rest/items/"+item+"/state", data=str(value).encode('utf-8'))
    req.add_header('Content-Type', 'text/plain')
    req.get_method = lambda: 'PUT'
    resp = request.urlopen(req)
    if resp.status!=202 :
        print("Response was %s %s" % (resp.status, resp.reason))

def usr1_handler(signum,frame):
    traceback.print_stack()


def startQueryLoop():
    signal.signal(signal.SIGUSR1,usr1_handler)
    while True:
        try:
          response=ser.readline()
          #print(response.decode("UTF-8"))
          regexMatch = re.search('1-0:1.8.0\*255\((.*)\*kWh\).*', response.decode("UTF-8"))
          if regexMatch:
              power = regexMatch.group(1)
              #print("Power: {}".format(float(power)))
              print(".", end='', flush=True)
              postUdpate("energyHouseholdTotal", power)
        except Exception as e:
          print("An exception occurred")
          time.sleep(10)

ser = serial.Serial(SERIALPORT, INITAL_BAUDRATE, serial.SEVENBITS, serial.PARITY_EVEN,serial.STOPBITS_ONE)
startQueryLoop()

With those items

Group gEnergy "Energy"

Number:Energy energyHouseholdTotal    "Haushaltsstrom Gesamt [%.4f kWh]"     <consumption>    (gEnergy)
Number:Energy energyHeatpumpTotal    "Wärmestrom Gesamt [%.4f kWh]"     <consumption>    (gEnergy)

The killing and respawning of a process is quite compute intensive. But I noticed that the EMH occasionally crashes! And as the serial port API does not appear to have a timeout, I am using processes… Not good, but at least it works.

hi ,
have the same issue.
i do have a lands Gyr E350 meter with volkszähler IR reader.

It was running with the old iec binding in openhab 1. I am the author of that binding.
I was not using openhab for a while and now decided to try again and saw that there is a smartmeter binding that includes the new version of openmuc.
I failed 2017 to migrate the iec binding to the new version of the openmuc.

I set up a IDE and are now able to debug the openmuc library used in the binding.
My meter was always recognized in wrong mode and acknowledge message were missing to get communication running.

if there is somebody in this forum having similar issues i could share my new updated library for openmuc for testing

That reminds me of the observation I made with regards to the Logarex. It does not use 7E1 but 8n1. That is why the lower layer of the Java API is dropping bytes, which causes the upper layer to fail on detection.
So I wrote myself a Homie Convention MQTT Adapter that I will publish soon.

Karsten

i guess we maybe also would find a way to make this setting a parameter in the existing binding instead.
the openmuc today has this hard coded but the data classes are prepared to make serial connection initialization with different settings.
In case you like to get a opemuc jar with your setting for test purpose i could easily create this

In the meantime i was able to also update the smart meter bundle to use the updated openmuc library.
i could also create a jar file with your serial settings.

Hello @kreutzer_peter, today I got a new Logarex smartmeter from my local provider Bayernwerk. I tried the smartmeter binding, and I experienced the same problem with the timeout. Using cat works fine:

> cat /dev/ttyUSB0 
/LOG5LK13BEXXXXXX

1-0:96.1.0*255(001LOG0XXXXXXXXX)
1-0:1.8.0*255(000000.1009*kWh)
1-0:2.8.0*255(000003.2680*kWh)
1-0:0.2.0*255(ver.03,432F,20170504)
1-0:96.90.2*255(0F66)
1-0:97.97.0*255(00000000)
!
...

I’m currently running the CentOS 7 RPM version of OpenHAB 2, so it pulls the bindings automatically. Do you have your running JAR version of the smartmeter binding available for download somewhere?

Regards, Christian

here the version that runs successfully with my landis gyr E350 and IR reader head from volkzaehler
-> link
good luck

Did you succeed in getting data?
If not what is shown in debug log

I am facing the same problem with a Logarex LK13BE and smartmeter binding in OpenHAB 3.0.2. I am quite new to openHAB, trying to see if I can track some data from my photovoltaics vs. power consumption. I use an optical reader from Weidmann Electronics.

It works well with ‘cat /dev/ttyUSB0’ but when I create a thing with default settings (and also trying with diferent settings) in openHAB it does not work (“The source did not signal an event for 40000 milliseconds and has been terminated.”). As this thread is a bit older: Did your changes go into current versions of the smartmeter binding? Or could you share the changes you made to the code, maybe even start a Pull Request?

Hi Dirk,

I’m also owning a Logarex smartmeter. And I also had problems to get the actual smartmeter binding working. In the past I had this configuration running:

smartmeter:meter:Hausanschluss     [port="/dev/ttyUSB0", refresh=20, mode="D", baudrate=9600] {
    Channels:
        Type 1-0_1-8-0 : 1-0_1-8-0
        Type 1-0_16-7-0 : 1-0_16-7-0 [
            negate="1-0_1-8-0:5:1:status"
        ]
}

A special remark to mode=“D” and baudrate=9600. I double checked this settings by using minicom program. Maybe this will help. But after updating my system to openhab 3.0.2 this binding is not working anymore

Thanks Julian. Looks similar to

http://mein-smarthome.org/blog/2019-06-13_smartmeter

So it seems that this binding is currently broken for our smartmeter.:-/ Unfortunately I am lacking the skills to debug this in Java…

Any process in this topic?
Is it possible to revert all changes in smartmeter addon to a version from january 2021?

Is there anyone able to generate a .jar file from this revision?
After this date, there were some changes inside this addon - I think this will cause our problems.

Any update on this? Still desperately trying to get my Logarex meter to work with the Smartmeter Binding whereas cat /dev/ttyUSB0 works perfectly… :frowning:
Running OpenHAB 3.1.0

The latest changes fixed an issue I was having where the meter (Landy&Gyr) was sending OBIS codes containing special characters like &.
This now works.
So I would not be happy if there will be a simple revert to a January version.
I am using ABC mode.

if you configure without setting up any channel, does the binding create the channels for you automatically (as it does for me) ?

Hi,
iam in trouble with this binding.
Openhab 3.2 on RPI3
I try to read my Itron ACE3000 Type 260.
For reading i have to send a initMessage
In ASCII “/?!”
or in HEX “2F3F210D0A”
To send this string i acctualy using “cutecom” and my ACE3000 sends a response like:
/ACE0\3k260V01.18
F.F(00)
C.1(1234567890123456)
C.5.0(00)
1.8.0(000285.4kWh)
2.8.0(000120.1
kWh)

When i use the Binding
config:
UID: smartmeter:meter:e868cefbff
label: Smart Meter
thingTypeUID: smartmeter:meter
configuration:
mode: ABC
baudrate: “300.0”
stopbit: 1
port: /dev/ttyUSB0
databit: 7
parity: EVEN
refresh: 30
conformity: NONE
initMessage: 2F3F210D0A
baudrateChangeDelay: 0

i got first:
HANDLER_CONFIGURATION_PENDING
Waiting for messages from device

and after one minute
COMMUNICATION_ERROR
The source did not signal an event for 60000 milliseconds and has been terminated.

can someone help me what iam doing wrong?

Hi @Zottel, have your problems be solved? I’m about to buy an optical reader from Weidmann Electronics as well but am unsure if I can read the data with the SmartMeter Binding.

Sorry, I gave up on this. I have no Java knowledge and it seems that noone else stepped in so far to fix this problem at least for this piece of hardware.