From 6abb5d52ce75ad5f358a3324044dec57f37d60ce Mon Sep 17 00:00:00 2001 From: Icinger <> Date: Thu, 23 Mar 2017 18:41:42 +0000 Subject: [PATCH] 47_OBIS: Added "get update" git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@13782 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- FHEM/47_OBIS.pm | 71 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 19 deletions(-) diff --git a/FHEM/47_OBIS.pm b/FHEM/47_OBIS.pm index e26f6559d..ee9997894 100644 --- a/FHEM/47_OBIS.pm +++ b/FHEM/47_OBIS.pm @@ -10,6 +10,7 @@ package main; use strict; use warnings; +use Unit; use Time::HiRes qw(gettimeofday usleep); use Scalar::Util qw(looks_like_number); use POSIX qw{strftime}; @@ -65,6 +66,18 @@ my %SML_specialities = ("TIME" => [qr{0.0.96.2.1 |129.129.199.130.3}x, ""], ); + my %devs= ( +# Name, Init-String, interval, 2ndInit + "none" => ["", -1, ""], + "Unknown" => ["", -1, ""], + "SML" => ["/?!".chr(13).chr(10), 600, ""], + "Ext" => ["", -1, ""], + "Standard" => ["", -1, ""], + "VSM102" => ["/?!".chr(13).chr(10), 600, chr(6)."050".chr(13).chr(10)], + "E110" => ["/?!".chr(13).chr(10), 600, chr(6)."050".chr(13).chr(10)], + "E350USB" => ["/?!".chr(13).chr(10), 600, chr(6)."050".chr(13).chr(10)], + ); + ##################################### sub OBIS_Initialize($) { @@ -76,11 +89,14 @@ sub OBIS_Initialize($) $hash->{ReadyFn} = "OBIS_Ready"; $hash->{DefFn} = "OBIS_Define"; $hash->{ParseFn} = "OBIS_Parse"; + $hash->{DbLog_splitFn} = "Unit_DbLog_split"; + # $hash->{SetFn} = "OBIS_Set"; + $hash->{GetFn} = "OBIS_Get"; $hash->{UndefFn} = "OBIS_Undef"; $hash->{AttrFn} = "OBIS_Attr"; - $hash->{AttrList}= "do_not_notify:1,0 interval offset_feed offset_energy IODev channels directions alignTime pollingMode:on,off unitReadings:on,off ignoreUnknown:on,off valueBracket:first,second,both ". + $hash->{AttrList}= "do_not_notify:1,0 interval offset_feed offset_energy IODev channels directions alignTime pollingMode:on,off unitReadings:on,off ignoreUnknown:on,off valueBracket:first,second,both desiredSpeed ". $readingFnAttributes; } @@ -134,24 +150,12 @@ sub OBIS_Define($$) } else {$baudrate=9600; $hash->{helper}{SPEED}="5";} - my %devs= ( -# Name, Init-String, interval, 2ndInit - "none" => ["", -1, ""], - "Unknown" => ["", -1, ""], - "SML" => ["", -1, ""], - "Ext" => ["", -1, ""], - "Standard" => ["", -1, ""], - "VSM102" => ["/?!".chr(13).chr(10), 600, chr(6)."0".$hash->{helper}{SPEED}."0".chr(13).chr(10)], - "E110" => ["/?!".chr(13).chr(10), 600, chr(6)."0".$hash->{helper}{SPEED}."0".chr(13).chr(10)], - "E350USB" => ["/?!".chr(13).chr(10), 600, chr(6)."0".$hash->{helper}{SPEED}."0".chr(13).chr(10)], - ); if (!$devs{$type}) {return 'unknown meterType. Must be one of , SML, Standard, VSM102, E110'}; + if ($devs{$type}[2] != "") {$devs{$type}[2]=chr(6)."0".$hash->{helper}{SPEED}."0".chr(13).chr(10);} $devs{$type}[1] = $hash->{helper}{DEVICES}[1] // $devs{$type}[1]; $hash->{helper}{DEVICES} =$devs{$type}; $hash->{helper}{TRIGGERTIME}=gettimeofday(); -# if( !$init_done ) { -# $attr{$name}{"event-on-change-reading"} = ".*"; - # } + my $t=OBIS_adjustAlign($hash,AttrVal($name,"alignTime",undef),$hash->{helper}{DEVICES}[1]); Log3 ($hash,5,"OBIS ($name) - Internal timer set to ".FmtDateTime($t)) if ($hash->{helper}{DEVICES}[1]>0); InternalTimer($t, "GetUpdate", $hash, 0) if ($hash->{helper}{DEVICES}[1]>0); @@ -185,9 +189,24 @@ sub OBIS_Set($@) } } + return; } +sub OBIS_Get($@) +{ + my ($hash, @a) = @_; + my $name = shift @a; + my $opt = shift @a; + + if ($opt eq "update") { + GetUpdate($hash); + } else + + {return "Unknown argument $opt, choose one of update";} + +} + # Update-Routine sub GetUpdate($) { @@ -473,6 +492,7 @@ sub OBIS_Parse($$) if (AttrVal($name,"ignoreUnknown","off") eq "off" || $L ne $channel) { readingsBulkUpdate($hash, $L,(looks_like_number($3) ? $3+0 : $3).(AttrVal($name,"unitReadings","off") eq "off"?"":" $4")); readingsBulkUpdate($hash, "dir_$L",$hash->{helper}{directions}{$2} // $dir{$2}) if (length $2); + $hash->{readingsDesc}{$L}{rtype}=$4; } } @@ -482,6 +502,7 @@ sub OBIS_Parse($$) if (AttrVal($name,"ignoreUnknown","off") eq "off" || $L ne $channel) { readingsBulkUpdate($hash, "$L",(looks_like_number($3) ? $3+0 : $3).(AttrVal($name,"unitReadings","off") eq "off"?"":" $4")); readingsBulkUpdate($hash, "dir_$L",$hash->{helper}{directions}{$2} // $dir{$2}) if (length $2); + $hash->{readingsDesc}{$L}{rtype}=$4; } } @@ -491,9 +512,11 @@ sub OBIS_Parse($$) my $chan=$3+0 > 0 ? "_Ch$3" : ""; if (AttrVal($name,"ignoreUnknown","off") eq "off" || $L ne $channel) { if($1==1) { - readingsBulkUpdate($hash, $L.$chan ,(looks_like_number($3) ? $5+0 : $5) +AttrVal($name,"offset_energy",0).(AttrVal($name,"unitReadings","off") eq "off"?"":" $6")); + readingsBulkUpdate($hash, $L.$chan ,(looks_like_number($3) ? $5+0 : $5) +AttrVal($name,"offset_energy",0).(AttrVal($name,"unitReadings","off") eq "off"?"":" $6")); + $hash->{readingsDesc}{$L.$chan}{rtype}=$6; } elsif ($1==2) { - readingsBulkUpdate($hash, $L.$chan ,(looks_like_number($3) ? $5+0 : $5) +AttrVal($name,"offset_feed",0).(AttrVal($name,"unitReadings","off") eq "off"?"":" $6")); + readingsBulkUpdate($hash, $L.$chan ,(looks_like_number($3) ? $5+0 : $5) +AttrVal($name,"offset_feed",0).(AttrVal($name,"unitReadings","off") eq "off"?"":" $6")); + $hash->{readingsDesc}{$L.$chan}{rtype}=$6; } readingsBulkUpdate($hash, "dir_$L",$hash->{helper}{directions}{$4} // $dir{$4}) if (length $4); } @@ -661,6 +684,16 @@ sub OBIS_Attr(@) } } + if ($aName eq "desiredSpeed") + { + if ($aVal ge 0 and $aVal le 9) + { + + } else + { + return "OBIS ($name): desiredSpeed - Value must be between 0 and 9"; + } + } } return undef; } @@ -807,7 +840,7 @@ sub OBIS_decodeTL($){
  • SML -> Smart Message Language

  • Example:
    - define myPowerMeter OBIS /dev/ttyPlugwise@@9600,7,E,1 VSM102 + define myPowerMeter OBIS /dev/ttyPlugwise@9600,7,E,1 VSM102

    @@ -872,7 +905,7 @@ sub OBIS_decodeTL($){
  • SML -> Smart Message Language

  • Beispiel:
    - define myPowerMeter OBIS /dev/ttyPlugwise@@9600,7,E,1 VSM102 + define myPowerMeter OBIS /dev/ttyPlugwise@9600,7,E,1 VSM102