HTTPMOD - Regex to extract W value from kW/W value

Begonnen von Ed66, 06 Juni 2017, 14:18:33

Vorheriges Thema - Nächstes Thema

Ed66

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

DeeSPe

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
MAINTAINER: 22_HOMEMODE, 98_Hyperion, 98_FileLogConvert, 98_serviced

Als kleine Unterstützung für meine Programmierungen könnt ihr mir gerne einen Kaffee spendieren: https://buymeacoff.ee/DeeSPe

Ed66

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   



Univega06

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

erwin

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
FHEM aktuell auf RaspberryPI Mdl 1-4
Maintainer: 00_KNXIO.pm 10_KNX.pm
User: CUNO2 (868 SLOWRF) - HMS100xx, FS20, FHT, 1-Wire  - 2401(iButton), 18x20, 2406, 2413 (AVR), 2450,..,MQTT2, KNX, SONOFF, mySENSORS,....
Hardware:  Busware ROT, Weinzierl IP731, 1-Wire GW,...