Integrating a Siemens Ultrasonic heat and cooling energy meter UH50 into OpenHAB 2 using MQTT

We use in our house a pellet heater and solar energy. As a secondary heating system we used up to now a long-distance heating which was provided by the Stadtwerke München (SWM). The energy for that long-distance heating is generated by SWMusing  garbage incineration plant.

Our community Unterföhring has successfully build a geothermal power plant. To switch our energy consumption totally to regenerative energies we decided to switch our energy supply to leverage the geothermal energy.

The transfer station from our new provider GeoVol is using a Siemens Ultrasonic heat and cooling energy meter (UH50) to measure our energy consumption. The UH50 is equipped with an optical interface which is supporting metering data exchange which is similar to the IEC 62056 standard.

Connecting a linux system to the UH50 smart meter

To access the data of the energy meter we will need a system running linux with python and an IR head which can be connected via RS232. I used the following IR head which includes a RS232 to USB converter:

Stromzähler, Smart Meter IR (Infrarot) Schreib / Lesekopf USB (Optokopf)

A raspberry pi 2 can then easily connected via the USB port to the sensor.

pi@raspberrypi:~ $ lsusb
Bus 001 Device 004: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus 001 Device 005: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. LAN9500 Ethernet 10/100 Adapter / SMSC9512/9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

In my example the sensor is connected via the device 005 on bus 001.

Read out the data from the UH50 smart meter

Stefan Sedelmaier has created a python script to read the UH50 out which can downloaded here.

The script starts to communicate with the smart meter using 300 baud. The UH50 will send respond with an ID telegram. The rest of the data part of the response telegram will then be transmitted with an increased speed, which is specific to your UH50. I will show how to determine the correct baudrate in the following:

After installing python and pyserial (sudo pip install pyserial) the script produces the following output:

pi@raspberrypi:~ $ ./uh50.py 

/LUGCUH50

6.8(0000062*kWh)6.26(00001.96*m3)9.21(68680080)
6.26*01(00000.00*m3)6.8*01(0000000*kWh)
F(0)9.20(68680080)6.35(60*m)
6.6(0010.0*kW)6.6*01(0000.0*kW)6.33(000.300*m3ph)9.4(149.3*C&083.3*C)
6.31(0000056*h)6.32(0000000*h)9.22(R)9.6(000&68680080&0&000&68680080&0)
9.7(20000)6.32*01(0000000*h)6.36(01-01&00:00)6.33*01(000.000*m3ph)
6.8.1()6.8.2()6.8.3()6.8.4()6.8.5()
6.8.1*01()6.8.2*01()6.8.3*01()
6.8.4*01()6.8.5*01()
9.4*01(000.0*C&000.0*C)
6.36.1(2016-04-02)6.36.1*01(2000-00-00)
6.36.2(2016-04-02)6.36.2*01(2000-00-00)
6.36.3(2016-04-01)6.36.3*01(2000-00-00)
6.36.4(2016-04-01)6.36.4*01(2000-00-00)
6.36.5()6.36*02(01&00:00)9.36(2016-04-04&04:14:43)9.24(1.5*m3ph)
9.17(0)9.18()9.19()9.25()
9.1(0&1&0&1700&CECV&CECV&1&5.22&5.22&F&081008&041>04&08&0&00&:5&00&20)
9.2(&&)9.29()9.31(0000003*h)
9.0.1(00000000)9.0.2(00000000)9.34.1(000.00000*m3)9.34.2(000.00000*m3)
8.26.1(00000000*m3)8.26.2(00000000*m3)
8.26.1*01(00000000*m3)8.26.2*01(00000000*m3)
6.26.1()6.26.4()6.26.5()
6.26.1*01()6.26.4*01()6.26.5*01()0.0(68680080)
!

If your output is scrambled and looks like the following:

pi@raspberrypi:~ $ ./uh50.py 

/LUGCUH50

@xx~@CGCCGxGf~~s~fxxgxCCGCOxx<xLsf~fx|COOx~<x@~xx@~xCsf`xxgxfGgCCGGCxCCff~fxx~DsCgGCCCCCf~~s~ff`xpCfxxgGx~<x@~xx@~xCsxxfxGff~ff`xxxCGGCxCf~~sfxxxfCgCCGxCf~~sfxxCCGxCCff~~fx|C`gg`gx|CfpxLC~x|Cfpff`xxgCGCCCfxf~fxxgGCCCCCCf~fx|Cggqfx|CxCGGxLx~<x~xx@~x<sGxLGGCxdx~<x@~xx@~x<sCff`x|C~ggCCCCfxxgfCgGGCCCCf~fxxxGGfCOxLCCxxxCsxxfGOCCGxCCCff~~ff`xx~xgfxx~|Cgfxx~|Cfxx~|C`gfxx~|Cfff`xx~|COfOfxx~|COfCOfxx~|CfGOff`xx~|C`gfCgfxx~|CffCgff`x|C`OfCOGGxCfpxLCCCxfpff`xxxxOgGgxfG`OfOfxxxxOfGOGCGCfCCfGCff`xxxxGGCgxfG`OfGOfxxxxgfCgOGGGfCGfCGff`xxxxOCgxfC`gfOfxxxxfCggCGCfGGfCCff`xxxx`OOGOxf`gfGOfxxxx`gfGOOCCCfGGfCCff`xxxxffxxxfGGgxDCCxxxAsx|CxOOxfG`gfG`OxDC`gx~~Lx~~Csx|Cg`ggxfff~~ff`x|Cg~gGfx|Cg~@Cfx|CGxfx|COfff`x|CGxLOxLxLO~gCCxdpfppxxDpfppxxdOxLfxggxdfxGgxdxpxLG~~xx@~<sG`GGx~x0~<sC~<sGxLGGxLxfxdCCxLOff`x|CgxLxdfx|COx@CfxxgGCCCGCf~ff`x|CGxOCCCGCGfx|CGxgCCCGCCCGfx|C`GxOCCGxCCGGCff~fx|C`gxgCCCxCCCCGff~ff`~|COxxOCGGCCCff~f~|CgxxgCGGCCCGCff~ff`~|CgxxgfCGGGCGCCGCff~f~|COxxgfCgGGCCCCff~ff`xxgxxgfxxOxx`Ofxxgxxfff`xxOxxgfCgfxxgxx`gfGOfxxOxxffGO

you have to adjust the baudrate in line following line:

ser.baudrate=2400

The nice thing is that you even do not have to guess the baudrate you have to use. The 5th character of the ID telegram (“/LUGxUH50”) found in the first line of the output corresponds to the code for the increased baudrate:

C: 2400 baud
D: 4800 baud
E: 9600 baud
F: 19200 baud

As you can see in the output in case of my smart meter I have to use 2400 baud.

Interpretation of the UH50 smart meter data

I did not find any official information about the data telegram. You can compare the values reported by the script with the values you can read on the UH50 itself.

You can find here a list of identified parameters. I found the following parameters interesting:

6.6  - Power Max (kW)
6.8  - Quantity of Heat consumed (kwh)
6.26 - Volume (m3)e
6.31 - Operating Hours (hour)
6.33 - Flowrate max (m3/h) 
9.4  - Flow Temperature Max / Return Temperature Max (Celcius)
9.24 - Measuring Range (m3/h)

In the following I will show how to extract the values of the parameters and how to publish them via mqtt.

Publish the data to MQTT

The following script will publish the data from the UH50 smart meter:

pi@raspberrypi:~ $ cat /home/pi/readout_uh50.sh 

#!/bin/bash
MQTT_USER="MYUSER"
MQTT_PASSWORD="MYPASSWORD"
MQTT_CAPATH="/etc/ssl/certs/"
MQTT_HOST="YOUR_MQTT_SERVER"
MQTT_PORT="8883"
MQTT="/usr/bin/mosquitto_pub -h $MQTT_HOST -p $MQTT_PORT -u $MQTT_USER -P $MQTT_PASSWORD --capath $MQTT_CAPATH "

for LINE in $(/home/pi/uh50.py); do
# echo $LINE
if [[ $(echo $LINE | grep "6.8(") != "" ]]; then
HeatConsumed=$(echo $LINE | awk -F"6.8\(" '{print $2}' | awk -F"\)" '{print $1}' | awk -F"\*" '{print $1}' )
Metrik=$(echo $LINE | awk -F"6.8\(" '{print $2}' | awk -F"\)" '{print $1}' | awk -F"\*" '{print $2}' )

if [[ "$Metrik" == "kWh" ]]; then
$MQTT -t "UH50/HeatConsumed" -m "$HeatConsumed"
fi
fi

if [[ $(echo $LINE | grep "6.26(") != "" ]]; then
FlowVolume=$(echo $LINE | awk -F"6.26\(" '{print $2}' | awk -F"\)" '{print $1}' | awk -F"\*" '{print $1}' )
Metrik=$(echo $LINE | awk -F"6.26\(" '{print $2}' | awk -F"\)" '{print $1}' | awk -F"\*" '{print $2}' )
if [[ "$Metrik" == "m3" ]]; then
$MQTT -t "UH50/FlowVolume" -m "$FlowVolume"
fi
fi

if [[ $(echo $LINE | grep "6.6(") != "" ]]; then
PowerMax=$(echo $LINE | awk -F"6.6\(" '{print $2}' | awk -F"\)" '{print $1}' | awk -F"\*" '{print $1}' )
Metrik=$(echo $LINE | awk -F"6.6\(" '{print $2}' | awk -F"\)" '{print $1}' | awk -F"\*" '{print $2}' )
if [[ "$Metrik" == "kW" ]]; then
$MQTT -t "UH50/PowerMax" -m "$PowerMax"
fi
fi

if [[ $(echo $LINE | grep "6.33(") != "" ]]; then
FlowrateMax=$(echo $LINE | awk -F"6.33\(" '{print $2}' | awk -F"\)" '{print $1}' | awk -F"\*" '{print $1}')
Metrik=$(echo $LINE | awk -F"6.33\(" '{print $2}' | awk -F"\)" '{print $1}' | awk -F"\*" '{print $2}' )
if [[ "$Metrik" == "m3ph" ]]; then
$MQTT -t "UH50/FlowrateMax" -m "$FlowrateMax"
fi
fi

if [[ $(echo $LINE | grep "9.4(") != "" ]]; then
FlowlineTempMax=$(echo $LINE | awk -F"9.4\(" '{print $2}' | awk -F"\)" '{print $1}' | awk -F"\&" '{print $1}' | awk -F"\*" '{print $1}' )
RefluxTempMax=$(echo $LINE | awk -F"9.4\(" '{print $2}' | awk -F"\)" '{print $1}' | awk -F"\&" '{print $2}' | awk -F"\*" '{print $1}' )
Metrik=$(echo $LINE | awk -F"9.4\(" '{print $2}' | awk -F"\)" '{print $1}' | awk -F"\&" '{print $1}' | awk -F"\*" '{print $2}' )
if [[ "$Metrik" == "C" ]]; then
$MQTT -t "UH50/FlowlineTempMax" -m "$FlowlineTempMax"
$MQTT -t "UH50/RefluxTempMax" -m "$RefluxTempMax"
fi
fi

if [[ $(echo $LINE | grep "6.31(") != "" ]]; then
OperatingHours=$(echo $LINE | awk -F"6.31\(" '{print $2}' | awk -F"\)" '{print $1}' | awk -F"\*" '{print $1}' )
Metrik=$(echo $LINE | awk -F"6.31\(" '{print $2}' | awk -F"\)" '{print $1}' | awk -F"\*" '{print $2}' )
if [[ "$Metrik" == "h" ]]; then
$MQTT -t "UH50/OperatingHours" -m "$OperatingHours"
fi
fi

if [[ $(echo $LINE | grep "9.31(") != "" ]]; then
FlowHours=$(echo $LINE | awk -F"9.31\(" '{print $2}' | awk -F"\)" '{print $1}' | awk -F"\*" '{print $1}' )
Metrik=$(echo $LINE | awk -F"9.31\(" '{print $2}' | awk -F"\)" '{print $1}' | awk -F"\*" '{print $2}' )
if [[ "$Metrik" == "h" ]]; then
$MQTT -t "UH50/FlowHours" -m "$FlowHours"
fi
fi

if [[ $(echo $LINE | grep "9.24(") != "" ]]; then
MeasuringRange=$(echo $LINE | awk -F"9.24\(" '{print $2}' | awk -F"\)" '{print $1}' | awk -F"\*" '{print $1}' )
Metrik=$(echo $LINE | awk -F"9.24\(" '{print $2}' | awk -F"\)" '{print $1}' | awk -F"\*" '{print $2}' )
if [[ "$Metrik" == "m3ph" ]]; then
$MQTT -t "UH50/MeasuringRange" -m "$MeasuringRange"
fi
fi

done

exit 0

OpenHAB2 Entries

UH50.items

Number UH50_Waermemenge     "Wärmemenge  [%.1f kWh]"        (UH50)  {mqtt="<[mosquitto:UH50/HeatConsumed:state:default]"}
Number UH50_FlowVolume     "Volumen  [%.1f m^3]"         (UH50)  {mqtt="<[mosquitto:UH50/FlowVolume:state:default]"}
Number UH50_PowerMax     "Max Leistung  [%.1f kW]"       (UH50)  {mqtt="<[mosquitto:UH50/PowerMax:state:default]"}
Number UH50_MaxDurchfluss   "Max Durchfluss  [%.1f m^3/h]"  (UH50)  {mqtt="<[mosquitto:UH50/FlowrateMax:state:default]"}
Number UH50_MaxVorlauf     "Max Vorlauf  [%.1f °C]"        (UH50)  {mqtt="<[mosquitto:UH50/FlowlineTempMax:state:default]"}
Number UH50_MaxRuecklauf    "Max Rücklauf  [%.1f °C]"       (UH50)  {mqtt="<[mosquitto:UH50/RefluxTempMax:state:default]"}
Number UH50_Betriebsstunden "Betriebsstunden  [%.1f h]"     (UH50)  {mqtt="<[mosquitto:UH50/OperatingHours:state:default]"}
Number UH50_Messbereich     "Messbereich  [%.1f m^3/h]"     (UH50)  {mqtt="<[mosquitto:UH50/MeasuringRange:state:default]"}
Number UH50_FlowStunden     "Flow Stunden  [%.1f h]" (UH50)  {mqtt="<[mosquitto:UH50/FlowHours:state:default]"}

Sitemaps:

Group item=UH50_Waermemenge_Heute label="W<C3><A4>rmeeinspeisung heute" icon="status" {
  Frame label="Geovol UH50" { 
       Text item=UH50_Waermemenge 
       Text item=UH50_FlowVolume 
       Text item=UH50_PowerMax 
       Text item=UH50_MaxDurchfluss 
       Text item=UH50_MaxVorlauf 
       Text item=UH50_MaxRuecklauf 
       Text item=UH50_Betriebsstunden
       Text item=UH50_Messbereich 
       Text item=UH50_FlowStunden 
    }
 }

 


   	

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.