Hi everyone. I‘m trying to get data from a sensor and set it by using regex.
- platform: template
sensors:
smartmeter_total:
unit_of_measurement: "kWh"
value_template: >
{% if states('sensor.smartmeter_data')|regex_search("1-0:1\.8\.0\*255") %}
{{ states('sensor.smartmeter_data')|regex_findall_index("\((\d*\.\d*)\)") | float }}
{% else %}<sup>Text</sup>
{{ states('sensor.smartmeter_total') | float }}
{% endif %}
The if statement works fine. My issue is in the line of regex_findall_index
. It‘s not returning the value I expect. This is the raw output of the data: 1-0:1.8.0*
255(00507.4541*kWh)
I want 507.4541 to be written as the sensor state.
Can someone help me with the expression?
Thanks