Reading Tasmota power consumption by HTTP and REGEX

Hey there,

I have a couple of Tasmotas I try to read by an HTTP call like this:

http://192.168.xx.xx/?m=1

After this I get a result like this

{t}{s}Voltage{m}231 V{e}{s}Current{m}0.023 A{e}{s}Power{m}2 W{e}{s}Apparent Power{m}5 VA{e}{s}Reactive Power{m}5 VAr{e}{s}Power Factor{m}0.39{e}{s}Energy Today{m}0.015 kWh{e}{s}Energy Yesterday{m}0.000 kWh{e}{s}Energy Total{m}14.304 kWh{e}{t}ON

My problem is that my regex skills are beginner level. I try to extract the power value “2 W”.
I’ve tried it with this (works in regex101, but not in Openhab):

}Power{m}([0-9]{1,5})

So my final goal would be a String Item like this:

String Tasmota_CurrentConsumption “Consumption [%s W]” { http="<[http://192.168.1.1/?m=1:10000:REGEX((}Power{m}([0-9]{1,5})))]" }

Can someone tell me how to format the regex correctly that I only get “2” as a result in the string?

Thanks a lot!

PS: I’m running OH 2.5

REGEXs that are used in OH need to match the full string.
Try to prepend and append .*
.*}Power{m}([0-9]{1,5}).*

Hi,
unfortunatelly it doesn’t work… Openhab is giving me this error:

Error during the execution of rule ‘test’: Illegal repetition near index 8
^.}Power{m}([0-9]{1,5}).$

Seems he doesn’t like the string “Power”

I finally got it working with this:

String Tasmota_Consumption “Consumption [%s W]” { http="<[http://192.168.1.1/?m=1:10000:REGEX(.Power…(.)(?= W).*)]" }

Thanks for your help!

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.