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
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
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
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
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