From 98384791451ef71cd51d9743fcdc5f351a50c2bb Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Thu, 8 Feb 2024 11:22:13 +0000 Subject: [PATCH] 10_ZWave.pm: better parameter parsing for METER get (Forum #136912) git-svn-id: https://svn.fhem.de/fhem/trunk@28490 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/10_ZWave.pm | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/fhem/FHEM/10_ZWave.pm b/fhem/FHEM/10_ZWave.pm index a327fcb68..064d1d5e0 100644 --- a/fhem/FHEM/10_ZWave.pm +++ b/fhem/FHEM/10_ZWave.pm @@ -1925,16 +1925,31 @@ ZWave_meterSet($$) sub ZWave_meterGet($) { - my ($scale) = @_; + my ($scale, $exp) = split(" ", $_[0]); if ($scale eq "%s") { # no parameter specified, use V1 get without scale return("", "01"); }; - if($scale < 7) { - return ("",sprintf('01%02x', $scale << 3)); + if($scale !~ m/^[0-9]+/) { + my $scaleAsInt; + foreach my $arr (values %zwm_unit) { + for(my $i1=0; $i1<@{$arr}; $i1++) { + $scaleAsInt = $i1 if($arr->[$i1] eq $scale); + } + } + return "unknown unit $scale" if(!defined($scaleAsInt)); + $scale = $scaleAsInt; + } + + return "invalid parameter $exp, only import or export is allowed" + if($exp && $exp !~ m/^(export|import)$/); + $exp = ($exp ? ($exp eq "export" ? 0x80 : 0x40) : 0); + + if($scale < 7) { # V1:no scale, V2:2 bits, V3: 3bits + return ("",sprintf('01%02x', ($scale << 3) | $exp)); } else { # Version 4 - return ("",sprintf('01%02x%02x', 7<<3, $scale-8)); + return ("",sprintf('01%02x%02x', (7<<3) | $exp, $scale-7)); } } @@ -7125,18 +7140,14 @@ ZWave_tmSet($)

Class METER -
  • meter scale
    +
  • meter [scale [export|import]]
    return the meter report for the requested scale.
    Note: protocol V1 does not support the scale parameter, the parameter will be ignored and the default scale will be returned.
    - For protocol V2 and higher, scale is supported and depends on the - type of the meter (energy, gas or water).
    - The device may not support all scales, see the meterSupported - command and its output. If the scale parameter is omitted, the - default unit will be reported.
    - Example: For an electric meter, meter 0 will report energy in kWh, - meter 2 will report power in W and meter 6 will report current in A - (if these scales are supported).
    + For protocol V2 and higher scale can be specified as integer or text, see + the output ot the meterSupported command.
    + If the scale parameter is omitted, the default unit will be reported. + export/import is only valid for protocol V4 or higher.
  • meterSupported
    request the type of the meter, the supported scales and the