FHEM Forum

FHEM => English Corner => Thema gestartet von: Ed66 am 06 Juni 2017, 14:18:33

Titel: HTTPMOD - Regex to extract W value from kW/W value
Beitrag von: Ed66 am 06 Juni 2017, 14:18:33
Hi together,

I'm using HTTPMOD to successfully extract several values from my Enphase Envoy solarcontroller. I am struggling with the creating a "smart" regex to derive the actual production in a uniform way: it displays in W when the value <= 999 W and switches to kW when above: x.xx kW

The webpage source:

<td>Currently generating</td>    <td>   671 W</td></tr>
or alternatively:
<td>Currently generating</td>    <td>   1.72 kW</td></tr>


I would like to use a single regex/reading that always returns the Watts, I tried something with looking ahead and replacing but my knowledge does not suffice. I try to avoid using multiple regexes/readings to identify the W and kW separately.
This is what I basically started with:


<td>Currently generating</td>[^0-9]+([0-9\.]+.*W)


I hope you can push me a little in the right direction.

KR,
Edwin
Titel: Antw:HTTPMOD - Regex to extract W value from kW/W value
Beitrag von: DeeSPe am 06 Juni 2017, 14:53:46
Try if this may work for you:
generating<\/td>\s+<td>\s+(\d+)\sW

http://www.regextester.com/ could help you finding the proper regex.

Cheers
Dan
Titel: Antw:HTTPMOD - Regex to extract W value from kW/W value
Beitrag von: Ed66 am 06 Juni 2017, 17:55:27
Hi Dan,

my challenge is to conditionally (only when webpage reports in kW) translate the kilowatts into watts through a regex. In the example the 1.72 should translate into 1720, but only in case a kW is matched after the value/string 1.72

Rgds, Edwin   


Titel: Antw:HTTPMOD - Regex to extract W value from kW/W value
Beitrag von: Univega06 am 02 Januar 2023, 08:42:53
Hi Edwin,
I try to extract the Values from the Enphase Envoy. Is it possible to get your full definition? have you solved the problem with the kW/W?

Thanks
Kai
Titel: Antw:HTTPMOD - Regex to extract W value from kW/W value
Beitrag von: erwin am 02 Januar 2023, 09:40:44
Hi Kai,
try this:
my $str = ' 671.5 W</td>';
#$str = ' 1234.5 kW</td>';

$str =~ s/([\d\.]+)\s([k])?W.*/$2?$1*1000 . ' W':$1 . ' W'/e;

regards erwin