From d7f5239e1b302510c59703ef8ee1b3e36fde6ac8 Mon Sep 17 00:00:00 2001 From: klausw <> Date: Tue, 20 Feb 2018 20:52:53 +0000 Subject: [PATCH] 53_GHoma: energy to kWh git-svn-id: https://svn.fhem.de/fhem/trunk@16234 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 2 ++ fhem/FHEM/53_GHoma.pm | 27 +++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 1065d0015..0af0aa421 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,7 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - change: 53_GHoma: plugs with energy measurement implemented + reading energy now in kWh / SetExtensions / DbLog_splitFn - change: 93_DbRep: commandref revised - change: 93_DbLog: V3.8.5, Parse Event for Zwave changed - feature: 00_MQTT: new attribute "client-id" diff --git a/fhem/FHEM/53_GHoma.pm b/fhem/FHEM/53_GHoma.pm index 367c55566..db5b05a96 100644 --- a/fhem/FHEM/53_GHoma.pm +++ b/fhem/FHEM/53_GHoma.pm @@ -105,9 +105,10 @@ sub GHoma_Initialize($) { # $hash->{AttrFn} = "GHoma_Attr"; $hash->{StateFn} = "GHoma_State"; $hash->{AttrList} = "restoreOnStartup:last,on,off restoreOnReinit:last,on,off blocklocal:yes,no ". - "allowfrom connectTimeout connectInterval"; + "allowfrom connectTimeout connectInterval $readingFnAttributes"; $hash->{noAutocreatedFilelog} = 1; # kein Filelog bei Autocreate anlegen - $hash->{ShutdownFn} = "GHoma_Shutdown"; + $hash->{ShutdownFn} = "GHoma_Shutdown"; + $hash->{DbLog_splitFn} = "GHoma_DbLog_splitFn"; } ##################################### sub GHoma_ClientConnect($) { # im Mom unnuetz @@ -376,7 +377,7 @@ sub GHoma_Read($) { # wird von der globalen loop aufgerufen (ueber $hash->{F my $value=$values{unpack('H*',substr($_,19,1))}; if (defined($value)) { my ($high,$mid,$low)=unpack('CCC',substr($_,21,3)); - readingsBulkUpdate($hash, $value, ($high*65536+$mid*256+$low)/100); + readingsBulkUpdate($hash, $value, ($high*65536+$mid*256+$low)/($value eq 'energy' ? 1000 : 100)); } else { # readingsBulkUpdate($hash, 'message_'.unpack('H*',substr($_,19,1)), unpack('H*',substr($_,20))); Log3 $name, 3, "$name unknown control message Id: " . unpack('H*',substr($_,19,1)) . " value: " . unpack('H*',substr($_,20)); @@ -503,6 +504,24 @@ sub GHoma_udpbroad { } +sub GHoma_DbLog_splitFn($) { # Einheiten + my ($event) = @_; + Log3 undef, 5, "in DbLog_splitFn empfangen: $event"; + my ($reading, $value, $unit) = ""; + + my @parts = split(/ /,$event); + $reading = shift @parts; + $reading =~ tr/://d; + $value = $parts[0]; + $unit = "W" if(lc($reading) =~ m/power/); + $unit = "kWh" if(lc($reading) =~ m/energy/); + $unit = "V" if(lc($reading) =~ m/voltage/); + $unit = "A" if(lc($reading) =~ m/current/); + $unit = "Hz" if(lc($reading) =~ m/frequency/); + $unit = "W" if(lc($reading) =~ m/maxpower/); + return ($reading, $value, $unit); +} + 1; =pod @@ -695,4 +714,4 @@ sub GHoma_udpbroad { =end html_DE -=cut +=cut \ No newline at end of file