73_ElectricityCalculator.pm 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021
  1. # $Id: 73_ElectricityCalculator.pm 16601 2018-04-13 17:57:41Z Sailor $
  2. ########################################################################################################################
  3. #
  4. # 73_ElectricityCalculator.pm
  5. # Observes a reading of a device which represents the actual counter (e.g. OW_devive)
  6. # acting as electricity meter, calculates the corresponding values and writes them back to
  7. # the counter device.
  8. # Written and best viewed with Notepad++ v.6.8.6; Language Markup: Perl
  9. #
  10. # Author : Matthias Deeke
  11. # e-mail : matthias.deeke(AT)deeke(PUNKT)eu
  12. # Fhem Forum : https://forum.fhem.de/index.php/topic,57106.msg485195.html
  13. # Fhem Wiki : Not yet implemented
  14. #
  15. # This file is part of fhem.
  16. #
  17. # Fhem is free software: you can redistribute it and/or modify
  18. # it under the terms of the GNU General Public License as published by
  19. # the Free Software Foundation, either version 2 of the License, or
  20. # (at your option) any later version.
  21. #
  22. # Fhem is distributed in the hope that it will be useful,
  23. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. # GNU General Public License for more details.
  26. #
  27. # You should have received a copy of the GNU General Public License
  28. # along with fhem. If not, see <http://www.gnu.org/licenses/>.
  29. #
  30. # fhem.cfg: define <devicename> ElectricityCalculator <regexp>
  31. #
  32. # Example 1:
  33. # define myElectricityCalculator ElectricityCalculator myElectricityCounter:CounterA.*
  34. #
  35. ########################################################################################################################
  36. ########################################################################################################################
  37. # List of open Problems / Issues:
  38. #
  39. # - set command to create Plots automatically
  40. #
  41. ########################################################################################################################
  42. package main;
  43. use strict;
  44. use warnings;
  45. ###START###### Initialize module ##############################################################################START####
  46. sub ElectricityCalculator_Initialize($)
  47. {
  48. my ($hash) = @_;
  49. $hash->{STATE} = "Init";
  50. $hash->{DefFn} = "ElectricityCalculator_Define";
  51. $hash->{UndefFn} = "ElectricityCalculator_Undefine";
  52. $hash->{GetFn} = "ElectricityCalculator_Get";
  53. $hash->{SetFn} = "ElectricityCalculator_Set";
  54. $hash->{AttrFn} = "ElectricityCalculator_Attr";
  55. $hash->{NotifyFn} = "ElectricityCalculator_Notify";
  56. $hash->{DbLog_splitFn} = "ElectricityCalculator_DbLog_splitFn";
  57. $hash->{NotifyOrderPrefix} = "10-"; # Want to be called before the rest
  58. $hash->{AttrList} = "disable:0,1 " .
  59. "header " .
  60. "ElectricityCounterOffset " .
  61. "ElectricityKwhPerCounts " .
  62. "BasicPricePerAnnum " .
  63. "ElectricityPricePerKWh " .
  64. "MonthlyPayment " .
  65. "MonthOfAnnualReading " .
  66. "ReadingDestination:CalculatorDevice,CounterDevice " .
  67. "SiPrefixPower:W,kW,MW,GW " .
  68. "Currency:&#8364;,&#163;,&#36; " .
  69. $readingFnAttributes;
  70. }
  71. ####END####### Initialize module ###############################################################################END#####
  72. ###START###### Activate module after module has been used via fhem command "define" ##########################START####
  73. sub ElectricityCalculator_Define($$$)
  74. {
  75. my ($hash, $def) = @_;
  76. my ($name, $type, $RegEx, $RegExst) = split("[ \t]+", $def, 4);
  77. ### Check whether regular expression has correct syntax
  78. if(!$RegEx || $RegExst)
  79. {
  80. my $msg = "Wrong syntax: define <name> ElectricityCalculator device[:event]";
  81. return $msg;
  82. }
  83. ### Check whether regular expression is misleading
  84. eval { "Hallo" =~ m/^$RegEx$/ };
  85. return "Bad regexp: $@" if($@);
  86. $hash->{REGEXP} = $RegEx;
  87. ### Writing values to global hash
  88. notifyRegexpChanged($hash, $RegEx);
  89. $hash->{NAME} = $name;
  90. $hash->{STATE} = "active";
  91. $hash->{REGEXP} = $RegEx;
  92. if(defined($attr{$hash}{SiPrefixPower}))
  93. {
  94. if ($attr{$hash}{SiPrefixPower} eq "W" ) {$hash->{system}{SiPrefixPowerFactor} = 1 ;}
  95. elsif ($attr{$hash}{SiPrefixPower} eq "kW") {$hash->{system}{SiPrefixPowerFactor} = 1000 ;}
  96. elsif ($attr{$hash}{SiPrefixPower} eq "MW") {$hash->{system}{SiPrefixPowerFactor} = 1000000 ;}
  97. elsif ($attr{$hash}{SiPrefixPower} eq "GW") {$hash->{system}{SiPrefixPowerFactor} = 1000000000 ;}
  98. else {$hash->{system}{SiPrefixPowerFactor} = 1 ;}
  99. }
  100. else
  101. {
  102. $hash->{system}{SiPrefixPowerFactor} = 1;
  103. }
  104. ### Writing log entry
  105. Log3 $name, 5, $name. " : ElectricityCalculator - Starting to define module";
  106. return undef;
  107. }
  108. ####END####### Activate module after module has been used via fhem command "define" ############################END#####
  109. ###START###### Deactivate module module after "undefine" command by fhem ######################################START####
  110. sub ElectricityCalculator_Undefine($$)
  111. {
  112. my ($hash, $def) = @_;
  113. my $name = $hash->{NAME};
  114. Log3 $name, 3, $name. " ElectricityCalculator- The Electricity calculator has been undefined. Values corresponding to electricity meter will no longer calculated";
  115. return undef;
  116. }
  117. ####END####### Deactivate module module after "undefine" command by fhem #######################################END#####
  118. ###START###### Handle attributes after changes via fhem GUI ###################################################START####
  119. sub ElectricityCalculator_Attr(@)
  120. {
  121. my @a = @_;
  122. my $name = $a[1];
  123. my $hash = $defs{$name};
  124. ### Check whether "disable" attribute has been provided
  125. if ($a[2] eq "disable")
  126. {
  127. if ($a[3] eq 0)
  128. {
  129. $hash->{STATE} = "active";
  130. }
  131. elsif ($a[3] eq 1)
  132. {
  133. $hash->{STATE} = "disabled";
  134. }
  135. }
  136. ### Check whether "SiPrefixPower" attribute has been provided
  137. if ($a[2] eq "SiPrefixPower")
  138. {
  139. if ($a[3] eq "W" ) {$hash->{system}{SiPrefixPowerFactor} = 1 ;}
  140. elsif ($a[3] eq "kW") {$hash->{system}{SiPrefixPowerFactor} = 1000 ;}
  141. elsif ($a[3] eq "MW") {$hash->{system}{SiPrefixPowerFactor} = 1000000 ;}
  142. elsif ($a[3] eq "GW") {$hash->{system}{SiPrefixPowerFactor} = 1000000000 ;}
  143. else {$hash->{system}{SiPrefixPowerFactor} = 1 ;}
  144. }
  145. return undef;
  146. }
  147. ####END####### Handle attributes after changes via fhem GUI ####################################################END#####
  148. ###START###### Provide units for DbLog database via DbLog_splitFn #############################################START####
  149. sub ElectricityCalculator_DbLog_splitFn($$)
  150. {
  151. my ($event, $name) = @_;
  152. my ($reading, $value, $unit);
  153. my $hash = $defs{$name};
  154. my @argument = split("[ \t][ \t]*", $event);
  155. ### Delete ":" and everything behind in readings name
  156. $argument[0] =~ s/:.*//;
  157. ### Log entries for debugging
  158. Log3 $name, 5, $name. " : ElectricityCalculator_DbLog_splitFn - Content of event : " . $event;
  159. Log3 $name, 5, $name. " : ElectricityCalculator_splitFn - Content of argument[0] : " . $argument[0];
  160. Log3 $name, 5, $name. " : ElectricityCalculator_splitFn - Content of argument[1] : " . $argument[1];
  161. ### If the reading contains "_EnergyCost" or "_FinanceReserve"
  162. if (($argument[0] =~ /_EnergyCost/) || ($argument[0] =~ /_FinanceReserve/))
  163. {
  164. ### Log entries for debugging
  165. Log3 $name, 5, $name. " : ElectricityCalculator_DbLog_splitFn - EnergyCost-Reading detected : " . $argument[0];
  166. ### Get values being changed from hash
  167. $reading = $argument[0];
  168. $value = $argument[1];
  169. $unit = $attr{$hash}{Currency};
  170. }
  171. ### If the reading contains "_Power"
  172. elsif ($argument[0] =~ /_Power/)
  173. {
  174. ### Log entries for debugging
  175. Log3 $name, 5, $name. " : ElectricityCalculator_DbLog_splitFn - Power-Reading detected : " . $argument[0];
  176. ### Get values being changed from hash
  177. $reading = $argument[0];
  178. $value = $argument[1];
  179. $unit = $attr{$hash}{SiPrefixPower};
  180. }
  181. ### If the reading contains "_Counter" or "_Last" or ("_Energy" but not "_EnergyCost") or "_PrevRead"
  182. elsif (($argument[0] =~ /_Counter/) || ($argument[0] =~ /_Last/) || (($argument[0] =~ /_Energy/) && ($argument[0] !~ /_EnergyCost/)) || ($argument[0] =~ /_PrevRead/))
  183. {
  184. ### Log entries for debugging
  185. Log3 $name, 5, $name. " : ElectricityCalculator_DbLog_splitFn - Counter/Energy-Reading detected: " . $argument[0];
  186. ### Get values being changed from hash
  187. $reading = $argument[0];
  188. $value = $argument[1];
  189. $unit = "kWh";
  190. }
  191. ### If the reading is unknown
  192. else
  193. {
  194. ### Log entries for debugging
  195. Log3 $name, 5, $name. " : ElectricityCalculator_DbLog_splitFn - unspecified-Reading detected : " . $argument[0];
  196. ### Get values being changed from hash
  197. $reading = $argument[0];
  198. $value = $argument[1];
  199. $unit = "";
  200. }
  201. return ($reading, $value, $unit);
  202. }
  203. ####END####### Provide units for DbLog database via DbLog_splitFn ##############################################END#####
  204. ###START###### Manipulate reading after "get" command by fhem #################################################START####
  205. sub ElectricityCalculator_Get($@)
  206. {
  207. my ( $hash, @a ) = @_;
  208. ### If not enough arguments have been provided
  209. if ( @a < 2 )
  210. {
  211. return "\"get ElectricityCalculator\" needs at least one argument";
  212. }
  213. my $ElectricityCalcName = shift @a;
  214. my $reading = shift @a;
  215. my $value;
  216. my $ReturnMessage;
  217. if(!defined($hash->{helper}{gets}{$reading}))
  218. {
  219. my @cList = keys %{$hash->{helper}{gets}};
  220. return "Unknown argument $reading, choose one of " . join(" ", @cList);
  221. ### Create Log entries for debugging
  222. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - get list: " . join(" ", @cList);
  223. }
  224. if ( $reading ne "?")
  225. {
  226. ### Write current value
  227. $value = ReadingsVal($ElectricityCalcName, $reading, undef);
  228. ### Create Log entries for debugging
  229. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - get " . $reading . " with value: " . $value;
  230. ### Create ReturnMessage
  231. $ReturnMessage = $value;
  232. }
  233. return($ReturnMessage);
  234. }
  235. ####END####### Manipulate reading after "get" command by fhem ##################################################END#####
  236. ###START###### Manipulate reading after "set" command by fhem #################################################START####
  237. sub ElectricityCalculator_Set($@)
  238. {
  239. my ( $hash, @a ) = @_;
  240. ### If not enough arguments have been provided
  241. if ( @a < 2 )
  242. {
  243. return "\"set ElectricityCalculator\" needs at least one argument";
  244. }
  245. my $ElectricityCalcName = shift @a;
  246. my $reading = shift @a;
  247. my $value = join(" ", @a);
  248. my $ReturnMessage;
  249. if(!defined($hash->{helper}{gets}{$reading}))
  250. {
  251. my @cList = keys %{$hash->{helper}{sets}};
  252. return "Unknown argument $reading, choose one of " . join(" ", @cList);
  253. ### Create Log entries for debugging
  254. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - set list: " . join(" ", @cList);
  255. }
  256. if ( $reading ne "?")
  257. {
  258. ### Create Log entries for debugging
  259. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - set " . $reading . " with value: " . $value;
  260. ### Write current value
  261. readingsSingleUpdate($hash, $reading, $value, 1);
  262. ### Create ReturnMessage
  263. $ReturnMessage = $ElectricityCalcName . " - Successfully set " . $reading . " with value: " . $value;
  264. }
  265. return($ReturnMessage);
  266. }
  267. ####END####### Manipulate reading after "set" command by fhem ##################################################END#####
  268. ###START###### Calculate Electricity meter values on changed events ###################################################START####
  269. sub ElectricityCalculator_Notify($$)
  270. {
  271. ### Define variables
  272. my ($ElectricityCalcDev, $ElectricityCountDev) = @_;
  273. my $ElectricityCalcName = $ElectricityCalcDev->{NAME};
  274. my $ElectricityCountName = $ElectricityCountDev->{NAME};
  275. my $ElectricityCountNameEvents = deviceEvents($ElectricityCountDev, 1);
  276. my $NumberOfChangedEvents = int(@{$ElectricityCountNameEvents});
  277. my $RegEx = $ElectricityCalcDev->{REGEXP};
  278. ### Check whether the Electricity calculator has been disabled
  279. if(IsDisabled($ElectricityCalcName))
  280. {
  281. return "";
  282. }
  283. ### Check whether all required attributes has been provided and if not, create them with standard values
  284. if(!defined($attr{$ElectricityCalcName}{BasicPricePerAnnum}))
  285. {
  286. ### Set attribute with standard value since it is not available
  287. $attr{$ElectricityCalcName}{BasicPricePerAnnum} = 0;
  288. ### Writing log entry
  289. Log3 $ElectricityCalcName, 3, $ElectricityCalcName. " : ElectricityCalculator - The attribute BasicPricePerAnnum was missing and has been set to 0";
  290. }
  291. if(!defined($attr{$ElectricityCalcName}{ElectricityCounterOffset}))
  292. {
  293. ### Set attribute with standard value since it is not available
  294. $attr{$ElectricityCalcName}{ElectricityCounterOffset} = 0;
  295. ### Writing log entry
  296. Log3 $ElectricityCalcName, 3, $ElectricityCalcName. " : ElectricityCalculator - The attribute ElectricityCounterOffset was missing and has been set to 0";
  297. }
  298. if(!defined($attr{$ElectricityCalcName}{ElectricityKwhPerCounts}))
  299. {
  300. ### Set attribute with standard value since it is not available
  301. $attr{$ElectricityCalcName}{ElectricityKwhPerCounts} = 1;
  302. ### Writing log entry
  303. Log3 $ElectricityCalcName, 3, $ElectricityCalcName. " : ElectricityCalculator - The attribute ElectricityKwhPerCounts was missing and has been set to 1 counts/kWh";
  304. }
  305. if(!defined($attr{$ElectricityCalcName}{ElectricityPricePerKWh}))
  306. {
  307. ### Set attribute with standard value since it is not available
  308. $attr{$ElectricityCalcName}{ElectricityPricePerKWh} = 0.2567;
  309. ### Writing log entry
  310. Log3 $ElectricityCalcName, 3, $ElectricityCalcName. " : ElectricityCalculator - The attribute ElectricityPricePerKWh was missing and has been set to 0.2567 currency-unit/electric Energy-unit";
  311. }
  312. if(!defined($attr{$ElectricityCalcName}{MonthlyPayment}))
  313. {
  314. ### Set attribute with standard value since it is not available
  315. $attr{$ElectricityCalcName}{MonthlyPayment} = 0;
  316. ### Writing log entry
  317. Log3 $ElectricityCalcName, 3, $ElectricityCalcName. " : ElectricityCalculator - The attribute MonthlyPayment was missing and has been set to 0 currency-units";
  318. }
  319. if(!defined($attr{$ElectricityCalcName}{MonthOfAnnualReading}))
  320. {
  321. ### Set attribute with standard value since it is not available
  322. $attr{$ElectricityCalcName}{MonthOfAnnualReading} = 5;
  323. ### Writing log entry
  324. Log3 $ElectricityCalcName, 3, $ElectricityCalcName. " : ElectricityCalculator - The attribute MonthOfAnnualReading was missing and has been set to 5 which is the month May";
  325. }
  326. if(!defined($attr{$ElectricityCalcName}{Currency}))
  327. {
  328. ### Set attribute with standard value since it is not available
  329. $attr{$ElectricityCalcName}{Currency} = "&#8364;";
  330. ### Writing log entry
  331. Log3 $ElectricityCalcName, 3, $ElectricityCalcName. " : ElectricityCalculator - The attribute Currency was missing and has been set to &#8364;";
  332. }
  333. if(!defined($attr{$ElectricityCalcName}{SiPrefixPower}))
  334. {
  335. ### Set attribute with standard value since it is not available
  336. $attr{$ElectricityCalcName}{SiPrefixPower} = "W";
  337. $ElectricityCalcDev->{system}{SiPrefixPowerFactor} = 1;
  338. ### Writing log entry
  339. Log3 $ElectricityCalcName, 3, $ElectricityCalcName. " : ElectricityCalculator - The attribute SiPrefixPower was missing and has been set to W";
  340. }
  341. if(!defined($attr{$ElectricityCalcName}{ReadingDestination}))
  342. {
  343. ### Set attribute with standard value since it is not available
  344. $attr{$ElectricityCalcName}{ReadingDestination} = "CalculatorDevice";
  345. ### Writing log entry
  346. Log3 $ElectricityCalcName, 3, $ElectricityCalcName. " : ElectricityCalculator - The attribute ReadingDestination was missing and has been set to CalculatorDevice";
  347. }
  348. if(!defined($attr{$ElectricityCalcName}{room}))
  349. {
  350. if(defined($attr{$ElectricityCountName}{room}))
  351. {
  352. ### Set attribute with standard value since it is not available
  353. $attr{$ElectricityCalcName}{room} = $attr{$ElectricityCountName}{room};
  354. ### Writing log entry
  355. Log3 $ElectricityCalcName, 3, $ElectricityCalcName. " : ElectricityCalculator - The attribute room was missing and has been set to the same room of the electricity meter: " . $attr{$ElectricityCountName}{room};
  356. }
  357. else
  358. {
  359. ### Set attribute with standard value since it is not available
  360. $attr{$ElectricityCalcName}{room} = "Electric Energy Counter";
  361. ### Writing log entry
  362. Log3 $ElectricityCalcName, 3, $ElectricityCalcName. " : ElectricityCalculator - The attribute room was missing and has been set to Electric Energy Counter";
  363. }
  364. }
  365. ### For each feedback on in the array of defined regexpression which has been changed
  366. for (my $i = 0; $i < $NumberOfChangedEvents; $i++)
  367. {
  368. ### Extract event
  369. my $s = $ElectricityCountNameEvents->[$i];
  370. ### Filtering all events which do not match the defined regex
  371. if(!defined($s))
  372. {
  373. next;
  374. }
  375. my ($ElectricityCountReadingName, $ElectricityCountReadingValueCurrent) = split(": ", $s, 2); # resets $1
  376. if("$ElectricityCountName:$s" !~ m/^$RegEx$/)
  377. {
  378. next;
  379. }
  380. ### Extracting value
  381. if(defined($1))
  382. {
  383. my $RegExArg = $1;
  384. if(defined($2))
  385. {
  386. $ElectricityCountReadingName = $1;
  387. $RegExArg = $2;
  388. }
  389. $ElectricityCountReadingValueCurrent = $RegExArg if(defined($RegExArg) && $RegExArg =~ m/^(-?\d+\.?\d*)/);
  390. }
  391. if(!defined($ElectricityCountReadingValueCurrent) || $ElectricityCountReadingValueCurrent !~ m/^(-?\d+\.?\d*)/)
  392. {
  393. next;
  394. }
  395. ###Get current Counter and transform in electric Energy (kWh) as read on mechanic Electricity meter
  396. $ElectricityCountReadingValueCurrent = $1 * $attr{$ElectricityCalcName}{ElectricityKwhPerCounts} + $attr{$ElectricityCalcName}{ElectricityCounterOffset};
  397. my $ElectricityCountReadingTimestampCurrent = ReadingsTimestamp($ElectricityCountName,$ElectricityCountReadingName,0);
  398. ### Create Log entries for debugging
  399. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator Begin_______________________________________________________________________________________________________________________________";
  400. ### Create name and destination device for general reading prefix
  401. my $ElectricityCalcReadingPrefix;
  402. my $ElectricityCalcReadingDestinationDevice;
  403. my $ElectricityCalcReadingDestinationDeviceName;
  404. if ($attr{$ElectricityCalcName}{ReadingDestination} eq "CalculatorDevice")
  405. {
  406. $ElectricityCalcReadingPrefix = ($ElectricityCountName . "_" . $ElectricityCountReadingName);
  407. $ElectricityCalcReadingDestinationDevice = $ElectricityCalcDev;
  408. $ElectricityCalcReadingDestinationDeviceName = $ElectricityCalcName;
  409. ### Create Log entries for debugging
  410. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - Attribut ReadingDestination has been set to CalculatorDevice";
  411. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCalcReadingPrefix : " . $ElectricityCalcReadingPrefix;
  412. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCalcReadingDestinationDevice : " . $ElectricityCalcReadingDestinationDevice;
  413. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCalcReadingDestinationDeviceName : " . $ElectricityCalcReadingDestinationDeviceName;
  414. }
  415. elsif ($attr{$ElectricityCalcName}{ReadingDestination} eq "CounterDevice")
  416. {
  417. $ElectricityCalcReadingPrefix = $ElectricityCountReadingName;
  418. $ElectricityCalcReadingDestinationDevice = $ElectricityCountDev;
  419. $ElectricityCalcReadingDestinationDeviceName = $ElectricityCountName;
  420. ### Create Log entries for debugging
  421. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - Attribut ReadingDestination has been set to CounterDevice";
  422. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCalcReadingPrefix : " . $ElectricityCalcReadingPrefix;
  423. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCalcReadingDestinationDevice : " . $ElectricityCalcReadingDestinationDevice;
  424. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCalcReadingDestinationDeviceName : " . $ElectricityCalcReadingDestinationDeviceName;
  425. }
  426. else
  427. {
  428. ### Create Log entries for debugging
  429. Log3 $ElectricityCalcName, 3, $ElectricityCalcName. " : ElectricityCalculator - Attribut ReadingDestination has not been set up correctly. Skipping event.";
  430. ### Skipping event
  431. next;
  432. }
  433. ### Restore previous Counter and if not available define it with "undef"
  434. my $ElectricityCountReadingTimestampPrevious = ReadingsTimestamp($ElectricityCalcReadingDestinationDeviceName, "." . $ElectricityCalcReadingPrefix . "_PrevRead", undef);
  435. my $ElectricityCountReadingValuePrevious = ReadingsVal($ElectricityCalcReadingDestinationDeviceName, "." . $ElectricityCalcReadingPrefix . "_PrevRead", undef);
  436. ### Create Log entries for debugging
  437. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCountReadingValuePrevious : " . $ElectricityCountReadingValuePrevious;
  438. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCalcReadingPrefix_PrevRead : " . $ElectricityCalcReadingPrefix . "_PrevRead";
  439. ### Find out whether there has been a previous value being stored
  440. if(defined($ElectricityCountReadingValuePrevious))
  441. {
  442. ### Write current electric Energy as previous Electric Energy for future use in the ElectricityCalc-Device
  443. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, "." . $ElectricityCalcReadingPrefix. "_PrevRead", sprintf('%.3f', ($ElectricityCountReadingValueCurrent)),1);
  444. ### Create Log entries for debugging
  445. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - Previous value found. Continuing with calculations";
  446. }
  447. ### If not: save value and quit loop
  448. else
  449. {
  450. ### Write current electric Energy as previous Value for future use in the ElectricityCalc-Device
  451. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, "." . $ElectricityCalcReadingPrefix. "_PrevRead", sprintf('%.3f', ($ElectricityCountReadingValueCurrent)),1);
  452. ### Create Log entries for debugging
  453. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - Previous value NOT found. Skipping Loop";
  454. ### Jump out of loop since there is nothing to do anymore than to wait for the next value
  455. next;
  456. }
  457. ###### Find out whether the device has been freshly defined and certain readings have never been set up yet or certain readings have been deleted
  458. ### Find out whether the reading for the daily start value has not been written yet
  459. if(!defined(ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_CounterDay1st", undef)))
  460. {
  461. ### Save current electric Energy as first reading of day = first after midnight and reset min, max value, value counter and value sum
  462. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_CounterDay1st", $ElectricityCountReadingValueCurrent, 1);
  463. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_CounterDayLast", $ElectricityCountReadingValuePrevious, 1);
  464. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, "." . $ElectricityCalcReadingPrefix . "_PowerDaySum", 0, 1);
  465. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, "." . $ElectricityCalcReadingPrefix . "_PowerDayCount", 0, 1);
  466. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_PowerDayMin", 0, 1);
  467. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_PowerDayMax", 0, 1);
  468. ### Create Log entries for debugging
  469. Log3 $ElectricityCalcName, 3, $ElectricityCalcName. " : ElectricityCalculator - Reading for the first daily value was not available and therfore reading and statistics have been written";
  470. }
  471. ### Find out whether the reading for the monthly start value has not been written yet
  472. if(!defined(ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_CounterMonth1st", undef)))
  473. {
  474. ### Save current electric Energy as first reading of month
  475. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_CounterMonth1st", $ElectricityCountReadingValueCurrent, 1);
  476. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_CounterMonthLast", $ElectricityCountReadingValuePrevious, 1);
  477. ### Create Log entries for debugging
  478. Log3 $ElectricityCalcName, 3, $ElectricityCalcName. " : ElectricityCalculator - Reading for the first monthly value was not available and therfore reading has been written";
  479. }
  480. ### Find out whether the reading for the meter reading year value has not been written yet
  481. if(!defined(ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_CounterMeter1st", undef)))
  482. {
  483. ### Save current electric Energy as first reading of month where Electricity-meter is read
  484. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_CounterMeter1st", $ElectricityCountReadingValueCurrent, 1);
  485. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_CounterMeterLast", $ElectricityCountReadingValuePrevious, 1);
  486. ### Create Log entries for debugging
  487. Log3 $ElectricityCalcName, 3, $ElectricityCalcName. " : ElectricityCalculator - Reading for the first value of Electricity meter year was not available and therfore reading has been written";
  488. }
  489. ### Find out whether the reading for the yearly value has not been written yet
  490. if(!defined(ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_CounterYear1st", undef)))
  491. {
  492. ### Save current electric Energy as first reading of the calendar year
  493. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_CounterYear1st", $ElectricityCountReadingValueCurrent, 1);
  494. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_CounterYearLast", $ElectricityCountReadingValuePrevious, 1);
  495. ### Create Log entries for debugging
  496. Log3 $ElectricityCalcName, 3, $ElectricityCalcName. " : ElectricityCalculator - Reading for the first yearly value was not available and therfore reading has been written";
  497. }
  498. ### Extracting year, month and day as numbers
  499. my $ElectricityCountReadingTimestampPreviousRelative = time_str2num($ElectricityCountReadingTimestampPrevious);
  500. my($ElectricityCountReadingTimestampPreviousSec,$ElectricityCountReadingTimestampPreviousMin,$ElectricityCountReadingTimestampPreviousHour,$ElectricityCountReadingTimestampPreviousMday,$ElectricityCountReadingTimestampPreviousMon,$ElectricityCountReadingTimestampPreviousYear,$ElectricityCountReadingTimestampPreviousWday,$ElectricityCountReadingTimestampPreviousYday,$ElectricityCountReadingTimestampPreviousIsdst) = localtime($ElectricityCountReadingTimestampPreviousRelative);
  501. my $ElectricityCountReadingTimestampCurrentRelative = time_str2num($ElectricityCountReadingTimestampCurrent);
  502. my($ElectricityCountReadingTimestampCurrentSec,$ElectricityCountReadingTimestampCurrentMin,$ElectricityCountReadingTimestampCurrentHour,$ElectricityCountReadingTimestampCurrentMday,$ElectricityCountReadingTimestampCurrentMon,$ElectricityCountReadingTimestampCurrentYear,$ElectricityCountReadingTimestampCurrentWday,$ElectricityCountReadingTimestampCurrentYday,$ElectricityCountReadingTimestampCurrentIsdst) = localtime($ElectricityCountReadingTimestampCurrentRelative);
  503. ### Correct current month by one month since Unix/Linux start January with 0 instead of 1
  504. $ElectricityCountReadingTimestampCurrentMon = $ElectricityCountReadingTimestampCurrentMon + 1;
  505. ### Create Log entries for debugging
  506. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - Reading Name : " . $ElectricityCountReadingName;
  507. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - Previous Reading Value : " . $ElectricityCountReadingTimestampPrevious;
  508. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - Current Reading Value : " . $ElectricityCountReadingTimestampCurrent;
  509. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - Previous Reading Value : " . $ElectricityCountReadingValuePrevious;
  510. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - Current Reading Value : " . $ElectricityCountReadingValueCurrent;
  511. ####### Check whether Initial readings needs to be written
  512. ### Check whether the current value is the first one after change of day = First one after midnight
  513. if ($ElectricityCountReadingTimestampCurrentHour < $ElectricityCountReadingTimestampPreviousHour)
  514. {
  515. ### Create Log entries for debugging
  516. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - First reading of day detected";
  517. ### Calculate Electricity energy of previous day € = (Wprevious[kWh] - WcurrentDay[kWh])
  518. my $ElectricityCalcEnergyDayLast = ($ElectricityCountReadingValuePrevious - ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_CounterDay1st", "0"));
  519. ### Calculate pure Electricity cost of previous day ElectricityCalcEnergyDayLast * Price per kWh
  520. my $ElectricityCalcEnergyCostDayLast = $ElectricityCalcEnergyDayLast * $attr{$ElectricityCalcName}{ElectricityPricePerKWh};
  521. ### Reload last Power Value
  522. my $ElectricityCalcPowerCurrent = ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_PowerCurrent", "0");
  523. ### Save Electricity pure cost of previous day, current electric Energy as first reading of day = first after midnight and reset min, max value, value counter and value sum
  524. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_EnergyCostDayLast", (sprintf('%.3f', ($ElectricityCalcEnergyCostDayLast ))), 1);
  525. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_EnergyDayLast", (sprintf('%.3f', ($ElectricityCalcEnergyDayLast ))), 1);
  526. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_CounterDay1st", (sprintf('%.3f', ($ElectricityCountReadingValueCurrent ))), 1);
  527. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_CounterDayLast", (sprintf('%.3f', ($ElectricityCountReadingValuePrevious ))), 1);
  528. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, "." . $ElectricityCalcReadingPrefix . "_PowerDaySum", 0 , 1);
  529. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, "." . $ElectricityCalcReadingPrefix . "_PowerDayCount", 0 , 1);
  530. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_PowerDayMin", (sprintf('%.3f', ($ElectricityCalcPowerCurrent ))), 1);
  531. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_PowerDayMax", 0 , 1);
  532. ### Check whether the current value is the first one after change of month
  533. if ($ElectricityCountReadingTimestampCurrentMday < $ElectricityCountReadingTimestampPreviousMday)
  534. {
  535. ### Create Log entries for debugging
  536. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - First reading of month detected";
  537. ### Calculate Electricity energy of previous month € = (Wprevious[kWh] - W1stReadMonth[kWh])
  538. my $ElectricityCalcEnergyMonthLast = ($ElectricityCountReadingValuePrevious - ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_CounterMonth1st", "0"));
  539. ### Calculate pure Electricity cost of previous month ElectricityCalcEnergyMonthLast * Price per kWh
  540. my $ElectricityCalcEnergyCostMonthLast = $ElectricityCalcEnergyMonthLast * $attr{$ElectricityCalcName}{ElectricityPricePerKWh};
  541. ### Save Electricity energy and pure cost of previous month
  542. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_EnergyCostMonthLast", (sprintf('%.3f', ($ElectricityCalcEnergyCostMonthLast ))), 1);
  543. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_EnergyMonthLast", (sprintf('%.3f', ($ElectricityCalcEnergyMonthLast ))), 1);
  544. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_CounterMonth1st", (sprintf('%.3f', ($ElectricityCountReadingValueCurrent ))), 1);
  545. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_CounterMonthLast", (sprintf('%.3f', ($ElectricityCountReadingValuePrevious ))), 1);
  546. ### Check whether the current value is the first one of the meter-reading month
  547. if ($ElectricityCountReadingTimestampCurrentMon eq $attr{$ElectricityCalcName}{MonthOfAnnualReading})
  548. {
  549. ### Create Log entries for debugging
  550. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - First reading of month for meter reading detected";
  551. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - Current month is : " . $ElectricityCountReadingTimestampCurrentMon;
  552. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - Attribute MonthOfAnnualReading is : " . $attr{$ElectricityCalcName}{MonthOfAnnualReading};
  553. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - Counter1stMeter is : " . $ElectricityCountReadingValueCurrent;
  554. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - CounterLastMeter is : " . $ElectricityCountReadingValuePrevious;
  555. ### Calculate Electricity energy of previous meter reading year € = (Wprevious[kWh] - WcurrentMeter[kWh])
  556. my $ElectricityCalcEnergyMeterLast = ($ElectricityCountReadingValuePrevious - ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_CounterMeter1st", "0"));
  557. ### Calculate pure Electricity cost of previous meter reading year € = ElectricityCalcEnergyMeterLast * Price per kWh
  558. my $ElectricityCalcEnergyCostMeterLast = $ElectricityCalcEnergyMeterLast * $attr{$ElectricityCalcName}{ElectricityPricePerKWh};
  559. ### Save Electricity energy and pure cost of previous meter year
  560. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_EnergyCostMeterLast", (sprintf('%.3f', ($ElectricityCalcEnergyCostMeterLast ))), 1);
  561. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_EnergyMeterLast", (sprintf('%.3f', ($ElectricityCalcEnergyMeterLast ))), 1);
  562. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_CounterMeter1st", (sprintf('%.3f', ($ElectricityCountReadingValueCurrent ))), 1);
  563. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_CounterMeterLast", (sprintf('%.3f', ($ElectricityCountReadingValuePrevious ))), 1);
  564. }
  565. ### Check whether the current value is the first one of the calendar year
  566. if ($ElectricityCountReadingTimestampCurrentYear > $ElectricityCountReadingTimestampPreviousYear)
  567. {
  568. ### Create Log entries for debugging
  569. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - First reading of calendar year detected";
  570. ### Calculate Electricity energy of previous calendar year € = (Wcurrent[kWh] - WcurrentYear[kWh])
  571. my $ElectricityCalcEnergyYearLast = ($ElectricityCountReadingValuePrevious - ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_CounterYear1st", "0"));
  572. ### Calculate pure Electricity cost of previous calendar year € = ElectricityCalcEnergyYearLast * Price per kWh
  573. my $ElectricityCalcEnergyCostYearLast = $ElectricityCalcEnergyYearLast * $attr{$ElectricityCalcName}{ElectricityPricePerKWh};
  574. ### Save Electricity energy and pure cost of previous calendar year
  575. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_EnergyCostYearLast", (sprintf('%.3f', ($ElectricityCalcEnergyCostYearLast ))), 1);
  576. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_EnergyYearLast", (sprintf('%.3f', ($ElectricityCalcEnergyYearLast ))), 1);
  577. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_CounterYear1st", (sprintf('%.3f', ($ElectricityCountReadingValueCurrent ))), 1);
  578. readingsSingleUpdate( $ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_CounterYearLast", (sprintf('%.3f', ($ElectricityCountReadingValuePrevious ))), 1);
  579. }
  580. }
  581. }
  582. ###### Do calculations
  583. ### Calculate DtCurrent (time difference) of previous and current timestamp / [s]
  584. my $ElectricityCountReadingTimestampDelta = $ElectricityCountReadingTimestampCurrentRelative - $ElectricityCountReadingTimestampPreviousRelative;
  585. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCountReadingTimestampDelta : " . $ElectricityCountReadingTimestampDelta . " s";
  586. ### Continue with calculations only if time difference is larger than 1 seconds to avoid "Illegal division by zero" and erroneous due to small values for divisor
  587. if ($ElectricityCountReadingTimestampDelta > 1)
  588. {
  589. ### Calculate DW (electric Energy difference) of previous and current value / [kWh]
  590. my $ElectricityCountReadingValueDelta = sprintf('%.3f', ($ElectricityCountReadingValueCurrent - $ElectricityCountReadingValuePrevious));
  591. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCountReadingValueDelta : " . $ElectricityCountReadingValueDelta;
  592. ### Calculate Current Power P = DW/Dt[kWh/s] * 3600[s/h] * 1000 [1/k] / SiPrefixPowerFactor
  593. my $ElectricityCalcPowerCurrent = ($ElectricityCountReadingValueDelta / $ElectricityCountReadingTimestampDelta) * 3600 * 1000 / $ElectricityCalcDev->{system}{SiPrefixPowerFactor};
  594. ### Calculate daily sum of power measurements "SP" and measurement counts "n" and then calculate average Power "Paverage = SP/n"
  595. my $ElectricityCalcPowerDaySum = ReadingsVal($ElectricityCalcReadingDestinationDeviceName, "." . $ElectricityCalcReadingPrefix . "_PowerDaySum", "0") + $ElectricityCalcPowerCurrent;
  596. my $ElectricityCalcPowerDayCount = ReadingsVal($ElectricityCalcReadingDestinationDeviceName, "." . $ElectricityCalcReadingPrefix . "_PowerDayCount", "0") + 1;
  597. my $ElectricityCalcPowerDayAverage = $ElectricityCalcPowerDaySum / $ElectricityCalcPowerDayCount;
  598. ### Calculate consumed Energy of current day W = (Wcurrent[kWh] - W1stReadDay[kWh])
  599. my $ElectricityCalcEnergyDay = ($ElectricityCountReadingValueCurrent - ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_CounterDay1st", "0"));
  600. ### Calculate consumed Energy of current month W = (Wcurrent[kWh] - W1stReadMonth[kWh])
  601. my $ElectricityCalcEnergyMonth = ($ElectricityCountReadingValueCurrent - ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_CounterMonth1st", "0"));
  602. ### Calculate consumed Energy of current year W = (Wcurrent[kWh] - W1stReadYear[kWh])
  603. my $ElectricityCalcEnergyYear = ($ElectricityCountReadingValueCurrent - ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_CounterYear1st", "0"));
  604. ### Calculate consumed Energy of Electricity-meter year W = (Wcurrent[kWh] - W1stReadMeter[kWh])
  605. my $ElectricityCalcEnergyMeter = ($ElectricityCountReadingValueCurrent - ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_CounterMeter1st", "0"));
  606. ### Calculate pure Electricity cost since midnight
  607. my $ElectricityCalcEnergyCostDay = $ElectricityCalcEnergyDay * $attr{$ElectricityCalcName}{ElectricityPricePerKWh};
  608. ### Calculate pure Electricity cost since first day of month
  609. my $ElectricityCalcEnergyCostMonth = $ElectricityCalcEnergyMonth * $attr{$ElectricityCalcName}{ElectricityPricePerKWh};
  610. ### Calculate pure Electricity cost since first day of calendar year
  611. my $ElectricityCalcEnergyCostYear = $ElectricityCalcEnergyYear * $attr{$ElectricityCalcName}{ElectricityPricePerKWh};
  612. ### Calculate pure Electricity cost since first day of Electricity meter reading year
  613. my $ElectricityCalcEnergyCostMeter = $ElectricityCalcEnergyMeter * $attr{$ElectricityCalcName}{ElectricityPricePerKWh};
  614. ### Calculate the payment month since the year of Electricity meter reading started
  615. my $ElectricityCalcMeterYearMonth=0;
  616. if (($ElectricityCountReadingTimestampCurrentMon - $attr{$ElectricityCalcName}{MonthOfAnnualReading} + 1) < 1)
  617. {
  618. $ElectricityCalcMeterYearMonth = 13 + $ElectricityCountReadingTimestampCurrentMon - $attr{$ElectricityCalcName}{MonthOfAnnualReading};
  619. }
  620. else
  621. {
  622. $ElectricityCalcMeterYearMonth = 1 + $ElectricityCountReadingTimestampCurrentMon - $attr{$ElectricityCalcName}{MonthOfAnnualReading};
  623. }
  624. ### Calculate reserves at electricity supplier based on monthly advance payments within year of Electricity meter reading
  625. my $ElectricityCalcReserves = ($ElectricityCalcMeterYearMonth * $attr{$ElectricityCalcName}{MonthlyPayment}) - ($attr{$ElectricityCalcName}{BasicPricePerAnnum} / 12 * $ElectricityCalcMeterYearMonth) - $ElectricityCalcEnergyCostMeter;
  626. ### Create Log entries for debugging
  627. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - _______Finance________________________________________";
  628. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - Monthly Payment : " . $attr{$ElectricityCalcName}{MonthlyPayment} . " " . $attr{$ElectricityCalcName}{Currency};
  629. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - Basic price per annum : " . $attr{$ElectricityCalcName}{BasicPricePerAnnum} . " " . $attr{$ElectricityCalcName}{Currency};
  630. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCalcEnergyCostMeter : " . sprintf('%.3f', ($ElectricityCalcEnergyCostMeter)) . " " . $attr{$ElectricityCalcName}{Currency};
  631. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCalcReserves : " . sprintf('%.3f', ($ElectricityCalcReserves)) . " " . $attr{$ElectricityCalcName}{Currency};
  632. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - _______Times__________________________________________";
  633. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCalcMeterYearMonth : " . $ElectricityCalcMeterYearMonth;
  634. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - Current Month : " . $ElectricityCountReadingTimestampCurrentMon;
  635. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - _______Energy_________________________________________";
  636. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCalcEnergyDay : " . sprintf('%.3f', ($ElectricityCalcEnergyDay)) . " kWh";
  637. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCalcEnergyMonth : " . sprintf('%.3f', ($ElectricityCalcEnergyMonth)) . " kWh";
  638. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCalcEnergyYear : " . sprintf('%.3f', ($ElectricityCalcEnergyYear)) . " kWh";
  639. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCalcEnergyMeter : " . sprintf('%.3f', ($ElectricityCalcEnergyMeter)) . " kWh";
  640. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - _______Power___________________________________________";
  641. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCalcPowerCurrent : " . sprintf('%.3f', ($ElectricityCalcPowerCurrent)) . " W";
  642. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCalcPowerDayMin : " . ReadingsVal( $ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_PowerDayMin", 0) . " W";
  643. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCalcPowerDayAverage : " . sprintf('%.3f', ($ElectricityCalcPowerDayAverage)) . " W";
  644. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCalcPowerDayMax : " . ReadingsVal( $ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_PowerDayMax", 0) . " W";
  645. ###### Write readings to ElectricityCalc device
  646. ### Initialize Bulkupdate
  647. readingsBeginUpdate($ElectricityCalcReadingDestinationDevice);
  648. ### Write consumed electric Energy (DV) since last measurement
  649. readingsBulkUpdate($ElectricityCalcReadingDestinationDevice, "." . $ElectricityCalcReadingPrefix . "_LastDV", sprintf('%.3f', ($ElectricityCountReadingValueDelta)));
  650. ### Write timelap (Dt) since last measurement
  651. readingsBulkUpdate($ElectricityCalcReadingDestinationDevice, "." . $ElectricityCalcReadingPrefix . "_LastDt", sprintf('%.0f', ($ElectricityCountReadingTimestampDelta)));
  652. ### Write current Power = average Power over last measurement period
  653. readingsBulkUpdate($ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_PowerCurrent", sprintf('%.3f', ($ElectricityCalcPowerCurrent)));
  654. ### Write daily Power = average Power since midnight
  655. readingsBulkUpdate($ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_PowerDayAver", sprintf('%.3f', ($ElectricityCalcPowerDayAverage)));
  656. ### Write Power measurement sum since midnight for average calculation
  657. readingsBulkUpdate($ElectricityCalcReadingDestinationDevice, "." . $ElectricityCalcReadingPrefix . "_PowerDaySum", sprintf('%.3f', ($ElectricityCalcPowerDaySum)));
  658. ### Write Power measurement counts since midnight for average calculation
  659. readingsBulkUpdate($ElectricityCalcReadingDestinationDevice, "." . $ElectricityCalcReadingPrefix . "_PowerDayCount", sprintf('%.0f', ($ElectricityCalcPowerDayCount)));
  660. ### Detect new daily minimum power value and write to reading
  661. if (ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_PowerDayMin", 0) > $ElectricityCalcPowerCurrent)
  662. {
  663. ### Write new minimum Power value
  664. readingsBulkUpdate($ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_PowerDayMin", sprintf('%.0f', ($ElectricityCalcPowerCurrent)));
  665. ### Create Log entries for debugging
  666. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - New daily minimum power value detected : " . sprintf('%.3f', ($ElectricityCalcPowerCurrent));
  667. }
  668. ### Detect new daily maximum power value and write to reading
  669. if (ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_PowerDayMax", 0) < $ElectricityCalcPowerCurrent)
  670. {
  671. ### Write new maximum Power value
  672. readingsBulkUpdate($ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_PowerDayMax", sprintf('%.3f', ($ElectricityCalcPowerCurrent)));
  673. ### Create Log entries for debugging
  674. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - New daily maximum power value detected : " . sprintf('%.3f', ($ElectricityCalcPowerCurrent));
  675. }
  676. ### Write energy consumption since midnight
  677. readingsBulkUpdate($ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_EnergyDay", sprintf('%.3f', ($ElectricityCalcEnergyDay)));
  678. ### Write energy consumption since beginning of month
  679. readingsBulkUpdate($ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_EnergyMonth", sprintf('%.3f', ($ElectricityCalcEnergyMonth)));
  680. ### Write energy consumption since beginning of year
  681. readingsBulkUpdate($ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_EnergyYear", sprintf('%.3f', ($ElectricityCalcEnergyYear)));
  682. ### Write energy consumption since last meter reading
  683. readingsBulkUpdate($ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_EnergyMeter", sprintf('%.3f', ($ElectricityCalcEnergyMeter)));
  684. ### Write pure energy costs since midnight
  685. readingsBulkUpdate($ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_EnergyCostDay", sprintf('%.3f', ($ElectricityCalcEnergyCostDay)));
  686. ### Write pure energy costs since beginning of month
  687. readingsBulkUpdate($ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_EnergyCostMonth", sprintf('%.3f', ($ElectricityCalcEnergyCostMonth)));
  688. ### Write pure energy costs since beginning of calendar year
  689. readingsBulkUpdate($ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_EnergyCostYear", sprintf('%.3f', ($ElectricityCalcEnergyCostYear)));
  690. ### Write pure energy costs since beginning of year of Electricity meter reading
  691. readingsBulkUpdate($ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_EnergyCostMeter", sprintf('%.3f', ($ElectricityCalcEnergyCostMeter)));
  692. ### Write reserves at electricity supplier based on monthly advance payments within year of Electricity meter reading
  693. readingsBulkUpdate($ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_FinanceReserve", sprintf('%.3f', ($ElectricityCalcReserves)));
  694. ### Write current meter reading as sshown on the mechanical meter
  695. readingsBulkUpdate($ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_CounterCurrent", sprintf('%.3f', ($ElectricityCountReadingValueCurrent)));
  696. ### Write months since last meter reading
  697. readingsBulkUpdate($ElectricityCalcReadingDestinationDevice, $ElectricityCalcReadingPrefix . "_MonthMeterReading", sprintf('%.0f', ($ElectricityCalcMeterYearMonth)));
  698. ### Finish and execute Bulkupdate
  699. readingsEndUpdate($ElectricityCalcReadingDestinationDevice, 1);
  700. }
  701. else
  702. {
  703. ### Create Log entries for debugging
  704. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCountReadingTimestampDelta = $ElectricityCountReadingTimestampDelta. Calculations skipped!";
  705. }
  706. ### Create Log entries for debugging
  707. Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator End_________________________________________________________________________________________________________________________________";
  708. }
  709. ### If readings exist, update list of available readings
  710. if($ElectricityCalcDev->{READINGS})
  711. {
  712. ### Copy readings in list of available "gets" and "sets"
  713. %{$ElectricityCalcDev->{helper}{gets}} = %{$ElectricityCalcDev->{READINGS}};
  714. %{$ElectricityCalcDev->{helper}{sets}} = %{$ElectricityCalcDev->{READINGS}};
  715. ### Create Log entries for debugging
  716. #Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - notify x_sets list: " . join(" ", (keys %{$ElectricityCalcDev->{helper}{sets}}));
  717. }
  718. return undef;
  719. }
  720. ####END####### Calculate Electricity meter values on changed events ####################################################END#####
  721. 1;
  722. ###START###### Description for fhem commandref ################################################################START####
  723. =pod
  724. =item helper
  725. =item summary Calculates the electrical energy consumption and costs
  726. =item summary_DE Berechnet den Energieverbrauch und verbundene Kosten
  727. =begin html
  728. <a name="ElectricityCalculator"></a>
  729. <h3>ElectricityCalculator</h3>
  730. <ul>
  731. <table>
  732. <tr>
  733. <td>
  734. The ElectricityCalculator Module calculates the electrical energy consumption and costs of one ore more electricity meters.<BR>
  735. It is not a counter module itself but it requires a regular expression (regex or regexp) in order to know where to retrieve the counting ticks of one or more mechanical or electronic electricity meter.<BR>
  736. <BR>
  737. As soon the module has been defined within the fhem.cfg, the module reacts on every event of the specified counter like myOWDEVICE:counter.* etc.<BR>
  738. <BR>
  739. The ElectricityCalculator module provides several current, historical, statistical values around with respect to one or more electricity meter and creates respective readings.<BR>
  740. <BR>
  741. To avoid waiting for max. 12 months to have realistic values, the readings <BR>
  742. <code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterDay1st</code>,<BR>
  743. <code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterMonth1st</code>,<BR>
  744. <code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterYear1st</code> and<BR>
  745. <code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterMeter1st</code><BR>
  746. must be corrected with real values by using the <code>setreading</code> - command.<BR>
  747. These real values may be found on the last electricity bill. Otherwise it will take 24h for the daily, 30days for the monthly and up to 12 month for the yearly values to become realistic.<BR>
  748. <BR>
  749. Intervalls smaller than 10s will be discarded to avoid peaks due to fhem blockages (e.g. DbLog - reducelog).
  750. <BR>
  751. </td>
  752. </tr>
  753. </table>
  754. <table><tr><td><a name="ElectricityCalculatorDefine"></a><b>Define</b></td></tr></table>
  755. <table><tr><td><ul><code>define &lt;name&gt; ElectricityCalculator &lt;regex&gt;</code></ul></td></tr></table>
  756. <ul><ul>
  757. <table>
  758. <tr><td><code>&lt;name&gt;</code> : </td><td>The name of the calculation device. (E.g.: "myElectricityCalculator")</td></tr>
  759. <tr><td><code>&lt;regex&gt;</code> : </td><td>A valid regular expression (also known as regex or regexp) of the event where the counter can be found</td></tr>
  760. </table>
  761. </ul></ul>
  762. <table><tr><td><ul>Example: <code>define myElectricityCalculator ElectricityCalculator myElectricityCounter:countersA.*</code></ul></td></tr></table>
  763. <BR>
  764. <table>
  765. <tr><td><a name="ElectricityCalculatorSet"></a><b>Set</b></td></tr>
  766. <tr><td>
  767. <ul>
  768. The set - function sets individual values for example to correct values after power loss etc.<BR>
  769. The set - function works only for readings which have been stored in the CalculatorDevice.<BR>
  770. The Readings being stored in the Counter - Device need to be changed individially with the <code>set</code> - command.<BR>
  771. </ul>
  772. </td></tr>
  773. </table>
  774. <BR>
  775. <table>
  776. <tr><td><a name="ElectricityCalculatorGet"></a><b>Get</b></td></tr>
  777. <tr><td>
  778. <ul>
  779. The get - function just returns the individual value of the reading.<BR>
  780. The get - function works only for readings which have been stored in the CalculatorDevice.<BR>
  781. The Readings being stored in the Counter - Device need to be read individially with <code>get</code> - command.<BR>
  782. </ul>
  783. </td></tr>
  784. </table>
  785. <BR>
  786. <table>
  787. <tr><td><a name="ElectricityCalculatorAttr"></a><b>Attributes</b></td></tr>
  788. <tr><td>
  789. <ul>
  790. If the below mentioned attributes have not been pre-defined completly beforehand, the program will create the ElectricityCalculator specific attributes with default values.<BR>
  791. In addition the global attributes e.g. <a href="#room">room</a> can be used.<BR>
  792. </ul>
  793. </td></tr>
  794. </table>
  795. <ul><ul>
  796. <table>
  797. <tr>
  798. <td>
  799. <tr><td><li><code>BasicPricePerAnnum</code> : </li></td><td> A valid float number for basic annual fee in the chosen currency for the electricity supply to the home.<BR>
  800. The value is provided by your local electricity supplier and is shown on your electricity bill.<BR>
  801. For UK and US users it may known under "standing charge". Please make sure it is based on one year!<BR>
  802. The default value is 0.00<BR>
  803. </td></tr>
  804. </td>
  805. </tr>
  806. </table>
  807. </ul></ul>
  808. <ul><ul>
  809. <table>
  810. <tr>
  811. <td>
  812. <tr><td><li><code>Currency</code> : </li></td><td> One of the pre-defined list of currency symbols [&#8364;,&#163;,&#36;].<BR>
  813. The default value is &#8364;<BR>
  814. </td></tr>
  815. </td>
  816. </tr>
  817. </table>
  818. </ul></ul>
  819. <ul><ul>
  820. <table>
  821. <tr>
  822. <td>
  823. <tr><td><li><code>disable</code> : </li></td><td> Disables the current module. The module will not react on any events described in the regular expression.<BR>
  824. The default value is 0 = enabled.<BR>
  825. </td></tr>
  826. </td>
  827. </tr>
  828. </table>
  829. </ul></ul>
  830. <ul><ul>
  831. <table>
  832. <tr>
  833. <td>
  834. <tr><td><li><code>ElectricityCounterOffset</code> : </li></td><td> A valid float number of the electric Energy difference = offset (not the difference of the counter ticks!) between the value shown on the mechanic meter for the electric energy and the calculated electric energy of the counting device.<BR>
  835. The value for this offset will be calculated as follows W<sub>Offset</sub> = W<sub>Mechanical</sub> - W<sub>Module</sub><BR>
  836. The default value is 0.00<BR>
  837. </td></tr>
  838. </td>
  839. </tr>
  840. </table>
  841. </ul></ul>
  842. <ul><ul>
  843. <table>
  844. <tr>
  845. <td>
  846. <tr><td><li><code>ElectricityKwhPerCounts</code> : </li></td><td> A valid float number of electric energy in kWh per counting ticks.<BR>
  847. The value is given by the mechanical trigger of the mechanical electricity meter. E.g. ElectricityKwhPerCounts = 0.001 means each count is a thousandth of one kWh (=Wh).<BR>
  848. Some electronic counter (E.g. HomeMatic HM-ES-TX-WM) providing the counted electric energy as Wh. Therfore this attribute must be 0.001 in order to transform it correctly to kWh.<BR>
  849. The default value is 1 (= the counter is already providing kWh)<BR>
  850. </td></tr>
  851. </td>
  852. </tr>
  853. </table>
  854. </ul></ul>
  855. <ul><ul>
  856. <table>
  857. <tr>
  858. <td>
  859. <tr><td><li><code>ElectricityPricePerKWh</code> : </li></td><td> A valid float number for electric energy price in the chosen currency per kWh.<BR>
  860. The value is provided by your local electricity supplier and is shown on your electricity bill.<BR>
  861. The default value is 0.2567<BR>
  862. </td></tr>
  863. </td>
  864. </tr>
  865. </table>
  866. </ul></ul>
  867. <ul><ul>
  868. <table>
  869. <tr>
  870. <td>
  871. <tr><td><li><code>MonthlyPayment</code> : </li></td><td> A valid float number for monthly advance payments in the chosen currency towards the electricity supplier.<BR>
  872. The default value is 0.00<BR>
  873. </td></tr>
  874. </td>
  875. </tr>
  876. </table>
  877. </ul></ul>
  878. <ul><ul>
  879. <table>
  880. <tr>
  881. <td>
  882. <tr><td><li><code>MonthOfAnnualReading</code> : </li></td><td> A valid integer number for the month when the mechanical electricity meter reading is performed every year.<BR>
  883. The default value is 5 (May)<BR>
  884. </td></tr>
  885. </td>
  886. </tr>
  887. </table>
  888. </ul></ul>
  889. <ul><ul>
  890. <table>
  891. <tr>
  892. <td>
  893. <tr><td><li><code>ReadingDestination</code> : </li></td><td> One of the pre-defined list for the destination of the calculated readings: [CalculatorDevice,CounterDevice].<BR>
  894. The CalculatorDevice is the device which has been created with this module.<BR>
  895. The CounterDevice is the Device which is reading the mechanical Electricity-meter.<BR>
  896. The default value is CalculatorDevice - Therefore the readings will be written into this device.<BR>
  897. </td></tr>
  898. </td>
  899. </tr>
  900. </table>
  901. </ul></ul>
  902. <ul><ul>
  903. <table>
  904. <tr>
  905. <td>
  906. <tr><td><li><code>SiPrefixPower</code> : </li></td><td> One value of the pre-defined list: W (Watt), kW (Kilowatt), MW (Megawatt) or GW (Gigawatt).<BR>
  907. It defines which SI-prefix for the power value shall be used. The power value will be divided accordingly by multiples of 1000.
  908. The default value is W (Watt).<BR>
  909. </td></tr>
  910. </td>
  911. </tr>
  912. </table>
  913. </ul></ul>
  914. <BR>
  915. <table>
  916. <tr><td><a name="ElectricityCalculatorReadings"></a><b>Readings</b></td></tr>
  917. <tr><td>
  918. <ul>
  919. As soon the device has been able to read at least 2 times the counter, it automatically will create a set of readings:<BR>
  920. The placeholder <code>&lt;DestinationDevice&gt;</code> is the device which has been chosen in the attribute <code>ReadingDestination</code> above. <BR> This will not appear if CalculatorDevice has been chosen.<BR>
  921. The placeholder <code>&lt;SourceCounterReading&gt;</code> is the reading based on the defined regular expression where the counting ticks are coming from.<BR>
  922. </ul>
  923. </td></tr>
  924. </table>
  925. <ul><ul>
  926. <table>
  927. <tr>
  928. <td>
  929. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterCurrent</code> : </li></td><td>Current indicated total electric energy consumption as shown on mechanical electricity meter. Correct Offset-attribute if not identical.<BR>
  930. </td></tr>
  931. </td>
  932. </tr>
  933. </table>
  934. </ul></ul>
  935. <ul><ul>
  936. <table>
  937. <tr>
  938. <td>
  939. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterDay1st</code> : </li></td><td>The first meter reading after midnight.<BR>
  940. </td></tr>
  941. </td>
  942. </tr>
  943. </table>
  944. </ul></ul>
  945. <ul><ul>
  946. <table>
  947. <tr>
  948. <td>
  949. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterDayLast</code> : </li></td><td>The last meter reading of the previous day.<BR>
  950. </td></tr>
  951. </td>
  952. </tr>
  953. </table>
  954. </ul></ul>
  955. <ul><ul>
  956. <table>
  957. <tr>
  958. <td>
  959. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterMonth1st</code> : </li></td><td>The first meter reading after midnight of the first day of the month.<BR>
  960. </td></tr>
  961. </td>
  962. </tr>
  963. </table>
  964. </ul></ul>
  965. <ul><ul>
  966. <table>
  967. <tr>
  968. <td>
  969. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterMonthLast</code> : </li></td><td>The last meter reading of the previous month.<BR>
  970. </td></tr>
  971. </td>
  972. </tr>
  973. </table>
  974. </ul></ul>
  975. <ul><ul>
  976. <table>
  977. <tr>
  978. <td>
  979. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterMeter1st</code> : </li></td><td>The first meter reading after midnight of the first day of the month where the mechanical meter is read by the electricity supplier.<BR>
  980. </td></tr>
  981. </td>
  982. </tr>
  983. </table>
  984. </ul></ul>
  985. <ul><ul>
  986. <table>
  987. <tr>
  988. <td>
  989. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterMeterLast</code> : </li></td><td>The last meter reading of the previous meter reading year.<BR>
  990. </td></tr>
  991. </td>
  992. </tr>
  993. </table>
  994. </ul></ul>
  995. <ul><ul>
  996. <table>
  997. <tr>
  998. <td>
  999. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterYear1st</code> : </li></td><td>The first meter reading after midnight of the first day of the year.<BR>
  1000. </td></tr>
  1001. </td>
  1002. </tr>
  1003. </table>
  1004. </ul></ul>
  1005. <ul><ul>
  1006. <table>
  1007. <tr>
  1008. <td>
  1009. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterYearLast</code> : </li></td><td>The last meter reading of the previous year.<BR>
  1010. </td></tr>
  1011. </td>
  1012. </tr>
  1013. </table>
  1014. </ul></ul>
  1015. <ul><ul>
  1016. <table>
  1017. <tr>
  1018. <td>
  1019. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyCostDayLast</code> : </li></td><td>Energy costs of the last day.<BR>
  1020. </td></tr>
  1021. </td>
  1022. </tr>
  1023. </table>
  1024. </ul></ul>
  1025. <ul><ul>
  1026. <table>
  1027. <tr>
  1028. <td>
  1029. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyCostMeterLast</code> : </li></td><td>Energy costs in the chosen currency of the last electricity meter period.<BR>
  1030. </td></tr>
  1031. </td>
  1032. </tr>
  1033. </table>
  1034. </ul></ul>
  1035. <ul><ul>
  1036. <table>
  1037. <tr>
  1038. <td>
  1039. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyCostMonthLast</code> : </li></td><td>Energy costs in the chosen currency of the last month.<BR>
  1040. </td></tr>
  1041. </td>
  1042. </tr>
  1043. </table>
  1044. </ul></ul>
  1045. <ul><ul>
  1046. <table>
  1047. <tr>
  1048. <td>
  1049. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyCostYearLast</code> : </li></td><td>Energy costs of the last calendar year.<BR>
  1050. </td></tr>
  1051. </td>
  1052. </tr>
  1053. </table>
  1054. </ul></ul>
  1055. <ul><ul>
  1056. <table>
  1057. <tr>
  1058. <td>
  1059. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyCostDay</code> : </li></td><td>Energy consumption in kWh since the beginning of the current day (midnight).<BR>
  1060. </td></tr>
  1061. </td>
  1062. </tr>
  1063. </table>
  1064. </ul></ul>
  1065. <ul><ul>
  1066. <table>
  1067. <tr>
  1068. <td>
  1069. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyCostMeter</code> : </li></td><td>Energy costs in the chosen currency since the beginning of the month of where the last electricity meter reading has been performed by the electricity supplier.<BR>
  1070. </td></tr>
  1071. </td>
  1072. </tr>
  1073. </table>
  1074. </ul></ul>
  1075. <ul><ul>
  1076. <table>
  1077. <tr>
  1078. <td>
  1079. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyCostMonth</code> : </li></td><td>Energy costs in the chosen currency since the beginning of the current month.<BR>
  1080. </td></tr>
  1081. </td>
  1082. </tr>
  1083. </table>
  1084. </ul></ul>
  1085. <ul><ul>
  1086. <table>
  1087. <tr>
  1088. <td>
  1089. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyCostYear</code> : </li></td><td>Energy costs in the chosen currency since the beginning of the current year.<BR>
  1090. </td></tr>
  1091. </td>
  1092. </tr>
  1093. </table>
  1094. </ul></ul>
  1095. <ul><ul>
  1096. <table>
  1097. <tr>
  1098. <td>
  1099. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyDay</code> : </li></td><td>Energy consumption in kWh since the beginning of the current day (midnight).<BR>
  1100. </td></tr>
  1101. </td>
  1102. </tr>
  1103. </table>
  1104. </ul></ul>
  1105. <ul><ul>
  1106. <table>
  1107. <tr>
  1108. <td>
  1109. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyDayLast</code> : </li></td><td>Total Energy consumption in kWh of the last day.<BR>
  1110. </td></tr>
  1111. </td>
  1112. </tr>
  1113. </table>
  1114. </ul></ul>
  1115. <ul><ul>
  1116. <table>
  1117. <tr>
  1118. <td>
  1119. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyMeter</code> : </li></td><td>Energy consumption in kWh since the beginning of the month of where the last electricity-meter reading has been performed by the Electricity supplier.<BR>
  1120. </td></tr>
  1121. </td>
  1122. </tr>
  1123. </table>
  1124. </ul></ul>
  1125. <ul><ul>
  1126. <table>
  1127. <tr>
  1128. <td>
  1129. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyMeterLast</code> : </li></td><td>Total Energy consumption in kWh of the last electricity-meter reading period.<BR>
  1130. </td></tr>
  1131. </td>
  1132. </tr>
  1133. </table>
  1134. </ul></ul>
  1135. <ul><ul>
  1136. <table>
  1137. <tr>
  1138. <td>
  1139. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyMonth</code> : </li></td><td>Energy consumption in kWh since the beginning of the current month (midnight of the first).<BR>
  1140. </td></tr>
  1141. </td>
  1142. </tr>
  1143. </table>
  1144. </ul></ul>
  1145. <ul><ul>
  1146. <table>
  1147. <tr>
  1148. <td>
  1149. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyMonthLast</code> : </li></td><td>Total Energy consumption in kWh of the last month.<BR>
  1150. </td></tr>
  1151. </td>
  1152. </tr>
  1153. </table>
  1154. </ul></ul>
  1155. <ul><ul>
  1156. <table>
  1157. <tr>
  1158. <td>
  1159. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyYear</code> : </li></td><td>Energy consumption in kWh since the beginning of the current year (midnight of the first).<BR>
  1160. </td></tr>
  1161. </td>
  1162. </tr>
  1163. </table>
  1164. </ul></ul>
  1165. <ul><ul>
  1166. <table>
  1167. <tr>
  1168. <td>
  1169. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyYearLast</code> : </li></td><td>Total Energy consumption in kWh of the last calendar year.<BR>
  1170. </td></tr>
  1171. </td>
  1172. </tr>
  1173. </table>
  1174. </ul></ul>
  1175. <ul><ul>
  1176. <table>
  1177. <tr>
  1178. <td>
  1179. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_FinanceReserve</code> : </li></td><td>Financial Reserve based on the advanced payments done on the first of every month towards the Electricity supplier. With negative values, an additional payment is to be expected.<BR>
  1180. </td></tr>
  1181. </td>
  1182. </tr>
  1183. </table>
  1184. </ul></ul>
  1185. <ul><ul>
  1186. <table>
  1187. <tr>
  1188. <td>
  1189. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_MonthMeterReading</code> : </li></td><td>Number of month since last meter reading. The month when the reading occured is the first month = 1.<BR>
  1190. </td></tr>
  1191. </td>
  1192. </tr>
  1193. </table>
  1194. </ul></ul>
  1195. <ul><ul>
  1196. <table>
  1197. <tr>
  1198. <td>
  1199. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_PowerCurrent</code> : </li></td><td>Current electric Power. (Average Power between current and previous measurement.)<BR>
  1200. </td></tr>
  1201. </td>
  1202. </tr>
  1203. </table>
  1204. </ul></ul>
  1205. <ul><ul>
  1206. <table>
  1207. <tr>
  1208. <td>
  1209. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_PowerDayAver</code> : </li></td><td>Average electric Power since midnight.<BR>
  1210. </td></tr>
  1211. </td>
  1212. </tr>
  1213. </table>
  1214. </ul></ul>
  1215. <ul><ul>
  1216. <table>
  1217. <tr>
  1218. <td>
  1219. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_PowerDayMax</code> : </li></td><td>Maximum Power peak since midnight.<BR>
  1220. </td></tr>
  1221. </td>
  1222. </tr>
  1223. </table>
  1224. </ul></ul>
  1225. <ul><ul>
  1226. <table>
  1227. <tr>
  1228. <td>
  1229. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_PowerDayMin</code> : </li></td><td>Minimum Power peak since midnight.<BR>
  1230. </td></tr>
  1231. </td>
  1232. </tr>
  1233. </table>
  1234. </ul></ul>
  1235. </ul>
  1236. =end html
  1237. =begin html_DE
  1238. <a name="ElectricityCalculator"></a>
  1239. <h3>ElectricityCalculator</h3>
  1240. <ul>
  1241. <table>
  1242. <tr>
  1243. <td>
  1244. Das ElectricityCalculator Modul berechnet den Verbrauch an elektrischer Energie (Stromverbrauch) und den verbundenen Kosten von einem oder mehreren Elektrizit&auml;tsz&auml;hlern.<BR>
  1245. Es ist kein eigenes Z&auml;hlermodul sondern ben&ouml;tigt eine Regular Expression (regex or regexp) um das Reading mit den Z&auml;hlimpulse von einem oder mehreren Electrizit&auml;tsz&auml;hlern zu finden.<BR>
  1246. <BR>
  1247. Sobald das Modul in der fhem.cfg definiert wurde, reagiert das Modul auf jedes durch das regex definierte event wie beispielsweise ein myOWDEVICE:counter.* etc.<BR>
  1248. <BR>
  1249. Das ElectricityCalculator Modul berechnet augenblickliche, historische statistische und vorhersehbare Werte von einem oder mehreren Elektrizit&auml;tsz&auml;hlern und erstellt die entsprechenden Readings.<BR>
  1250. <BR>
  1251. Um zu verhindern, dass man bis zu 12 Monate warten muss, bis alle Werte der Realit&auml;t entsprechen, m&uuml;ssen die Readings<BR>
  1252. <code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterDay1st</code>,<BR>
  1253. <code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterMonth1st</code>,<BR>
  1254. <code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterYear1st</code> und<BR>
  1255. <code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterMeter1st</code><BR>
  1256. entsprechend mit dem <code>setreading</code> - Befehl korrigiert werden.<BR>
  1257. Diese Werte findet man unter Umst&auml;nden auf der letzten Abrechnung des Elektrizit&auml;tsversorgers. Andernfalls dauert es bis zu 24h f&uuml;r die t&auml;glichen, 30 Tage f&uuml;r die monatlichen und bis zu 12 Monate f&uuml;r die j&auml;hrlichen Werte bis diese der Realit&auml;t entsprechen.<BR>
  1258. <BR>
  1259. <BR>
  1260. Intervalle kleienr als 10s werden ignoriert um Spitzen zu verhindern die von Blockaden des fhem Systems hervorgerufen werden (z.B. DbLog - reducelog).
  1261. </td>
  1262. </tr>
  1263. </table>
  1264. <table>
  1265. <tr><td><a name="ElectricityCalculatorDefine"></a><b>Define</b></td></tr>
  1266. </table>
  1267. <table><tr><td><ul><code>define &lt;name&gt; ElectricityCalculator &lt;regex&gt;</code></ul></td></tr></table>
  1268. <ul><ul>
  1269. <table>
  1270. <tr><td><code>&lt;name&gt;</code> : </td><td>Der Name dieses Berechnungs-Device. Empfehlung: "myElectricityCalculator".</td></tr>
  1271. <tr><td><code>&lt;regex&gt;</code> : </td><td>Eine g&uuml;ltige Regular Expression (regex or regexp) von dem Event wo der Z&auml;hlerstand gefunden werden kann</td></tr>
  1272. </table>
  1273. </ul></ul>
  1274. <table><tr><td><ul>Beispiel: <code>define myElectricityCalculator ElectricityCalculator myElectricityCounter:countersA.*</code></ul></td></tr></table>
  1275. <BR>
  1276. <table>
  1277. <tr><td><a name="ElectricityCalculatorSet"></a><b>Set</b></td></tr>
  1278. <tr><td>
  1279. <ul>
  1280. Die set - Funktion erlaubt individuelle Readings zu ver&auml;ndern um beispielsweise nach einem Stromausfall Werte zu korrigieren.<BR>
  1281. Die set - Funktion funktioniert nur f&uumlr Readings welche im CalculatorDevice gespeichert wurden.<BR>
  1282. Die Readings welche im Counter - Device gespeichert wurden, m&uumlssen individuell mit <code>set</code> - Befehl gesetzt werden.<BR>
  1283. </ul>
  1284. </td></tr>
  1285. </table>
  1286. <BR>
  1287. <table>
  1288. <tr><td><a name="ElectricityCalculatorGet"></a><b>Get</b></td></tr>
  1289. <tr><td>
  1290. <ul>
  1291. Die get - Funktion liefert nur den Wert des jeweiligen Readings zur&uuml;ck.<BR>
  1292. Die get - Funktion funktioniert nur f&uumlr Readings welche im CalculatorDevice gespeichert wurden.<BR>
  1293. Die Readings welche im Counter - Device gespeichert wurden, m&uumlssen individuell mit <code>get</code> - Befehl ausgelesen werden.<BR>
  1294. </ul>
  1295. </td></tr>
  1296. </table>
  1297. <BR>
  1298. <table>
  1299. <tr><td><a name="ElectricityCalculatorAttr"></a><b>Attributes</b></td></tr>
  1300. <tr><td>
  1301. <ul>
  1302. Sollten die unten ausfeg&auuml;hrten Attribute bei der Definition eines entsprechenden Ger&auml;tes nicht gesetzt sein, so werden sie vom Modul mit Standard Werten automatisch gesetzt<BR>
  1303. Zus&auml;tzlich k&ouml;nnen die globalen Attribute wie <a href="#room">room</a> verwendet werden.<BR>
  1304. </ul>
  1305. </td></tr>
  1306. </table>
  1307. <ul><ul>
  1308. <table>
  1309. <tr>
  1310. <td>
  1311. <tr><td><li><code>BasicPricePerAnnum</code> : </li></td><td> Eine g&uuml;ltige float Zahl f&uuml;r die j&auml;hrliche Grundgeb&uuml;hr in der gew&auml;hlten W&auml;hrung f&uuml;r die Elektrizit&auml;ts-Versorgung zum Endverbraucher.<BR>
  1312. Dieser Wert stammt vom Elektrizit&auml;tsversorger und steht auf der Abrechnung.<BR>
  1313. Der Standard Wert ist 0.00<BR>
  1314. </td></tr>
  1315. </td>
  1316. </tr>
  1317. </table>
  1318. </ul></ul>
  1319. <ul><ul>
  1320. <table>
  1321. <tr>
  1322. <td>
  1323. <tr><td><li><code>Currency</code> : </li></td><td> Eines der vordefinerten W&auml;hrungssymbole: [&#8364;,&#163;,&#36;].<BR>
  1324. Der Standard Wert ist &#8364;<BR>
  1325. </td></tr>
  1326. </td>
  1327. </tr>
  1328. </table>
  1329. </ul></ul>
  1330. <ul><ul>
  1331. <table>
  1332. <tr>
  1333. <td>
  1334. <tr><td><li><code>disable</code> : </li></td><td> Deaktiviert das device. Das Modul wird nicht mehr auf die Events reagieren die durch die Regular Expression definiert wurde.<BR>
  1335. Der Standard Wert ist 0 = aktiviert.<BR>
  1336. </td></tr>
  1337. </td>
  1338. </tr>
  1339. </table>
  1340. </ul></ul>
  1341. <ul><ul>
  1342. <table>
  1343. <tr>
  1344. <td>
  1345. <tr><td><li><code>ElectricityCounterOffset</code> : </li></td><td> Eine g&uuml;ltige float-Zahl f&uuml;r den Unterschied = Offset (Nicht der Unterschied zwischen Z&auml;hlimpulsen) zwischen dem am mechanischen Elektrizit&auml;tsz&auml;hlern und dem angezeigten Wert im Reading dieses Device.<BR>
  1346. Der Offset-Wert wird wie folgt ermittelt: W<sub>Offset</sub> = W<sub>Mechanisch</sub> - W<sub>Module</sub><BR>
  1347. Der Standard-Wert ist 0.00<BR>
  1348. </td></tr>
  1349. </td>
  1350. </tr>
  1351. </table>
  1352. </ul></ul>
  1353. <ul><ul>
  1354. <table>
  1355. <tr>
  1356. <td>
  1357. <tr><td><li><code>ElectricityKwhPerCounts</code> : </li></td><td> Eine g&uuml;ltige float-Zahl f&uuml;r die Menge kWh pro Z&auml;hlimpulsen.<BR>
  1358. Der Wert ist durch das mechanische Z&auml;hlwerk des Elektrizit&auml;tsz&auml;hlern vorgegeben. ElectricityKwhPerCounts = 0.001 bedeutet, dass jeder Z&auml;hlimpuls ein Tausendstel einer kWh ist (=Wh).<BR>
  1359. Einige elektronische Zähler (Bsp.: HomeMatic HM-ES-TX-WM) stellen die gezählte Menge an elektrischer Energie als Wh bereit.<BR>
  1360. Aus diesem Grund muss dieses Attribut auf 0.001 gesetzt werden um eine korrekte Transformation in kWh zu erm&ouml;glichen.<BR>
  1361. Der Standard-Wert ist 1<BR>
  1362. </td></tr>
  1363. </td>
  1364. </tr>
  1365. </table>
  1366. </ul></ul>
  1367. <ul><ul>
  1368. <table>
  1369. <tr>
  1370. <td>
  1371. <tr><td><li><code>ElectricityPricePerKWh</code> : </li></td><td> Eine g&uuml;ltige float-Zahl f&uuml;r den Preis pro kWh.<BR>
  1372. Dieser Wert stammt vom Elektrizit&auml;tsversorger und steht auf der Abrechnung.<BR>
  1373. Der Standard-Wert ist 0.2567<BR>
  1374. </td></tr>
  1375. </td>
  1376. </tr>
  1377. </table>
  1378. </ul></ul>
  1379. <ul><ul>
  1380. <table>
  1381. <tr>
  1382. <td>
  1383. <tr><td><li><code>MonthlyPayment</code> : </li></td><td> Eine g&uuml;ltige float-Zahl f&uuml;r die monatlichen Abschlagszahlungen in der gew&auml;hlten W&auml;hrung an den Elektrizit&auml;tsversorger.<BR>
  1384. Der Standard-Wert ist 0.00<BR>
  1385. </td></tr>
  1386. </td>
  1387. </tr>
  1388. </table>
  1389. </ul></ul>
  1390. <ul><ul>
  1391. <table>
  1392. <tr>
  1393. <td>
  1394. <tr><td><li><code>MonthOfAnnualReading</code> : </li></td><td> Eine g&uuml;ltige Ganz-Zahl f&uuml;r den Monat wenn der mechanische Elektrizit&auml;tsz&auml;hler jedes Jahr durch den Elektrizit&auml;tsversorger abgelesen wird.<BR>
  1395. Der Standard-Wert ist 5 (Mai)<BR>
  1396. </td></tr>
  1397. </td>
  1398. </tr>
  1399. </table>
  1400. </ul></ul>
  1401. <ul><ul>
  1402. <table>
  1403. <tr>
  1404. <td>
  1405. <tr><td><li><code>ReadingDestination</code> : </li></td><td> Eines der vordefinerten Device als Ziel der errechneten Readings: [CalculatorDevice,CounterDevice].<BR>
  1406. Das CalculatorDevice ist das mit diesem Modul erstellte Device.<BR>
  1407. Das CounterDevice ist das Device von welchem der mechanische Z&auml;hler ausgelesen wird.<BR>
  1408. Der Standard-Wert ist CalculatorDevice.<BR>
  1409. </td></tr>
  1410. </td>
  1411. </tr>
  1412. </table>
  1413. </ul></ul>
  1414. <ul><ul>
  1415. <table>
  1416. <tr>
  1417. <td>
  1418. <tr><td><li><code>SiPrefixPower</code> : </li></td><td> Ein Wert der vorgegebenen Auswahlliste: W (Watt), kW (Kilowatt), MW (Megawatt) or GW (Gigawatt).<BR>
  1419. Es definiert welcher SI-Prefix verwendet werden soll und teilt die Leistung entsprechend durch ein Vielfaches von 1000.
  1420. Der Standard-Wert ist W (Watt).<BR>
  1421. </td></tr>
  1422. </td>
  1423. </tr>
  1424. </table>
  1425. </ul></ul>
  1426. <BR>
  1427. <table>
  1428. <tr><td><a name="ElectricityCalculatorReadings"></a><b>Readings</b></td></tr>
  1429. <tr><td>
  1430. <ul>
  1431. Sobald das Device in der Lage war mindestens 2 Werte des Z&auml;hlers einzulesen, werden automatisch die entsprechenden Readings erzeugt:<BR>
  1432. Der Platzhalter <code>&lt;DestinationDevice&gt;</code> steht f&uuml;r das Device, welches man in dem Attribut <code>ReadingDestination</code> oben festgelegt hat. Dieser Platzhalter bleibt leer, sobald man dort CalculatorDevice ausgew&auml;hlt hat.<BR>
  1433. Der Platzhalter <code>&lt;SourceCounterReading&gt;</code> steht f&uuml;r das Reading welches mit der Regular Expression definiert wurde.<BR>
  1434. </ul>
  1435. </td></tr>
  1436. </table>
  1437. <ul><ul>
  1438. <table>
  1439. <tr>
  1440. <td>
  1441. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterCurrent</code> : </li></td><td>Aktueller Z&auml;hlerstand am mechanischen Z&auml;hler. Bei Unterschied muss das Offset-Attribut entspechend korrigiert werden.<BR>
  1442. </td></tr>
  1443. </td>
  1444. </tr>
  1445. </table>
  1446. </ul></ul>
  1447. <ul><ul>
  1448. <table>
  1449. <tr>
  1450. <td>
  1451. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterDay1st</code> : </li></td><td>Der erste Z&auml;hlerstand des laufenden Tages seit Mitternacht.<BR>
  1452. </td></tr>
  1453. </td>
  1454. </tr>
  1455. </table>
  1456. </ul></ul>
  1457. <ul><ul>
  1458. <table>
  1459. <tr>
  1460. <td>
  1461. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterDayLast</code> : </li></td><td>Der letzte Z&auml;hlerstand des vorherigen Tages.<BR>
  1462. </td></tr>
  1463. </td>
  1464. </tr>
  1465. </table>
  1466. </ul></ul>
  1467. <ul><ul>
  1468. <table>
  1469. <tr>
  1470. <td>
  1471. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterMeter1st</code> : </li></td><td>Der erste Z&auml;hlerstand seit Mitternacht des ersten Tages der laufenden Ableseperiode.<BR>
  1472. </td></tr>
  1473. </td>
  1474. </tr>
  1475. </table>
  1476. </ul></ul>
  1477. <ul><ul>
  1478. <table>
  1479. <tr>
  1480. <td>
  1481. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterMeterLast</code> : </li></td><td>Der letzte Z&auml;hlerstand seit Mitternacht des ersten Tages der vorherigen Ableseperiode.<BR>
  1482. </td></tr>
  1483. </td>
  1484. </tr>
  1485. </table>
  1486. </ul></ul>
  1487. <ul><ul>
  1488. <table>
  1489. <tr>
  1490. <td>
  1491. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterMonth1st</code> : </li></td><td>Der erste Z&auml;hlerstand seit Mitternacht des ersten Tages des laufenden Monats.<BR>
  1492. </td></tr>
  1493. </td>
  1494. </tr>
  1495. </table>
  1496. </ul></ul>
  1497. <ul><ul>
  1498. <table>
  1499. <tr>
  1500. <td>
  1501. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterMonthLast</code> : </li></td><td>Der letzte Z&auml;hlerstand des vorherigen Monats.<BR>
  1502. </td></tr>
  1503. </td>
  1504. </tr>
  1505. </table>
  1506. </ul></ul>
  1507. <ul><ul>
  1508. <table>
  1509. <tr>
  1510. <td>
  1511. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterYear1st</code> : </li></td><td>Der erste Z&auml;hlerstand seit Mitternacht des ersten Tages des laufenden Jahres.<BR>
  1512. </td></tr>
  1513. </td>
  1514. </tr>
  1515. </table>
  1516. </ul></ul>
  1517. <ul><ul>
  1518. <table>
  1519. <tr>
  1520. <td>
  1521. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_CounterYearLast</code> : </li></td><td>Der letzte Z&auml;hlerstand des letzten Jahres.<BR>
  1522. </td></tr>
  1523. </td>
  1524. </tr>
  1525. </table>
  1526. </ul></ul>
  1527. <ul><ul>
  1528. <table>
  1529. <tr>
  1530. <td>
  1531. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyCostDayLast</code> : </li></td><td>Elektrische Energiekosten des letzten Tages.<BR>
  1532. </td></tr>
  1533. </td>
  1534. </tr>
  1535. </table>
  1536. </ul></ul>
  1537. <ul><ul>
  1538. <table>
  1539. <tr>
  1540. <td>
  1541. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyCostMeterLast</code> : </li></td><td>Elektrische Energiekosten der letzten Ableseperiode.<BR>
  1542. </td></tr>
  1543. </td>
  1544. </tr>
  1545. </table>
  1546. </ul></ul>
  1547. <ul><ul>
  1548. <table>
  1549. <tr>
  1550. <td>
  1551. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyCostMonthLast</code> : </li></td><td>Elektrische Energiekosten des letzten Monats.<BR>
  1552. </td></tr>
  1553. </td>
  1554. </tr>
  1555. </table>
  1556. </ul></ul>
  1557. <ul><ul>
  1558. <table>
  1559. <tr>
  1560. <td>
  1561. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyCostYearLast</code> : </li></td><td>Elektrische Energiekosten des letzten Kalenderjahres.<BR>
  1562. </td></tr>
  1563. </td>
  1564. </tr>
  1565. </table>
  1566. </ul></ul>
  1567. <ul><ul>
  1568. <table>
  1569. <tr>
  1570. <td>
  1571. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyCostDay</code> : </li></td><td>Energiekosten in gew&auml;hlter W&auml;hrung seit Mitternacht des laufenden Tages.<BR>
  1572. </td></tr>
  1573. </td>
  1574. </tr>
  1575. </table>
  1576. </ul></ul>
  1577. <ul><ul>
  1578. <table>
  1579. <tr>
  1580. <td>
  1581. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyCostMeter</code> : </li></td><td>Energiekosten in gew&auml;hlter W&auml;hrung seit Beginn der laufenden Ableseperiode.<BR>
  1582. </td></tr>
  1583. </td>
  1584. </tr>
  1585. </table>
  1586. </ul></ul>
  1587. <ul><ul>
  1588. <table>
  1589. <tr>
  1590. <td>
  1591. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyCostMonth</code> : </li></td><td>Energiekosten in gew&auml;hlter W&auml;hrung seit Beginn des laufenden Monats.<BR>
  1592. </td></tr>
  1593. </td>
  1594. </tr>
  1595. </table>
  1596. </ul></ul>
  1597. <ul><ul>
  1598. <table>
  1599. <tr>
  1600. <td>
  1601. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyCostYear</code> : </li></td><td>Energiekosten in gew&auml;hlter W&auml;hrung seit Beginn des laufenden Kalenderjahres.<BR>
  1602. </td></tr>
  1603. </td>
  1604. </tr>
  1605. </table>
  1606. </ul></ul>
  1607. <ul><ul>
  1608. <table>
  1609. <tr>
  1610. <td>
  1611. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyDay</code> : </li></td><td>Energieverbrauch seit Beginn der aktuellen Tages (Mitternacht).<BR>
  1612. </td></tr>
  1613. </td>
  1614. </tr>
  1615. </table>
  1616. </ul></ul>
  1617. <ul><ul>
  1618. <table>
  1619. <tr>
  1620. <td>
  1621. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyDayLast</code> : </li></td><td>Energieverbrauch in kWh des vorherigen Tages.<BR>
  1622. </td></tr>
  1623. </td>
  1624. </tr>
  1625. </table>
  1626. </ul></ul>
  1627. <ul><ul>
  1628. <table>
  1629. <tr>
  1630. <td>
  1631. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyMeter</code> : </li></td><td>Energieverbrauch seit Beginn der aktuellen Ableseperiode.<BR>
  1632. </td></tr>
  1633. </td>
  1634. </tr>
  1635. </table>
  1636. </ul></ul>
  1637. <ul><ul>
  1638. <table>
  1639. <tr>
  1640. <td>
  1641. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyMeterLast</code> : </li></td><td>Energieverbrauch in kWh der vorherigen Ableseperiode.<BR>
  1642. </td></tr>
  1643. </td>
  1644. </tr>
  1645. </table>
  1646. </ul></ul>
  1647. <ul><ul>
  1648. <table>
  1649. <tr>
  1650. <td>
  1651. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyMonth</code> : </li></td><td>Energieverbrauch seit Beginn des aktuellen Monats.<BR>
  1652. </td></tr>
  1653. </td>
  1654. </tr>
  1655. </table>
  1656. </ul></ul>
  1657. <ul><ul>
  1658. <table>
  1659. <tr>
  1660. <td>
  1661. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyMonthLast</code> : </li></td><td>Energieverbrauch in kWh des vorherigen Monats.<BR>
  1662. </td></tr>
  1663. </td>
  1664. </tr>
  1665. </table>
  1666. </ul></ul>
  1667. <ul><ul>
  1668. <table>
  1669. <tr>
  1670. <td>
  1671. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyYear</code> : </li></td><td>Energieverbrauch seit Beginn des aktuellen Kalenderjahres.<BR>
  1672. </td></tr>
  1673. </td>
  1674. </tr>
  1675. </table>
  1676. </ul></ul>
  1677. <ul><ul>
  1678. <table>
  1679. <tr>
  1680. <td>
  1681. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_EnergyYearLast</code> : </li></td><td>Energieverbrauch in kWh des vorherigen Kalenderjahres.<BR>
  1682. </td></tr>
  1683. </td>
  1684. </tr>
  1685. </table>
  1686. </ul></ul>
  1687. <ul><ul>
  1688. <table>
  1689. <tr>
  1690. <td>
  1691. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_FinanceReserve</code> : </li></td><td>Finanzielle Reserve basierend auf den Abschlagszahlungen die jeden Monat an den Elektrizit&auml;tsversorger gezahlt werden. Bei negativen Werten ist von einer Nachzahlung auszugehen.<BR>
  1692. </td></tr>
  1693. </td>
  1694. </tr>
  1695. </table>
  1696. </ul></ul>
  1697. <ul><ul>
  1698. <table>
  1699. <tr>
  1700. <td>
  1701. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_MonthMeterReading</code> : </li></td><td>Anzahl der Monate seit der letzten Zählerablesung. Der Monat der Zählerablesung ist der erste Monat = 1.<BR>
  1702. </td></tr>
  1703. </td>
  1704. </tr>
  1705. </table>
  1706. </ul></ul>
  1707. <ul><ul>
  1708. <table>
  1709. <tr>
  1710. <td>
  1711. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_PowerCurrent</code> : </li></td><td>Aktuelle elektrische Leistung. (Mittelwert zwischen aktueller und letzter Messung)<BR>
  1712. </td></tr>
  1713. </td>
  1714. </tr>
  1715. </table>
  1716. </ul></ul>
  1717. <ul><ul>
  1718. <table>
  1719. <tr>
  1720. <td>
  1721. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_PowerDayAver</code> : </li></td><td>Mittlere elektrische Leistung seit Mitternacht.<BR>
  1722. </td></tr>
  1723. </td>
  1724. </tr>
  1725. </table>
  1726. </ul></ul>
  1727. <ul><ul>
  1728. <table>
  1729. <tr>
  1730. <td>
  1731. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_PowerDayMax</code> : </li></td><td>Maximale elektrische Leistungsaufnahme seit Mitternacht.<BR>
  1732. </td></tr>
  1733. </td>
  1734. </tr>
  1735. </table>
  1736. </ul></ul>
  1737. <ul><ul>
  1738. <table>
  1739. <tr>
  1740. <td>
  1741. <tr><td><li><code>&lt;DestinationDevice&gt;_&lt;SourceCounterReading&gt;_PowerDayMin</code> : </li></td><td>Minimale elektrische Leistungsaufnahme seit Mitternacht.<BR>
  1742. </td></tr>
  1743. </td>
  1744. </tr>
  1745. </table>
  1746. </ul></ul>
  1747. </ul>
  1748. =end html_DE
  1749. =cut