47_OBIS.pm 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. ###############################################
  2. #
  3. # 47_OBIS.pm
  4. #
  5. # Thanks to matzefizi for letting me merge this with 70_SMLUSB.pm and for testing
  6. # Tanks to immi for testing and supporting help and tips
  7. #
  8. # $Id: 47_OBIS.pm 14235 2017-05-09 19:24:14Z Icinger $
  9. package main;
  10. use strict;
  11. use warnings;
  12. use Time::HiRes qw(gettimeofday usleep);
  13. use Scalar::Util qw(looks_like_number);
  14. use POSIX qw{strftime};
  15. my %OBIS_channels = ( "21" =>"power_L1",
  16. "41" =>"power_L2",
  17. "61" =>"power_L3",
  18. "12" =>"voltage_avg",
  19. "32" =>"voltage_L1",
  20. "52" =>"voltage_L2",
  21. "72" =>"voltage_L3",
  22. "11" =>"current_sum",
  23. "31" =>"current_L1",
  24. "51" =>"current_L2",
  25. "71" =>"current_L3",
  26. "1.8" =>"total_consumption",
  27. "2.8" =>"total_feed",
  28. "2" =>"feed_L1",
  29. "4" =>"feed_L2",
  30. "6" =>"feed_L3",
  31. "1" =>"power",
  32. "15" =>"power",
  33. "16" =>"power",
  34. "24" =>"Gas",
  35. );
  36. my %OBIS_codes = ( "Serial" => qr{^0-0:96.1.255(?:.\d+)?\((.*?)\).*},
  37. "Serial" => qr{^(?:1-0:)?0\.0\.[1-9]+(?:.\d+)?\((.*?)\).*},
  38. "Owner" => qr{^1.0.0.0.0(?:.\d+)?\((.*?)\).*}x,
  39. "Status" => qr{^1.0.96.5.5(?:.\d+)?\((.*?)\).*}x,
  40. "Powerdrops" => qr{^0.0.96.7.\d(?:.\d+)?\((.*?)\).*},
  41. "Time_param" => qr{^0.0.96.2.1(?:.\d+)?\((.*?)\).*},
  42. "Time_current" => qr{^0.0.1.0.0(?:.\d+)?\((.*?)\).*},
  43. "Channel_sum" => qr{^(?:1.0.)?(\d+).1.7(?:.0|.255)?(?:\(.*?\))?\((<|>)?([-+]?\d+\.?\d*)\*?(.*)\).*},
  44. "Channels" => qr{^(?:\d.0.)?(\d+).7\.\d+(?:.0|.255)?(?:\(.*?\))?\((<|>)?([-+]?\d+\.?\d*)\*?(.*)\).*},
  45. "Channels2" => qr{^(?:0.1.)?(\d+).2\.\d+(?:.0|.255)?(?:\(.*?\))?\((<|>)?(-?\d+\.?\d*)\*?(.*)\).*},
  46. "Counter" => qr{^(?:1.\d.)?(\d).(8)\.(\d)(?:.\d+)?(?:\(.*?\))?\((<|>)?(-?\d+\.?\d*)\*?(.*)\).*},
  47. "ManufID" => qr{^129-129:199\.130\.3(?:.\d+)?\((.*?)\).*},
  48. "PublicKey" => qr{^129-129:199\.130\.5(?:.\d+)?\((.*?)\).*},
  49. );
  50. my %SML_specialities = ("TIME" => [qr{0.0.96.2.1
  51. |0.0.1.0.0 }x, sub{return strftime("%d-%m-%Y %H:%M:%S", localtime(unpack("i", pack("I", hex(@_)))))}],
  52. "HEX2" => [qr{1-0:0\.0\.[0-9] }x, sub{my $a=shift;
  53. if ( $a =~ /^[0-9a-fA-F]+$/ ) {$a=~s/(..)/$1-/g;$a=~s/-$//};
  54. return $a;}],
  55. "HEX4" => [qr{1.0.96.5.5
  56. |0.0.96.240.\d+
  57. |129.129.199.130.5}x, sub{my $a=shift;
  58. if ( $a =~ /^[0-9a-fA-F]+$/ ) {$a=~s/(....)/$1-/g;$a=~s/-$//};
  59. return $a;}],
  60. "INFO" => [qr{1-0:0\.0\.[0-9]
  61. |129.129.199.130.3}x, ""],
  62. );
  63. #####################################
  64. sub OBIS_Initialize($)
  65. {
  66. my ($hash) = @_;
  67. require "$attr{global}{modpath}/FHEM/DevIo.pm";
  68. $hash->{Match} = "^\/(?s:.*)\!\$";
  69. $hash->{ReadFn} = "OBIS_Read";
  70. $hash->{ReadyFn} = "OBIS_Ready";
  71. $hash->{DefFn} = "OBIS_Define";
  72. $hash->{ParseFn} = "OBIS_Parse";
  73. # $hash->{SetFn} = "OBIS_Set";
  74. $hash->{GetFn} = "OBIS_Get";
  75. $hash->{UndefFn} = "OBIS_Undef";
  76. $hash->{AttrFn} = "OBIS_Attr";
  77. $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 ".
  78. $readingFnAttributes;
  79. }
  80. #1B1B1B1B010101017605002605426200620072630101760107FFFFFFFFFFFF05000CAC6C0B0A01454D4800005A561C726201640DF29B620163676F0076050026054362006200726307017707FFFFFFFFFFFF0B0A01454D4800005A561C070100620AFFFF726201640DF29B7577070100603201010101010104454D480177070100600100FF010101010B0A01454D4800005A561C0177070100010800FF641C0104726201640DF29B621E52FF6404AB760177070100020800FF01726201640DF29B621E52FF6324910177070100100700FF0101621B52005301360101016373F100760500260544620062007263020171016326A3000000001B1B1B1B1A03CDC9
  81. #1B1B1B1B010101017605002605456200620072630101760107FFFFFFFFFFFF05000CAC6D0B0A01454D4800005A561C726201640DF29C62016343D30076050026054662006200726307017707FFFFFFFFFFFF0B0A01454D4800005A561C070100620AFFFF726201640DF29C7577070100603201010101010104454D480177070100600100FF010101010B0A01454D4800005A561C0177070100010800FF641C0104726201640DF29C621E52FF6404AB770177070100020800FF01726201640DF29C621E52FF6324910177070100100700FF0101621B520053012C0101016319F6007605002605476200620072630201710163955D000000001B1B1B1B1A0310B4
  82. #####################################
  83. sub OBIS_Define($$)
  84. {
  85. my ($hash, $def) = @_;
  86. my @a = split("[ \t][ \t]*", $def);
  87. return 'wrong syntax: define <name> OBIS devicename@baudrate[,databits,parity,stopbits]|none [MeterType]'
  88. if(@a < 3);
  89. DevIo_CloseDev($hash);
  90. RemoveInternalTimer($hash);
  91. my $name = $a[0];
  92. my $dev = $a[2];
  93. my $type = $a[3]//"Unknown";
  94. $hash->{DeviceName} = $dev;
  95. $hash->{MeterType}=$type if (defined($type));
  96. my $device_name = "OBIS_".$name;
  97. $modules{OBIS}{defptr}{$device_name} = $hash;
  98. # If device="none", prepeare for an external IO-Module
  99. if($dev=~/none|ext/) {
  100. if (@a == 4){
  101. my $device_name = "OBIS.".$a[4];
  102. $hash->{CODE} = $a[4];
  103. $modules{OBIS}{defptr}{$device_name} = $hash;
  104. }
  105. AssignIoPort($hash);
  106. Log3 ($hash,1, "OBIS ($name) - OBIS device is none, commands will be echoed only");
  107. return undef;
  108. }
  109. my $baudrate;
  110. my $devi;
  111. ($devi, $baudrate) = split("@", $dev);
  112. $hash->{helper}{SPEED}="0";
  113. if (defined($baudrate)) { ## added for ser2net connection
  114. if($baudrate =~ m/(\d+)(,([78])(,([NEO])(,([012]))?)?)?/) {
  115. $baudrate = $1 if(defined($1));
  116. }
  117. my %bd=("300"=>"0","600"=>"1","1200"=>"2","2400"=>"3","4800"=>"4","9600"=>"5","18200"=>"6","36400"=>"7","57600"=>"8","115200"=>"9");
  118. $hash->{helper}{SPEED}=$bd{$baudrate};
  119. $hash->{helper}{SPEED2}=$bd{$a[4]//$baudrate};
  120. }
  121. else {$baudrate=9600; $hash->{helper}{SPEED}="5";}
  122. my %devs= (
  123. # Name, Init-String, interval, 2ndInit
  124. "none" => ["", -1, ""],
  125. "Unknown" => ["", -1, ""],
  126. "SML" => ["", -1, ""],
  127. "Ext" => ["", -1, ""],
  128. "Standard" => ["", -1, ""],
  129. "VSM102" => ["/?!".chr(13).chr(10), 600, chr(6)."0".$hash->{helper}{SPEED}."0".chr(13).chr(10)],
  130. "E110" => ["/?!".chr(13).chr(10), 600, chr(6)."0".$hash->{helper}{SPEED}."0".chr(13).chr(10)],
  131. "E350USB" => ["/?!".chr(13).chr(10), 600, chr(6)."0".$hash->{helper}{SPEED}."0".chr(13).chr(10)],
  132. );
  133. if (!$devs{$type}) {return 'unknown meterType. Must be one of <nothing>, SML, Standard, VSM102, E110'};
  134. $devs{$type}[1] = $hash->{helper}{DEVICES}[1] // $devs{$type}[1];
  135. $hash->{helper}{DEVICES} =$devs{$type};
  136. $hash->{helper}{TRIGGERTIME}=gettimeofday();
  137. # if( !$init_done ) {
  138. # $attr{$name}{"event-on-change-reading"} = ".*";
  139. # }
  140. my $t=OBIS_adjustAlign($hash,AttrVal($name,"alignTime",undef),$hash->{helper}{DEVICES}[1]);
  141. Log3 ($hash,5,"OBIS ($name) - Internal timer set to ".FmtDateTime($t)) if ($hash->{helper}{DEVICES}[1]>0);
  142. InternalTimer($t, "GetUpdate", $hash, 0) if ($hash->{helper}{DEVICES}[1]>0);
  143. $hash->{helper}{EoM}=-1;
  144. Log3 $hash,5,"OBIS ($name) - Opening device...";
  145. return DevIo_OpenDev($hash, 0, "OBIS_Init");
  146. }
  147. sub OBIS_Get($@)
  148. {
  149. my ($hash, @a) = @_;
  150. my $name = shift @a;
  151. my $opt = shift @a;
  152. if ($opt eq "update") {
  153. GetUpdate($hash);
  154. } else
  155. {return "Unknown argument $opt, choose one of update";}
  156. }
  157. sub OBIS_Set($@)
  158. {
  159. my ( $hash, @a ) = @_;
  160. my $name = shift @a;
  161. my $opt = shift @a;
  162. my $value = join("", @a);
  163. my $teststr="";
  164. my %bd=("300"=>"0","600"=>"1","1200"=>"2","2400"=>"3","4800"=>"4","9600"=>"5","18200"=>"6","36400"=>"7","57600"=>"8","115200"=>"9");
  165. if ($opt eq "setSpeed") {
  166. if ($bd{$value} ne $hash->{helper}{SPEED}) {
  167. $hash->{helper}{BUFFER}="";
  168. $hash->{helper}{SPEED}=$bd{$value};
  169. print "old Helper: $hash->{helper}{DEVICES}[2] \r\n";
  170. $hash->{helper}{DEVICES}[2]=$hash->{helper}{DEVICES}[2] eq "" ? "" : chr(6)."0".$hash->{helper}{SPEED}."0".chr(13).chr(10);
  171. print "new Helper: $hash->{helper}{DEVICES}[2] \r\n";
  172. $hash->{helper}{SpeedChange}=$value;
  173. DevIo_SimpleWrite($hash,$hash->{helper}{DEVICES}[0],undef) ;
  174. print "Wrote $hash->{helper}{DEVICES}[0]\r\n";
  175. }
  176. }
  177. return;
  178. }
  179. # Update-Routine
  180. sub GetUpdate($)
  181. {
  182. my ($hash) = @_;
  183. my $name = $hash->{NAME};
  184. my $type= $hash->{MeterType};
  185. RemoveInternalTimer($hash);
  186. $hash->{helper}{EoM}=-1;
  187. if ($hash->{helper}{DEVICES}[1] eq "") {return undef;}
  188. if( $init_done ) {
  189. DevIo_SimpleWrite($hash,$hash->{helper}{DEVICES}[0],undef) ;
  190. Log3 $hash,4,"Wrote $hash->{helper}{DEVICES}[0]";
  191. }
  192. my $t=OBIS_adjustAlign($hash,AttrVal($name,"alignTime",undef),$hash->{helper}{DEVICES}[1]);
  193. Log3 ($hash,5,"OBIS ($name) - Internal timer set to ".FmtDateTime($t)) if ($hash->{helper}{DEVICES}[1]>0);
  194. InternalTimer($t, "GetUpdate", $hash, 1) if ($hash->{helper}{DEVICES}[1]>0);
  195. }
  196. sub OBIS_Init($)
  197. {
  198. Log 3,"Init done";
  199. return undef;
  200. }
  201. #####################################
  202. sub OBIS_Undef($$)
  203. {
  204. my ($hash, $arg) = @_;
  205. RemoveInternalTimer($hash);
  206. DevIo_CloseDev($hash) if $hash->{DeviceName} ne "none";
  207. return undef;
  208. }
  209. #####################################
  210. sub OBIS_Read($)
  211. {
  212. my ($hash) = @_;
  213. if( $init_done ) {
  214. my $name = $hash->{NAME};
  215. my $buf = DevIo_SimpleRead($hash);
  216. my $b=$buf;
  217. $b =~ s/(.)/sprintf("%X",ord($1))/eg;
  218. if ( !defined($hash->{helper}{SpeedChange}) || ($hash->{helper}{SpeedChange} eq ""))
  219. {
  220. OBIS_Parse($hash,$buf) if ($hash->{helper}{EoM}!=1);
  221. } else
  222. {
  223. # if ($hash->{helper}{SpeedChange2} eq "")
  224. # {
  225. # Log3 $hash,4,"Part 1";
  226. ## $hash->{helper}{SPEED}=$bd{$value};
  227. # DevIo_SimpleWrite($hash,$hash->{helper}{DEVICES}[2],undef) ;
  228. # Log3 $hash,4,"Writing ".$hash->{helper}{DEVICES}[2];
  229. # $hash->{helper}{SpeedChange2}="1";
  230. # } elsif ($hash->{helper}{SpeedChange2} eq "1")
  231. # {
  232. # if ($buf ne hex(15)) {
  233. # Log3 $hash,4,"Part 2";
  234. # my $sp=$hash->{helper}{SPEED};
  235. # my $d=$hash->{DeviceName};
  236. # my $repl=$sp;
  237. # Log3 $hash,4,"Old Dev: $d";
  238. # $d=~/(.*@)(\d*)(.*)/;
  239. # my $d2=$1.$hash->{helper}{SpeedChange}.$3;
  240. # # $d=~s/(.*@)(\d*)(.*)/$repl$2/ee;
  241. #
  242. # Log3 $hash,4, "Replaced dev: $d2";
  243. # RemoveInternalTimer($hash);
  244. # DevIo_CloseDev($hash) if $hash->{DeviceName} ne "none";
  245. # $hash->{DeviceName} = $d2;
  246. # $hash->{helper}{EoM}=-1;
  247. # Log3 $hash,5,"OBIS ($name) - Opening device...";
  248. # my $t=OBIS_adjustAlign($hash,AttrVal($name,"alignTime",undef),$hash->{helper}{DEVICES}[1]);
  249. # Log3 ($hash,5,"OBIS ($name) - Internal timer set to ".FmtDateTime($t)) if ($hash->{helper}{DEVICES}[1]>0);
  250. # InternalTimer($t, "GetUpdate", $hash, 0) if ($hash->{helper}{DEVICES}[1]>0);
  251. # DevIo_OpenDev($hash, 1, "OBIS_Init");
  252. # } else
  253. # {
  254. # Log3 $hash,4,"Recieved NAK from Meter";
  255. # }
  256. # $hash->{helper}{SpeedChange2}="";
  257. # $hash->{helper}{SpeedChange}="";
  258. # Log3 $hash,4, "Cleared helper\r\n";
  259. # }
  260. }
  261. }
  262. return(undef);
  263. }
  264. sub OBIS_trySMLdecode($$)
  265. {
  266. my ( $hash, $remainingSML ) = @_;
  267. my $t=$remainingSML;
  268. if ($remainingSML=~m/SML\((.*)\)/g) {$remainingSML=$1};
  269. if($remainingSML!~/[\x00-\x09|\x10-\x1F]/g) {return $remainingSML} else {$hash->{MeterType}="SML"};
  270. $remainingSML=uc(unpack('H*',$remainingSML));
  271. $hash->{MeterType}="SML";
  272. my $newMsg="";
  273. while ($remainingSML=~/(1B1B1B1B010101.*?1B1B1B1B1A[0-9A-F]{6})/mip) {
  274. my $msg=$1;
  275. Log3 $hash,5,"SML-Parse $1";
  276. $remainingSML=${^POSTMATCH};
  277. if (OBIS_CRC16($hash,pack('H*',$msg)) == 1) {
  278. $remainingSML=""; #reset possible further messages if actual CRC ok; if someone misses some messages, we remove it.
  279. my $OBISmsg="";
  280. my $initstr="/";
  281. my $OBISid=$msg=~m/7701([0-9A-F]*?)01/g;
  282. Log3 $hash,5,"OBIS: Full message-> $msg";
  283. (undef,undef,$OBISid,undef)=OBIS_decodeTL($1);
  284. # Log3 $hash,5,"OBIS: ObisID-> $1";
  285. while ($msg =~ m/(7707)([0-9A-F]*)/g) {
  286. # my $telegramm = $&;
  287. my @list=$&=~/(7707)([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]*)/g;
  288. Log3 $hash, 5,"OBIS: Telegram=$msg";
  289. # Log 3,Dumper(@list);
  290. if (!@list) {Log3 $hash,3,"OBIS - Empty datagram: .$msg"};
  291. my $line=hex($list[1])."-".hex($list[2]).":".hex($list[3]).".".hex($list[4]).".".hex($list[5])."*255(";
  292. if ($line eq '255-255:255.255.255*255(') {
  293. $list[7]=~/(7707.*)/;
  294. $msg=$1;
  295. } else
  296. {
  297. # Log3 $hash,5,"Line: $line";
  298. # Log3 $hash,5,"Before decoding: $list[7]";
  299. my ($status,$statusL,$statusT,$valTime,$valTimeL,$valTimeT,$unit,$unitL,$unitT,$scaler,$scalerL,$scalerT,$data,$dataL,$dataT,$other);
  300. ($statusL,$statusT,$status,$other)=OBIS_decodeTL($list[7]);
  301. # Log3 $hash,5,"After status: $other";
  302. ($valTimeL,$valTimeT,$valTime,$other)=OBIS_decodeTL($other);
  303. # Log3 $hash,5,"After Time: $other";
  304. ($unitL,$unitT,$unit,$other)=OBIS_decodeTL($other);
  305. # Log3 $hash,5,"After Unit: $other";
  306. ($scalerL,$scalerT,$scaler,$other)=OBIS_decodeTL($other);
  307. # Log3 $hash,5,"After Scaler: $other";
  308. ($dataL,$dataT,$data,$msg)=OBIS_decodeTL($other);
  309. # Log3 $hash,5,"After Data: $msg";
  310. # Type String
  311. my $line2="";
  312. if ($dataT ==0 ) {
  313. $line2=$data;
  314. if($line=~$SML_specialities{"HEX4"}[0]) {
  315. #
  316. # $line2=$SML_specialities{"HEX4"}[1]->($data)
  317. } elsif($line=~$SML_specialities{"HEX2"}[0]) {
  318. # $line2=$SML_specialities{"HEX2"}[1]->($data)
  319. } else {
  320. $data=~s/([A-F0-9]{2})/chr(hex($1))/eg;
  321. $line2="$data";
  322. }
  323. # Type signed (=80) and unsigned (=96) Integer
  324. } elsif ($dataT & 0b01010000|$dataT & 0b01100000) {
  325. $unit= $unit eq "1E" ? "Wh" :
  326. $unit eq "1B" ? "W" :
  327. $unit eq "21" ? "A" :
  328. $unit eq "23" ? "V" :
  329. $unit eq "2C" ? "Hz" :
  330. $unit eq "01" ? "" :
  331. $unit eq "1D" ? "varh" :
  332. $unit eq "" ? "" : "var";
  333. $scaler=$scaler ne "" ? 10**unpack("c", pack("C", hex($scaler))) : 1;
  334. if ($scaler==0) {$scaler=1}; # just to make sure
  335. $line2.="<" if ($status=~/[aA]2$/);
  336. $line2.=">" if ($status=~/82$/);
  337. my $val=0;
  338. # signed Values
  339. my $tmp="";
  340. if ($dataT & 0b00010000) {
  341. if ($data =~ /^[89a-f]/i) {$val = hex($data) - hex(sprintf ("FF" x $dataL)) -1;}
  342. else {$val = hex($data)} #positive value
  343. }
  344. if ($dataT & 0b00100000 || $val>=0) {
  345. $val=hex($data);
  346. }
  347. # $line2.=($val*$scaler).($unit eq "" ? "" : "*$unit") if($dataT ==80);
  348. $line2.=($val*$scaler).($unit eq "" ? "" : "*$unit"); # if($dataT ==96);
  349. } elsif ($dataT & 0b01000000) { # Type Boolean - no Idea, where this is used
  350. $line2=OBIS_hex2int($data); # 0=false, everything else is true
  351. } elsif ($dataT & 0b01110000) { # Type List of.... - Time is sometimes delivered as structure
  352. # my @a_Length;
  353. # my @a_Type;
  354. # my @a_Data;
  355. # for (my $b=0;$b<$dataL;$b++) {
  356. # my ($l_length,$l_type,$l_data);
  357. # }
  358. }
  359. $initstr.="$line2\\" if ($line=~$SML_specialities{"INFO"}[0]);
  360. $newMsg.=$line.$line2.")\r\n";
  361. # Log 3,"$line$line2)";
  362. ###### TypeLength-Test ends here
  363. }
  364. }
  365. $initstr=~s/\\$//;
  366. $newMsg=$initstr.chr(13).chr(10).$newMsg;
  367. $newMsg.="!".chr(13).chr(10);
  368. Log3 $hash,4,"MSG IS: \r\n$newMsg";
  369. } else {
  370. # Log 3,"Illegal CRC";
  371. $hash->{CRC_Errors}+=1;
  372. }
  373. }
  374. return ($newMsg,pack('H*',$remainingSML));
  375. }
  376. sub OBIS_Parse($$)
  377. {
  378. my ($hash, $buf) = @_;
  379. my $buf2=uc(unpack('H*',$buf));
  380. if($hash->{MeterType}!~/SML|Unknown/ && $buf2=~m/7701([0-9A-F]*?)01/g) {
  381. Log 3,"OBIS_Ext called";
  382. my (undef,undef,$OBISid,undef)=OBIS_decodeTL($1);
  383. my $device_name = "OBIS.".$OBISid;
  384. Log3 $hash,5,"New Devicename: $device_name";
  385. my $def = $modules{OBIS}{defptr}{"$device_name"};
  386. if(!$def) {
  387. Log3 $hash, 3, "OBIS: Unknown device $device_name, please define it";
  388. return "UNDEFINED $device_name OBIS none Ext $OBISid";
  389. }
  390. }
  391. $hash->{helper}{BUFFER} .= $buf;
  392. if (length($hash->{helper}{BUFFER}) >10000) { #longer than 3 messages, this is a traffic jam
  393. $hash->{helper}{BUFFER} =substr( $hash->{helper}{BUFFER} , -10000);
  394. }
  395. my %dir=("<"=>"out",">"=>"in");
  396. my $buffer=$hash->{helper}{BUFFER};
  397. my $remainingSML;
  398. ($buffer,$remainingSML) = OBIS_trySMLdecode($hash,$buffer) if ($hash->{MeterType}=~/SML|Ext|Unknown/);
  399. my $type= $hash->{MeterType};
  400. my $name = $hash->{NAME};
  401. if(index($buffer,chr(13).chr(10)) ne -1){
  402. readingsBeginUpdate($hash);
  403. while(index($buffer,chr(13).chr(10)) ne -1)
  404. {
  405. my $rmsg="";
  406. $rmsg = substr($buffer, 0, index($buffer,chr(13).chr(10)));
  407. Log3 $hash,5,"OBIS ($name) - Msg-Parse: $rmsg";
  408. my $channel=" ";
  409. if($rmsg=~/\/.*|^((?:\d{1,3}-\d{1,3}:)?(?:\d{1,3}|[CF]).\d{1,3}(?:.\d{1,3})?(?:\*\d{1,3})?)(?:\(.*?\))?\(.*?\)|!/) { # old regex: \/.*|\d-\d{1,3}:\d{1,3}.\d{1,3}.\d{1,3}\*\d{1,3}\(.*?\)|!
  410. if (length $1) {
  411. $channel=$1;
  412. # $channel=~s/[\:\-*]/\./;
  413. $channel=~s/:/\./;
  414. $channel=~s/-/\./;
  415. $channel=~s/\*/\./;
  416. }
  417. if ($hash->{MeterType} eq "Unknown") {$hash->{MeterType}="Standard"}
  418. # if($rmsg=~/^([23456789]+)-.*/) {
  419. # Log3 $hash,3,"OBIS ($name) - Unknown OBIS-Device, please report: $rmsg".chr(13).chr(10)."Please report to User icinger at forum.fhem.de";
  420. # }
  421. # End of Message
  422. if ($rmsg=~/!.*/) {
  423. $hash->{helper}{EoM}+=1 if ($hash->{helper}{DEVICES}[1]>0);
  424. }
  425. #Version
  426. elsif ($rmsg=~ /.*\/(.*)/) {
  427. DevIo_SimpleWrite($hash,$hash->{helper}{DEVICES}[2],undef) if (!$hash->{helper}{DEVICES}[2] eq "");
  428. if (ReadingsVal($name,"Version","") ne $1) {readingsBulkUpdate($hash, "Version" ,$1); }
  429. $hash->{helper}{EoM}=0;
  430. }
  431. elsif ($hash->{helper}{EoM}!=1) {
  432. my @patterns=values %OBIS_codes;
  433. if (!$rmsg~~@patterns) {
  434. Log3 $hash,3,"OBIS ($name) - Unknown Message: $rmsg".chr(13).chr(10)."Please report to User icinger at forum.fhem.de"
  435. } else {
  436. my $found=0;
  437. if (!($hash->{helper}{Channels}{$channel} //$hash->{helper}{Channels}{$1})) {
  438. for my $code (keys %OBIS_codes) {
  439. if ($rmsg =~ $OBIS_codes{$code}) {
  440. Log3 $hash,5,"Msg $rmsg is of type $code";
  441. if ($code=~/Channel_sum.*/) {
  442. $rmsg =~ $OBIS_codes{$code};
  443. my $L= $hash->{helper}{Channels}{$channel} //$hash->{helper}{Channels}{$1} // "sum_$OBIS_channels{$1}" //$channel;
  444. if (AttrVal($name,"ignoreUnknown","off") eq "off" || $L ne $channel) {
  445. readingsBulkUpdate($hash, $L,(looks_like_number($3) ? $3+0 : $3).(AttrVal($name,"unitReadings","off") eq "off"?"":" $4"));
  446. readingsBulkUpdate($hash, "dir_$L",$hash->{helper}{directions}{$2} // $dir{$2}) if (length $2);
  447. }
  448. }
  449. elsif ($code=~/Channels.*/) {
  450. $rmsg =~ $OBIS_codes{$code};
  451. my $L=$hash->{helper}{Channels}{$channel} //$hash->{helper}{Channels}{$1} // $OBIS_channels{$1} //$channel;
  452. if (AttrVal($name,"ignoreUnknown","off") eq "off" || $L ne $channel) {
  453. readingsBulkUpdate($hash, "$L",(looks_like_number($3) ? $3+0 : $3).(AttrVal($name,"unitReadings","off") eq "off"?"":" $4"));
  454. readingsBulkUpdate($hash, "dir_$L",$hash->{helper}{directions}{$2} // $dir{$2}) if (length $2);
  455. }
  456. }
  457. elsif ($code=~/Counter.*/) {
  458. $rmsg =~ $OBIS_codes{$code};
  459. my $L=$hash->{helper}{Channels}{$channel} //$hash->{helper}{Channels}{$1.".".$2} // $OBIS_channels{$1.".".$2} // $channel;
  460. my $chan=$3+0 > 0 ? "_Ch$3" : "";
  461. if (AttrVal($name,"ignoreUnknown","off") eq "off" || $L ne $channel) {
  462. if($1==1) {
  463. Log3($hash,4,"Set ".$L.$chan." to ".((looks_like_number($3) ? $5+0 : $5) +AttrVal($name,"offset_energy",0)));
  464. readingsBulkUpdate($hash, $L.$chan ,(looks_like_number($3) ? $5+0 : $5) +AttrVal($name,"offset_energy",0).(AttrVal($name,"unitReadings","off") eq "off"?"":" $6"));
  465. } elsif ($1==2) {
  466. readingsBulkUpdate($hash, $L.$chan ,(looks_like_number($3) ? $5+0 : $5) +AttrVal($name,"offset_feed",0).(AttrVal($name,"unitReadings","off") eq "off"?"":" $6"));
  467. }
  468. readingsBulkUpdate($hash, "dir_$L",$hash->{helper}{directions}{$4} // $dir{$4}) if (length $4);
  469. }
  470. } else
  471. {
  472. $rmsg =~ $OBIS_codes{$code};
  473. my $data=$1;
  474. if($rmsg=~$SML_specialities{"HEX4"}[0]) {
  475. $data=$SML_specialities{"HEX4"}[1]->($data)
  476. } elsif($rmsg=~$SML_specialities{"HEX2"}[0]) {
  477. $data=$SML_specialities{"HEX2"}[1]->($data)
  478. } elsif($rmsg=~$SML_specialities{"TIME"}[0]) {
  479. $data=~/(\d+)/;
  480. $data=$SML_specialities{"TIME"}[1]->($1)
  481. }
  482. my $chan=$code//$OBIS_channels{$channel} //$channel;
  483. if ($#+ > 0) {
  484. $chan=$hash->{helper}{Channels}{$channel} // $hash->{helper}{Channels}{$1} // $OBIS_channels{$1} //$channel;
  485. } else {
  486. $chan=$hash->{helper}{Channels}{$channel} //$channel;
  487. }
  488. if (AttrVal($name,"ignoreUnknown","off") eq "off" || $chan ne $channel) {
  489. readingsBulkUpdate($hash, $chan ,$data); }
  490. }
  491. $found=1;
  492. last;
  493. }
  494. }
  495. }
  496. if ($found==0) {
  497. $rmsg=~/^((?:\d{1,3}-\d{1,3}:)?(?:\d{1,3}|[CF]).\d{1,3}(?:.\d{1,3})?(?:\*\d{1,3})?)(?:\((.*?)\))?\((.*?)\)/;
  498. my $chan=$hash->{helper}{Channels}{$channel} //$hash->{helper}{Channels}{$1} // $OBIS_channels{$1} //$channel;
  499. my $chan1=$chan;
  500. my $chan2=$chan."_2";
  501. # Log 3,"Setting $chan";
  502. my $v1=$3;
  503. my $v2;
  504. if (AttrVal($name,"valueBracket","second") eq "first") {
  505. $v1=length $2 ? $2 : $3;
  506. }
  507. if (AttrVal($name,"valueBracket","second") eq "both") {
  508. $v2=$2;
  509. ($v1,$v2)=($v2,$v1);
  510. if (!length $v1 and length $v2) {$v1=$v2;$v2=""}
  511. $chan1.="_1" if length $2;
  512. }
  513. if (AttrVal($name,"unitReadings","off") eq "off") {
  514. $v1=~s/(.*)\*.*/$1/;
  515. if ($v2) {$v2=~s/(.*)\*.*/$1/};
  516. }
  517. $v1+=0 if (looks_like_number($v1));
  518. $v2+=0 if (looks_like_number($v2));
  519. if (AttrVal($name,"ignoreUnknown","off") eq "off" || $chan ne $channel) {
  520. readingsBulkUpdate($hash, $chan1 ,$v1) if length $v1;
  521. readingsBulkUpdate($hash, $chan2 ,$v2) if length $v2;}
  522. }
  523. }
  524. }
  525. if ($hash->{helper}{EoM}==1) {last;}
  526. }
  527. $buffer = substr($buffer, index($buffer,chr(13).chr(10))+2);;
  528. }
  529. readingsEndUpdate($hash,1);
  530. }
  531. if (defined($remainingSML)) {$hash->{helper}{BUFFER}=$remainingSML}
  532. else{$hash->{helper}{BUFFER}=$buffer;}
  533. if($hash->{helper}{EoM}==1) { $hash->{helper}{BUFFER}="";}
  534. return $name;
  535. }
  536. #####################################
  537. sub OBIS_Ready($)
  538. {
  539. my ($hash) = @_;
  540. return DevIo_OpenDev($hash, 1, "OBIS_Init")
  541. if($hash->{STATE} eq "disconnected");
  542. my $name = $hash->{NAME};
  543. my $dev=$hash->{DeviceName};
  544. # This is relevant for windows/USB only
  545. my $po = $hash->{USBDev};
  546. my ($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags);
  547. return if (!$po);
  548. ($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags) = $po->status;
  549. return ($InBytes>0);
  550. }
  551. sub OBIS_Attr(@)
  552. {
  553. my ($cmd,$name,$aName,$aVal) = @_;
  554. # $cmd can be "del" or "set"
  555. # $name is device name
  556. # aName and aVal are Attribute name and value
  557. my $hash = $defs{$name};
  558. my $dev=$hash->{DeviceName};
  559. #{$hash->{"test"}->{SetFn} = "OBIS_Set"}
  560. if ($cmd eq "del") {
  561. if ($aName eq "channels") { $hash->{helper}{Channels}=undef;}
  562. if ($aName eq "interval") {
  563. RemoveInternalTimer($hash);
  564. $hash->{helper}{DEVICES}[1]=0;
  565. }
  566. if ($aName eq "pollingMode") {
  567. delete($readyfnlist{"$name.$dev"});
  568. $selectlist{"$name.$dev"} = $hash;
  569. DevIo_CloseDev($hash);
  570. DevIo_OpenDev($hash, 0, "OBIS_Init");
  571. }
  572. }
  573. if ($cmd eq "set") {
  574. if ($aName eq "channels") {
  575. $hash->{helper}{Channels}=eval $aVal;
  576. if ($@) {
  577. Log3 $name, 3, "OBIS ($name) - X: Invalid regex in attr $name $aName $aVal: $@";
  578. $hash->{helper}{Channels}=undef;
  579. }
  580. }
  581. if ($aName eq "directions") {
  582. $hash->{helper}{directions}=eval $aVal;
  583. if ($@) {
  584. Log3 $name, 3, "OBIS ($name) - X: Invalid regex in attr $name $aName $aVal: $@";
  585. $hash->{helper}{directions}=undef;
  586. }
  587. }
  588. if ($aName eq "interval") {
  589. if ($aVal=~/^[1-9][0-9]*$/) {
  590. $hash->{helper}{TRIGGERTIME}=gettimeofday();
  591. RemoveInternalTimer($hash);
  592. $hash->{helper}{DEVICES}[1]=$aVal;
  593. my $t=OBIS_adjustAlign($hash,AttrVal($name,"alignTime",undef),$hash->{helper}{DEVICES}[1]);
  594. Log3 ($hash,5,"OBIS ($name) - Internal timer set to ".FmtDateTime($t)) if ($hash->{helper}{DEVICES}[1]>0);
  595. InternalTimer($t, "GetUpdate", $hash, 0) if ($hash->{helper}{DEVICES}[1]>0);
  596. } else {
  597. return "OBIS ($name) - $name: attr interval must be a number -> $aVal";
  598. }
  599. }
  600. if ($aName eq "alignTime") {
  601. if ($hash->{helper}{DEVICES}[1]>0) {
  602. if ($aVal=~/\d+/) {
  603. RemoveInternalTimer($hash);
  604. $hash->{helper}{TRIGGERTIME}=gettimeofday();
  605. my $t=OBIS_adjustAlign($hash,$aVal,$hash->{helper}{DEVICES}[1]);
  606. Log3 ($hash,5,"OBIS ($name) - Internal timer set to ".FmtDateTime($t));
  607. InternalTimer($t, "GetUpdate", $hash, 0);
  608. } else {return "OBIS ($name): attr alignTime must be a Value >0"}
  609. } else {
  610. return "OBIS ($name): attr alignTime is useless, if no interval is specified";
  611. }
  612. }
  613. if ($aName eq "pollingMode")
  614. {
  615. if ($aVal eq "on") {
  616. delete $hash->{FD};
  617. delete($selectlist{"$name.$dev"});
  618. $readyfnlist{"$name.$dev"} = $hash;
  619. } elsif ($aVal eq "off") {
  620. delete($readyfnlist{"$name.$dev"});
  621. $selectlist{"$name.$dev"} = $hash;
  622. DevIo_CloseDev($hash);
  623. DevIo_OpenDev($hash, 0, "OBIS_Init");
  624. }
  625. }
  626. }
  627. return undef;
  628. }
  629. sub OBIS_adjustAlign($$$)
  630. {
  631. my($hash, $attrVal, $interval) = @_;
  632. if (!$attrVal) {return gettimeofday()+$interval;}
  633. my ($alErr, $alHr, $alMin, $alSec, undef) = GetTimeSpec($attrVal);
  634. return "$hash->{NAME} alignTime: $alErr" if($alErr);
  635. my $tspec=strftime("\%H:\%M:\%S", gmtime($interval));
  636. # Obis_adjustAlignTimetest2($hash,AttrVal($hash->{NAME},"alignTime",undef),$hash->{helper}{DEVICES}[1]);
  637. my (undef, $hr, $min, $sec, undef) = GetTimeSpec($tspec);
  638. my $now = time();
  639. my $step = ($hr*60+$min)*60+$sec;
  640. my $alTime = ($alHr*60+$alMin)*60+$alSec;#-fhemTzOffset($now);
  641. my $ttime = int($hash->{helper}{TRIGGERTIME});
  642. my $off = ($ttime % 86400) - 86400;
  643. if ($off >= $alTime) {
  644. $ttime = gettimeofday();#-86400;
  645. $off -= 86400;
  646. }
  647. my $off2=$off;
  648. while($off < $alTime) {
  649. $off += $step;
  650. }
  651. $ttime += ($alTime-$off);
  652. $ttime += $step if($ttime <= $now);
  653. $hash->{NEXT} = FmtDateTime($ttime);
  654. $hash->{helper}{TRIGGERTIME} = ($off2<=$alTime) ? $ttime : (gettimeofday());
  655. return $hash->{helper}{TRIGGERTIME};
  656. }
  657. sub OBIS_hex2int {
  658. my ($hexstr) = @_;
  659. return 0
  660. if $hexstr !~ /^[0-9A-Fa-f]{1,35}$/;
  661. my $num = hex($hexstr);
  662. return $num >> 31 ? $num - 2 ** 32 : $num;
  663. }
  664. sub OBIS_CRC16($$) {
  665. my ($hash,$buff)=@_;
  666. my @crc16 = ( 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 0x8c48,
  667. 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c,
  668. 0x75b7, 0x643e, 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, 0x2102, 0x308b, 0x0210,
  669. 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
  670. 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef,
  671. 0xea66, 0xd8fd, 0xc974, 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, 0xce4c, 0xdfc5,
  672. 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3,
  673. 0x263a, 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, 0x6306, 0x728f, 0x4014, 0x519d,
  674. 0x2522, 0x34ab, 0x0630, 0x17b9, 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, 0x7387,
  675. 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862,
  676. 0x9af9, 0x8b70, 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, 0x0840, 0x19c9, 0x2b52,
  677. 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
  678. 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e,
  679. 0xf2a7, 0xc03c, 0xd1b5, 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, 0xb58b, 0xa402,
  680. 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5,
  681. 0x4d7c, 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, 0x4a44, 0x5bcd, 0x6956, 0x78df,
  682. 0x0c60, 0x1de9, 0x2f72, 0x3efb, 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, 0x5ac5,
  683. 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3,
  684. 0x8238, 0x93b1, 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, 0xf78f, 0xe606, 0xd49d,
  685. 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78);
  686. my $crc=0xFFFF;
  687. my $a=substr($buff,0,-2);
  688. my $b=substr($buff,-2);
  689. my $crc2=OBIS_hex2int(uc(unpack('H*',$b)));
  690. foreach (split //, $a) {
  691. $crc = ($crc >> 8) ^ $crc16[($crc ^ ord($_)) & 0xff];
  692. }
  693. $crc ^= 0xffff;
  694. $crc = (($crc & 0xff) << 8) | (($crc & 0xff00) >> 8);
  695. return $crc2==$crc ? 1 : 0;
  696. }
  697. ###############################################
  698. # Input: Whole Datastream, inkl. TL-Byte #
  699. # Output: Length, Type, Value, remaining Data #
  700. ###############################################
  701. sub OBIS_decodeTL($){
  702. my ($msg)=@_;
  703. my $msgLength=0;
  704. my $msgType=0;
  705. my $lt="";
  706. my $tmp="";
  707. # Log 3,"In: $msg";
  708. if ($msg) {
  709. $msgType =hex(substr($msg,0,2)) & 0b01110000;
  710. do {
  711. $lt=hex(substr($msg,0,2));
  712. $msg=substr($msg,2);
  713. $msgLength=($msgLength*16) + ($lt & 0b00001111);
  714. } while ($lt & 0b10000000);
  715. # Log 3,"Calculated length: $msgLength";
  716. if ($msgType == 0b01110000) {
  717. for (my $i=0;$i<$msgLength;$i++) {
  718. my $tmp2="";
  719. # Log 3,"--> $msg";
  720. (undef,undef,undef,$msg,$tmp2)=OBIS_decodeTL($msg);
  721. # Log 3,"<-- $tmp2 $msg";
  722. $tmp.=$tmp2;
  723. }
  724. $msgLength-=1;
  725. }
  726. $msgLength-=1;
  727. my $valu;
  728. if (length($msg)>$msgLength*2) {
  729. $valu=substr($msg,0,$msgLength*2);
  730. $tmp.=$valu;
  731. $msg=substr($msg,$msgLength*2);
  732. }
  733. # Log 3," Split Msg: $tmp $msg";
  734. return $msgLength,$msgType,$valu,$msg,$tmp;
  735. };
  736. }
  737. "Cogito, ergo sum.";
  738. =pod
  739. =item device
  740. =item summary Collects data from Smartmeters that report in OBIS-Standard
  741. =item summary_DE Wertet Smartmeter aus, welche ihre Daten im OBIS-Standard senden
  742. =begin html
  743. <a name="OBIS"></a>
  744. <h3>OBIS</h3>
  745. This module is for SmartMeters, that report their data in OBIS-Standard. It dosen't matter, wether the data comes as PlainText or SML-encoded.
  746. <br>
  747. <b>Define</b>
  748. <code>define &lt;name&gt; OBIS device|none [MeterType] </code><br>
  749. <br>
  750. &lt;device&gt; specifies the serial port to communicate with the smartmeter.
  751. Normally on Linux the device will be named /dev/ttyUSBx, where x is a number.
  752. For example /dev/ttyUSB0. You may specify the baudrate used after the @ char.<br>
  753. <br><br>
  754. Optional:MeterType can be of
  755. <ul><li>VSM102 -&gt; Voltcraft VSM102</li>
  756. <li>E110 -&gt; Landis&&;Gyr E110</li>
  757. <li>E350USB -&gt; Landis&&;Gyr E350 USB-Version</li>
  758. <li>Standard -&gt; Data comes as plainText</li>
  759. <li>SML -&gt; Smart Message Language</li></ul>
  760. <br>
  761. Example: <br>
  762. <code>define myPowerMeter OBIS /dev/ttyPlugwise@@9600,7,E,1 VSM102</code>
  763. <br>
  764. <br>
  765. <b>Attributes</b>
  766. <ul><li>
  767. <code>offset_feed <br>offset_energy</code><br>
  768. If your smartmeter is BEHIND the meter of your powersupplier, then you can hereby adjust
  769. the total-reading of your SM to that of your official one.
  770. <br><br>
  771. </li>
  772. <li>
  773. <code>channels</code><br>
  774. With this, you can rename the reported channels.
  775. <code>attr myOBIS channels {"1.0.96.5.5.255"=>"Status","1.0.0.0.0.255"=>"Info","16.7"=>"Verbrauch"}></code>
  776. <br><br></li>
  777. <li><code>directions</code><br>
  778. Some Meters report feeding/comnsuming of power in a statusword.
  779. If this is set, you get an extra reading dir_total_consumption which defaults to "in" and "out"
  780. Here, you can change this text with:
  781. <code>attr myOBIS directions {">" => "pwr consuming", "<"=>"pwr feeding"}</code>
  782. </li>
  783. <li>
  784. <code>interval</code><br>
  785. The polling-interval in seconds. (Only useful in Polling-Mode)
  786. </li>
  787. <li>
  788. <code>alignTime</code><br>
  789. Aligns the intervals to a given time. Each interval is repeatedly calculated.
  790. So if alignTime=00:00 and interval=600 aligns the interval to xx:00:00, xx:10:00, xx:20:00 etc....
  791. <code>pollingMode</code><br>
  792. Changes from direct-read to polling-mode.
  793. Useful with meters, that send a continous datastream.
  794. Reduces CPU-load.
  795. <code>unitReadings</code><br>
  796. Adds the units to the readings like w, wH, A etc.
  797. <code>valueBracket</code><br>
  798. Sets, weather to use the value from the first or the second bracket, if applicable.
  799. Standard is "second"
  800. </li>
  801. <br>
  802. </ul>
  803. =end html
  804. =begin html_DE
  805. <a name="OBIS"></a>
  806. <h3>OBIS</h3>
  807. Modul für Smartmeter, die ihre Daten im OBIS-Standard senden. Hierbei ist es egal, ob die Daten als reiner Text oder aber SML-kodiert kommen.
  808. <br>
  809. <b>Define</b>
  810. <code>define &lt;name&gt; OBIS device|none [MeterType] </code><br>
  811. <br>
  812. &lt;device&gt; gibt den seriellen Port an.
  813. <br><br>
  814. Optional:MeterType kann sein:
  815. <ul><li>VSM102 -&gt; Voltcraft VSM102</li>
  816. <li>E110 -&gt; Landis&&;Gyr E110</li>
  817. <li>E350USB -&gt; Landis&&;Gyr E350 USB-Version</li>
  818. <li>Standard -&gt; Daten kommen als plainText</li>
  819. <li>SML -&gt; Smart Message Language</li></ul>
  820. <br>
  821. Beispiel: <br>
  822. <code>define myPowerMeter OBIS /dev/ttyPlugwise@@9600,7,E,1 VSM102</code>
  823. <br>
  824. <br>
  825. <b>Attribute</b>
  826. <ul><li>
  827. <code>offset_feed <br>offset_energy</code><br>
  828. Wenn das Smartmeter hinter einem Zähler des EVU's sitzt, kann hiermit der Zähler des
  829. Smartmeters an den des EVU's angepasst werden.
  830. <br><br>
  831. </li>
  832. <li>
  833. <code>channels</code><br>
  834. Hiermit können die einzelnen Kanal-Readings mittels RegExes umbenannt werden.
  835. Beispiel:
  836. <code>attr myOBIS channels {"1.0.96.5.5.255"=>"Status","1.0.0.0.0.255"=>"Info","16.7"=>"Verbrauch"}></code>
  837. <br><br>
  838. </li>
  839. <li><code>directions</code><br>
  840. Manche SmartMeter senden im Statusbyte die Stromrichtung.
  841. In diesem Fall gibt es ein extra Reading "dir_total_consumption" welches standardmäßig "in" and "out" beinhaltet
  842. Hiermit kann dieser Text geändert werden:
  843. <code>attr myOBIS directions {">" => "pwr consuming", "<"=>"pwr feeding"}</code>
  844. </li><li>
  845. <code>interval</code><br>
  846. Abrufinterval der Daten. (Bringt nur im Polling-Mode was)
  847. </li><li>
  848. <code>algignTime</code><br>
  849. Richtet den Zeitpunkt von <interval> nach einer bestimmten Uhrzeit aus.
  850. </li><li>
  851. <code>pollingMode</code><br>
  852. Hiermit wird von Direktbenachrichtigung auf Polling umgestellt.
  853. Bei Smartmetern, welche von selbst im Sekundentakt senden,
  854. kann das zu einer spürbaren Senkung der Prozessorleistung führen.
  855. <code>unitReadings</code><br>
  856. Hängt bei den Readings auch die Einheiten an, zB w, wH, A usw.
  857. <code>valueBracket</code><br>
  858. Legt fest, ob der Wert aus dem ersten oder zweiten Klammernpaar genommen wird.
  859. Standard ist "second"
  860. </li>
  861. <br>
  862. </ul>
  863. =end html_DE
  864. =cut