Hi,
I am receiving serial data from a Electricity meter (Landis & Gyr) via a direct serial link on my Rpi 3B+ running Home assistant 2021-08-06 on Hass OS 6.2. It took some effort to get the serial port to work, but serial data is arriving in the serial sensor.
sensor:
- platform: serial
name: Energy meter
serial_port: /dev/ttyAMA0
baudrate: 115200
bytesize: 8
parity: N
From the log file:
2021-08-13 21:32:12 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: /XMX5LGBBFG1012664304
2021-08-13 21:32:12 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received:
2021-08-13 21:32:12 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 1-3:0.2.8(42)
2021-08-13 21:32:12 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 0-0:1.0.0(210813213203S)
2021-08-13 21:32:12 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 0-0:96.1.1(4530303331303033373334343237393136)
2021-08-13 21:32:12 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 1-0:1.8.1(017386.714*kWh)
2021-08-13 21:32:12 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 1-0:1.8.2(016328.895*kWh)
2021-08-13 21:32:12 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 1-0:2.8.1(000000.000*kWh)
2021-08-13 21:32:12 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 1-0:2.8.2(000000.000*kWh)
2021-08-13 21:32:12 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 0-0:96.14.0(0001)
2021-08-13 21:32:12 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 1-0:1.7.0(00.507*kW)
2021-08-13 21:32:12 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 1-0:2.7.0(00.000*kW)
2021-08-13 21:32:13 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 0-0:96.7.21(00004)
2021-08-13 21:32:13 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 0-0:96.7.9(00002)
2021-08-13 21:32:13 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 1-0:99.97.0(2)(0-0:96.7.19)(180823090507S)(0000003479*s)(170212204313W)(0000000294*s)
2021-08-13 21:32:13 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 1-0:32.32.0(00000)
2021-08-13 21:32:13 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 1-0:32.36.0(00000)
2021-08-13 21:32:13 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 0-0:96.13.1()
2021-08-13 21:32:13 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 0-0:96.13.0()
2021-08-13 21:32:13 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 1-0:31.7.0(002*A)
2021-08-13 21:32:13 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 1-0:21.7.0(00.507*kW)
2021-08-13 21:32:13 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 1-0:22.7.0(00.000*kW)
2021-08-13 21:32:13 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 0-1:24.1.0(003)
2021-08-13 21:32:13 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 0-1:96.1.0(4730303331303033333738373439353136)
2021-08-13 21:32:13 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: 0-1:24.2.1(210813210000S)(15068.413*m3)
2021-08-13 21:32:13 DEBUG (MainThread) [homeassistant.components.serial.sensor] Received: !B906
The meter is sending a block of multiple lines (all terminated CR/LF) with electricity consumption data, every couple of seconds. I am (for now) only interested in a single line, that starts with 1-0:1.8.1.
The full line reads: 1-0:1.8.1(017386.714*kWh)
The rest of the lines should be discarded. Later I need to create more sensors to cater for some of the other data (6 lines out of 20).
I created a template sensor for that, which takes the serial sensor as input. Problem is that the value always seems to be empty (not undefined, but an empty string). I think that every line is evaluated and results in setting of the state. When I experiment in Developer tools / templates, it seems that a value flashes by. I am new to this Jinja syntax, so it would not be a surprise if the code is wrong.
Please advise. Many thanks in advance.
Template sensor definitition:
template:
- sensor:
- name: "Energy current use"
unit_of_measurement: "kWh"
state: >
{% if "1-0:1.8.1" in states('sensor.energy_meter') %}
{{ states('sensor.energy_meter').split("(")[1].split("*")[0] | float }}
{% endif %}