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.
Not sure if you’re still trying to figure this out, but I came across this while trying to figure out how to do a regex inside a template and figured I would drop an answer.
Since there would be no matches where there are digits followed by a ) you would remove that escaped \) and just use \((\d*\.\d*). This worked for me in the template tester:
That’s no solution! You want to get digits and search for ‘(’ as ‘helper’ or startpoint ?
Normally that finds
00507.4541 and only because of the filter float you get the ‘right’ result. That’s no solution per se. (how many filters you wanna use in a more complicated scenario ?)
Use this instead:
{{ str|regex_findall_index("[\d]{3}\.[\d]{4}")}}
That finds a sequence which includes 3 digits + point + 4 digits