Hi guys, I am a little bit frustrated right now, but let me explain!
at first: If this thread is in the wrong chapter, please move it to the correct one!
I am able to receive data through serial port from sensor, this is working!
Now I want to extract the values from this string via templating.
What I have:
sensor:
- platform: serial
serial_port: /dev/ttyUSB0
name: smartmeter_data
baudrate: 9600
bytesize: 7
parity: E
stopbits: 1 - platform: template
sensors:
smartmeter_total:
unit_of_measurement: “kWh”
value_template: >
{% if states(‘sensor.smartmeter_data’)|regex_search(“1-0:1.8.0255") %}
{{ states(‘sensor.smartmeter_data’)|regex_findall_index("((\d.\d*))”) | float }}
{% else %}
{{ ‘sensor.smartmeter_data’ }}
{% endif %}
The received string is looking like that:
1-0:0.0.0255(hidden_serialnumber)
1-0:96.1.0255(hidden_serialnumber)
1-0:1.8.0255(000021kWh)
1-0:2.8.0255(000004kWh)
1-0:96.5.0255(001C0104)
0-0:96.8.0255(0002DC73)
The result on the dashboard is “unknown” for “smartmeter_total”
What I am doing wrong?
Thanks for your help in advance!