[Patch] 24_TPLinkHS110.pm Addition of KP115 (UK Only)

Begonnen von kam, 20 August 2021, 22:45:06

Vorheriges Thema - Nächstes Thema

kam

I hope this is the correct place to add this but if not - forgive a newbie.

Description:

The KP115 is currently hardware version 1.0 but it reports it's realtime measurements in mA and mV etc. like version 2.0 and later of the HS110. The hardware map in TPLinkHS110.pm does not have existing entries for a hardware version of 1.0 that returns current_ma, voltage_mv, power_mw and total_wh so those have been added. An addition has also been made to see if something identifying itself as version 1.0 has reported 'energy' in which case it is treated as normal for calculation of total consumtion. If not it uses the calculation for hardware Version 2.0 or later using 'energy_wh'. 

The KP115(UK) has also been added were the model type is checked.

Note that ONLY the UK version has been added since I do not know what other regional variations report as their model designation.

error500

Hello,

i've got the KP115(EU) and as far as i can tell the measures are the same as on the HS110(EU).

How do we get this to work with fhem 24_TPLinkHS110 module?

Regards
Mark

Measures from KP115(EU)
{"emeter":{"get_realtime":{"voltage_mv":226944,"current_ma":138,"power_mw":30976,"total_wh":183,"err_code":0}}}

Measures from HS110(EU)
{"emeter":{"get_realtime":{"voltage_mv":227282,"current_ma":253,"power_mw":52891,"total_wh":38476,"err_code":0}}}

kam

Hi Mark,

What does it report as it's 'model' and 'hardware version'?

The UK version reports it model as "KP115(UK)" so to add that I did the following:

Where the code checks to see if the device supports realtime data, I added the "KP115(UK)" as a valid device model. Note that this is the 'model' name returned by the device.

Line 241 in the original .pm file should be:

if ($json->{'system'}->{'get_sysinfo'}->{'model'} eq "HS110(EU)" or $json->{'system'}->{'get_sysinfo'}->{'model'} eq "HS110(UK)") {


To make it easier to read I split the line before adding the KP115 and it now looks like this:

    if ($json->{'system'}->{'get_sysinfo'}->{'model'} eq "HS110(EU)"
        or $json->{'system'}->{'get_sysinfo'}->{'model'} eq "HS110(UK)"
        or $json->{'system'}->{'get_sysinfo'}->{'model'} eq "KP115(UK)") {  #KM


If the EU model is reported as 'KP115(EU)', change that line to:


   if ($json->{'system'}->{'get_sysinfo'}->{'model'} eq "HS110(EU)"
        or $json->{'system'}->{'get_sysinfo'}->{'model'} eq "KP115(EU)"
        or $json->{'system'}->{'get_sysinfo'}->{'model'} eq "HS110(UK)"
        or $json->{'system'}->{'get_sysinfo'}->{'model'} eq "KP115(UK)") {  #KM


(The #KM comments just let me know what changes are mine and should be stripped out of the distributed version.)

I then had to check what hardware version ('$hw_ver') the device was reporting and the units that it was reporting it's realtime data in. The $hw_ver and units are used to map the readings correctly. My TP115(UK) gave it's hw_ver as '1.0' but reported it's realtime data as 'energy_wh', 'power_mw' etc. but there was no mapping for a version 1.0 device which reported those units. I therefore had to add mapping for those values.


        $hwMap{'1.0'}{'emeter'}{'get_realtime'}{'current'}{'name'} = 'current';
        $hwMap{'1.0'}{'emeter'}{'get_realtime'}{'current'}{'factor'} = 1;
# The following are for the KP115(UK) which has a firmware version of 1.0 but reports it's readings
# in mA, mV, mW and Wh.
        $hwMap{'1.0'}{'emeter'}{'get_realtime'}{'current_ma'}{'name'} = 'current'; #KM
        $hwMap{'1.0'}{'emeter'}{'get_realtime'}{'current_ma'}{'factor'} = 0.001;   #KM
        $hwMap{'1.0'}{'emeter'}{'get_realtime'}{'power_mw'}{'name'} = 'power';     #KM
        $hwMap{'1.0'}{'emeter'}{'get_realtime'}{'power_mw'}{'factor'} = 0.001;     #KM
        $hwMap{'1.0'}{'emeter'}{'get_realtime'}{'total_wh'}{'name'} = 'total';     #KM
        $hwMap{'1.0'}{'emeter'}{'get_realtime'}{'total_wh'}{'factor'} = 1;         #KM
        $hwMap{'1.0'}{'emeter'}{'get_realtime'}{'voltage_mv'}{'name'} = 'voltage'; #KM
        $hwMap{'1.0'}{'emeter'}{'get_realtime'}{'voltage_mv'}{'factor'} = 0.001;   #KM



To select the correct map for a version 1.0 device depending on what units it uses to report it's readings I just changed line 306.


# If it's hw_ver 1.0 but it's reporting {'energy_mw'} and not {'energy'} then $key2->{'energy'} will be undefined
# and it's probably a KP115, in which case we need to treat it like later hardware versions.

#                 if ($hw_ver eq "1.0"){
                  if ( ($hw_ver eq "1.0") and (defined($key2->{'energy'})) ){ #KM


I attached a patch file to my original post for the maintainer to consider but I don't know if anyone is looking at it. If you have any questions or want a copy of my modified file, message me.