diff --git a/fhem/FHEM/73_ElectricityCalculator.pm b/fhem/FHEM/73_ElectricityCalculator.pm index 9bf3ce7b4..2da18146f 100644 --- a/fhem/FHEM/73_ElectricityCalculator.pm +++ b/fhem/FHEM/73_ElectricityCalculator.pm @@ -44,6 +44,7 @@ package main; use strict; use warnings; +use FHEM::Meta; ###START###### Initialize module ##############################################################################START#### sub ElectricityCalculator_Initialize($) @@ -73,6 +74,7 @@ sub ElectricityCalculator_Initialize($) "Currency:€,£,$ " . "DecimalPlace:3,4,5,6,7 " . $readingFnAttributes; + return FHEM::Meta::InitMod( __FILE__, $hash ); } ####END####### Initialize module ###############################################################################END##### @@ -130,6 +132,19 @@ sub ElectricityCalculator_Define($$$) ### Writing log entry Log3 $name, 5, $name. " : ElectricityCalculator - Starting to define module"; + ### Start timer for execution around midnight + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); + my $EpochNextMidnight = timelocal(1, 0, 0, $mday, $mon, $year+1900) + 86400; + InternalTimer($EpochNextMidnight, "ElectricityCalculator_MidnightTimer", $hash, 0); + + ### For debugging purpose only + Log3 $name, 5, $name. " : ElectricityCalculator_MidnightTimer - time : " . time(); + Log3 $name, 5, $name. " : ElectricityCalculator_MidnightTimer - year : " . $year; + Log3 $name, 5, $name. " : ElectricityCalculator_MidnightTimer - mon : " . $mon; + Log3 $name, 5, $name. " : ElectricityCalculator_MidnightTimer - day : " . $mday; + Log3 $name, 5, $name. " : ElectricityCalculator_MidnightTimer - timelocal : " . timelocal(1, 0, 0, $mday, $mon, $year+1900); + Log3 $name, 5, $name. " : ElectricityCalculator_MidnightTimer - nextMidnight : " . $EpochNextMidnight; + return undef; } ####END####### Activate module after module has been used via fhem command "define" ############################END##### @@ -398,6 +413,125 @@ sub ElectricityCalculator_Set($@) } ####END####### Manipulate reading after "set" command by fhem ##################################################END##### +###START###### Midnight Routine ###############################################################################START#### +sub ElectricityCalculator_MidnightTimer($) +{ + ### Define variables + my ($ElectricityCalcDev) = @_; + my $ElectricityCalcName = $ElectricityCalcDev->{NAME}; + my $RegEx = $ElectricityCalcDev->{REGEXP}; + my ($ElectricityCountName, $ElectricityCountReadingRegEx) = split(":", $RegEx, 2); + my $ElectricityCountDev = $defs{$ElectricityCountName}; + $ElectricityCountReadingRegEx =~ s/[\.\*]//g; + + my @ElectricityCountReadingNameListComplete = keys(%{$ElectricityCountDev->{READINGS}}); + my @ElectricityCountReadingNameListFiltered; + + foreach my $ElectricityCountReadingName (@ElectricityCountReadingNameListComplete) { + if ($ElectricityCountReadingName =~ m[$ElectricityCountReadingRegEx]) { + push(@ElectricityCountReadingNameListFiltered, $ElectricityCountReadingName); + } + } + + + ### Create Log entries for debugging purpose + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer__________________________________________________________"; + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer : MidnightTimer initiated"; + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - RegEx : " . $RegEx; + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - ElectricityCountName : " . $ElectricityCountName; + #Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - ElectricityCountReadList : " . Dumper(@ElectricityCountReadingNameListFiltered); + + + ### Remove internal timer for ElectricityCalculator_MidnightTimer + RemoveInternalTimer($ElectricityCalcDev, "ElectricityCalculator_MidnightTimer"); + + ### Create Log entries for debugging purpose + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - Looping through every Counter defined by RegEx"; + + foreach my $ElectricityCountReadingName (@ElectricityCountReadingNameListFiltered) { + + # ### Restore Destination of readings + my $ElectricityCalcReadingPrefix = $ElectricityCountName . "_" . $ElectricityCountReadingName; + my $ElectricityCalcReadingDestinationDeviceName = ReadingsVal($ElectricityCalcName, ".ReadingDestinationDeviceName" , "error"); + my $ElectricityCounterReadingValue = ReadingsVal($ElectricityCountName, $ElectricityCountReadingName , "error"); + my $LastUpdateTimestampUnix = ReadingsVal($ElectricityCalcName, "." . $ElectricityCalcReadingPrefix . "_LastUpdateTimestampUnix", 0 ); + + ### Calculate time difference since last update + my $DeltaTimeSinceLastUpdate = time() - $LastUpdateTimestampUnix ; + + ### Create Log entries for debugging purpose + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer ___________Looping________________"; + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - ReadingPrefix : " . $ElectricityCalcReadingPrefix; + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - DeviceName : " . $ElectricityCalcReadingDestinationDeviceName; + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - Timestamp now : " . time(); + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - Timestamp update : " . $LastUpdateTimestampUnix; + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - Timestamp Delta : " . $DeltaTimeSinceLastUpdate; + + + ### If the Readings for midnight settings have been provided + if (($ElectricityCalcReadingPrefix ne "error") && ($ElectricityCalcReadingDestinationDeviceName ne "error") && ($LastUpdateTimestampUnix > 0)){ + + ### Create Log entries for debugging purpose + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - Timestamp update : " . $LastUpdateTimestampUnix; + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - Timestamp Delta : " . $DeltaTimeSinceLastUpdate; + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - ReadingPrefix : " . $ElectricityCalcReadingPrefix; + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - DeviceName : " . $ElectricityCalcReadingDestinationDeviceName; + + ### If there was no update in the last 24h + if ( $DeltaTimeSinceLastUpdate >= 86400) { + ### Create Log entries for debugging purpose + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - Last Update : No Update in the last 24h!"; + + } + else { + ### Create Log entries for debugging purpose + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - Last Update : There was an Update in the last 24h!"; + } + + #Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - ElectricityCalcRDD : \n" . Dumper($ElectricityCalcReadingDestinationDevice); + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - ElectricityCounter: " . $ElectricityCounterReadingValue; + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - Pre WFRDaySum : " . ReadingsVal($ElectricityCalcReadingDestinationDeviceName, "." . $ElectricityCalcReadingPrefix . "_PowerDaySum", "error"); + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - Pre WFRDayCount : " . ReadingsVal($ElectricityCalcReadingDestinationDeviceName, "." . $ElectricityCalcReadingPrefix . "_PowerDayCount", "error"); + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - Pre WFRDayCurrent : " . ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_PowerCurrent", "error"); + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - Pre WFRDayAver : " . ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_PowerDayAver", "error"); + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - Pre WFRDayMax : " . ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_PowerDayMax", "error"); + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - Pre WFRDayMin : " . ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_PowerDayMin", "error"); + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - Pre ConsumDay : " . ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_EnergyDay", "error"); + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - Pre ConsumDayLast : " . ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_EnergyDayLast", "error"); + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - Pre ConsumCstDay : " . ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_EnergyCostDay", "error"); + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - Pre ConsumCstDayL : " . ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_EnergyCostDayLast", "error"); + + + if ($ElectricityCounterReadingValue ne "error") { + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - Writing Counter : " . $ElectricityCounterReadingValue; + readingsSingleUpdate($ElectricityCountDev, $ElectricityCountReadingName, $ElectricityCounterReadingValue, 1); + } + else { + + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - Writing Counter : Error!"; + } + } + ### If the Readings for midnight settings have not been provided + else { + ### Warning Log entry + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - ERROR - There have no information stored about previous readings. Make sure the counter has been delivering at least 2 values to the Calculator device before next midnight!"; + } + } + + ### Start timer for execution around midnight + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); + my $EpochNextMidnight = timelocal(1, 0, 0, $mday, $mon, $year+1900) + 86400; + InternalTimer($EpochNextMidnight, "ElectricityCalculator_MidnightTimer", $ElectricityCalcDev, 0); + + ### For debugging purpose only + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer _______Looping finished___________"; + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - time : " . time(); + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - timelocal : " . timelocal(1, 0, 0, $mday, $mon, $year+1900); + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_MidnightTimer - nextMidnight : " . $EpochNextMidnight; +} +####END####### Midnight Routine ################################################################################END##### + + ###START###### Calculate Electricity meter values on changed events ###################################################START#### sub ElectricityCalculator_Notify($$) { @@ -603,9 +737,13 @@ sub ElectricityCalculator_Notify($$) next; } + ### Save Destination of readings into hidden readings + readingsSingleUpdate($ElectricityCalcDev, ".ReadingDestinationDeviceName", $ElectricityCalcReadingDestinationDeviceName, 0); + ### Restore previous Counter and if not available define it with "undef" - my $ElectricityCountReadingTimestampPrevious = ReadingsTimestamp($ElectricityCalcReadingDestinationDeviceName, "." . $ElectricityCalcReadingPrefix . "_PrevRead", undef); - my $ElectricityCountReadingValuePrevious = ReadingsVal($ElectricityCalcReadingDestinationDeviceName, "." . $ElectricityCalcReadingPrefix . "_PrevRead", undef); + my $ElectricityCountReadingTimestampPrevious = ReadingsTimestamp($ElectricityCalcReadingDestinationDeviceName, "." . $ElectricityCalcReadingPrefix . "_PrevRead", undef); + my $ElectricityCountReadingValuePrevious = ReadingsVal($ElectricityCalcReadingDestinationDeviceName, "." . $ElectricityCalcReadingPrefix . "_PrevRead", undef); + my $ElectricityCountReadingLastChangeDelta = time() - ReadingsVal($ElectricityCalcReadingDestinationDeviceName, "." . $ElectricityCalcReadingPrefix . "_LastUpdateTimestampUnix", undef); ### Create Log entries for debugging Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCountReadingValuePrevious : " . $ElectricityCountReadingValuePrevious; @@ -696,11 +834,15 @@ sub ElectricityCalculator_Notify($$) Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - Current Reading Value : " . $ElectricityCountReadingValueCurrent; ####### Check whether Initial readings needs to be written - ### Check whether the current value is the first one after change of day = First one after midnight - if ($ElectricityCountReadingTimestampCurrentHour < $ElectricityCountReadingTimestampPreviousHour) + ### Check whether the current value is the first one after change of day = First one after midnight or if last update is older than 1 day + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_Notify ElectricityCountReadTimeCurHour : " . $ElectricityCountReadingTimestampCurrentHour; + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_Notify ElectricityCountReadTimePrevHour : " . $ElectricityCountReadingTimestampPreviousHour; + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator_Notify ElectricityCountReadTimeRelDelta : " . $ElectricityCountReadingLastChangeDelta; + + if (($ElectricityCountReadingTimestampCurrentHour < $ElectricityCountReadingTimestampPreviousHour) || ($ElectricityCountReadingLastChangeDelta > 86400)) { ### Create Log entries for debugging - Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - First reading of day detected"; + Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - First reading of day detected OR last reading is older than 24h!"; ### Calculate Electricity energy of previous day € = (Wprevious[kWh] - WcurrentDay[kWh]) my $ElectricityCalcEnergyDayLast = ($ElectricityCountReadingValuePrevious - ReadingsVal($ElectricityCalcReadingDestinationDeviceName, $ElectricityCalcReadingPrefix . "_CounterDay1st", "0")); @@ -791,6 +933,12 @@ sub ElectricityCalculator_Notify($$) my $ElectricityCountReadingValueDelta = sprintf($ElectricityCalcDev->{system}{DecimalPlace}, ($ElectricityCountReadingValueCurrent)) - sprintf($ElectricityCalcDev->{system}{DecimalPlace}, ($ElectricityCountReadingValuePrevious)); Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - ElectricityCountReadingValueDelta : " . $ElectricityCountReadingValueDelta; + ### If the value has been changed since the last one + if ($ElectricityCountReadingValueDelta > 0) { + ### Save current Timestamp as UNIX epoch into hash if the + readingsSingleUpdate($ElectricityCalcDev, "." . $ElectricityCalcReadingPrefix . "_LastUpdateTimestampUnix", $ElectricityCountReadingTimestampCurrentRelative, 0); + } + ### Calculate Current Power P = DW/Dt[kWh/s] * 3600[s/h] * 1000 [1/k] / SiPrefixPowerFactor my $ElectricityCalcPowerCurrent = ($ElectricityCountReadingValueDelta / $ElectricityCountReadingTimestampDelta) * 3600 * 1000 / $ElectricityCalcDev->{system}{SiPrefixPowerFactor}; @@ -977,581 +1125,104 @@ sub ElectricityCalculator_Notify($$)
- The ElectricityCalculator Module calculates the electrical energy consumption and costs of one ore more electricity meters. - 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. - - 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. - - The ElectricityCalculator module provides several current, historical, statistical values around with respect to one or more electricity meter and creates respective readings. - - To avoid waiting for max. 12 months to have realistic values, the readings - <DestinationDevice>_<SourceCounterReading>_CounterDay1st ,- <DestinationDevice>_<SourceCounterReading>_CounterMonth1st ,- <DestinationDevice>_<SourceCounterReading>_CounterYear1st and- <DestinationDevice>_<SourceCounterReading>_CounterMeter1st - must be corrected with real values by using the setreading - command.- 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. - - Intervalls smaller than 10s will be discarded to avoid peaks due to fhem blockages (e.g. DbLog - reducelog). - - |
-
Define |
define <name> ElectricityCalculator <regex> |
<name> : | The name of the calculation device. (E.g.: "myElectricityCalculator") |
<regex> : | A valid regular expression (also known as regex or regexp) of the event where the counter can be found |
define myElectricityCalculator ElectricityCalculator myElectricityCounter:countersA.* |
Attributes |
-
- In addition the global attributes e.g. room can be used. - |
- | |
BasicPricePerAnnum : | A valid float number for basic annual fee in the chosen currency for the electricity supply to the home. - The value is provided by your local electricity supplier and is shown on your electricity bill. - For UK and US users it may known under "standing charge". Please make sure it is based on one year! - The default value is 0.00 - |
- | |
ElectricityKwhPerCounts : | A valid float number of electric energy in kWh per counting ticks. - 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). - 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. - The default value is 1 (= the counter is already providing kWh) - |
Attributes | |
In addition the global attributes e.g. room can be used. |
- | |
MonthOfAnnualReading : | A valid integer number for the month when the mechanical electricity meter reading is performed every year. - The default value is 5 (May) - |
| : Current indicated total electric energy consumption as shown on mechanical electricity meter. Correct Offset-attribute if not identical. |
| : The first meter reading after midnight. |
| : The last meter reading of the previous day. |
| : The first meter reading after midnight of the first day of the month. |
| : The last meter reading of the previous month. |
| : The first meter reading after midnight of the first day of the month where the mechanical meter is read by the electricity supplier. |
| : The last meter reading of the previous meter reading year. |
| : The first meter reading after midnight of the first day of the year. |
| : The last meter reading of the previous year. |
| : Energy costs of the last day. |
| : Energy costs in the chosen currency of the last electricity meter period. |
| : Energy costs in the chosen currency of the last month. |
| : Energy costs of the last calendar year. |
| : Energy consumption in kWh since the beginning of the current day (midnight). |
| : 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. |
| : Energy costs in the chosen currency since the beginning of the current month. |
| : Energy costs in the chosen currency since the beginning of the current year. |
| : Energy consumption in kWh since the beginning of the current day (midnight). |
| : Total Energy consumption in kWh of the last day. |
| : Energy consumption in kWh since the beginning of the month of where the last electricity-meter reading has been performed by the Electricity supplier. |
| : Total Energy consumption in kWh of the last electricity-meter reading period. |
| : Energy consumption in kWh since the beginning of the current month (midnight of the first). |
| : Total Energy consumption in kWh of the last month. |
| : Energy consumption in kWh since the beginning of the current year (midnight of the first). |
| : Total Energy consumption in kWh of the last calendar year. |
| : 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. |
| : Number of month since last meter reading. The month when the reading occured is the first month = 1. |
| : Current electric Power. (Average Power between current and previous measurement.) |
| : Average electric Power since midnight. |
| : Maximum Power peak since midnight. |
| : Minimum Power peak since midnight. |
- | |
ReadingDestination : | One of the pre-defined list for the destination of the calculated readings: [CalculatorDevice,CounterDevice]. - The CalculatorDevice is the device which has been created with this module. - The CounterDevice is the Device which is reading the mechanical Electricity-meter. - The default value is CalculatorDevice - Therefore the readings will be written into this device. - |
- | |
SiPrefixPower : | One value of the pre-defined list: W (Watt), kW (Kilowatt), MW (Megawatt) or GW (Gigawatt). - It defines which SI-prefix for the power value shall be used. The power value will be divided accordingly by multiples of 1000. - The default value is W (Watt). - |
- | |
DecimalPlace : | One value of the pre-defined list 3 to 7. - It defines to which accuracy in decimal places all results shall be calculated. - The default value is 3 = 0.001. - |
- | |
<DestinationDevice>_<SourceCounterReading>_CounterCurrent : | Current indicated total electric energy consumption as shown on mechanical electricity meter. Correct Offset-attribute if not identical. - |
- | |
<DestinationDevice>_<SourceCounterReading>_CounterDay1st : | The first meter reading after midnight. - |
- | |
<DestinationDevice>_<SourceCounterReading>_CounterDayLast : | The last meter reading of the previous day. - |
- | |
<DestinationDevice>_<SourceCounterReading>_CounterMonth1st : | The first meter reading after midnight of the first day of the month. - |
- | |
<DestinationDevice>_<SourceCounterReading>_CounterMonthLast : | The last meter reading of the previous month. - |
- | |
<DestinationDevice>_<SourceCounterReading>_CounterMeter1st : | The first meter reading after midnight of the first day of the month where the mechanical meter is read by the electricity supplier. - |
- | |
<DestinationDevice>_<SourceCounterReading>_CounterMeterLast : | The last meter reading of the previous meter reading year. - |
- | |
<DestinationDevice>_<SourceCounterReading>_CounterYear1st : | The first meter reading after midnight of the first day of the year. - |
- | |
<DestinationDevice>_<SourceCounterReading>_CounterYearLast : | The last meter reading of the previous year. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostDayLast : | Energy costs of the last day. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostMeterLast : | Energy costs in the chosen currency of the last electricity meter period. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostMonthLast : | Energy costs in the chosen currency of the last month. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostYearLast : | Energy costs of the last calendar year. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostDay : | Energy consumption in kWh since the beginning of the current day (midnight). - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostMeter : | 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. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostMonth : | Energy costs in the chosen currency since the beginning of the current month. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostYear : | Energy costs in the chosen currency since the beginning of the current year. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyDay : | Energy consumption in kWh since the beginning of the current day (midnight). - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyDayLast : | Total Energy consumption in kWh of the last day. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyMeter : | Energy consumption in kWh since the beginning of the month of where the last electricity-meter reading has been performed by the Electricity supplier. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyMeterLast : | Total Energy consumption in kWh of the last electricity-meter reading period. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyMonth : | Energy consumption in kWh since the beginning of the current month (midnight of the first). - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyMonthLast : | Total Energy consumption in kWh of the last month. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyYear : | Energy consumption in kWh since the beginning of the current year (midnight of the first). - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyYearLast : | Total Energy consumption in kWh of the last calendar year. - |
- | |
<DestinationDevice>_<SourceCounterReading>_FinanceReserve : | 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. - |
- | |
<DestinationDevice>_<SourceCounterReading>_MonthMeterReading : | Number of month since last meter reading. The month when the reading occured is the first month = 1. - |
- | |
<DestinationDevice>_<SourceCounterReading>_PowerCurrent : | Current electric Power. (Average Power between current and previous measurement.) - |
- | |
<DestinationDevice>_<SourceCounterReading>_PowerDayAver : | Average electric Power since midnight. - |
- | |
<DestinationDevice>_<SourceCounterReading>_PowerDayMax : | Maximum Power peak since midnight. - |
- | |
<DestinationDevice>_<SourceCounterReading>_PowerDayMin : | Minimum Power peak since midnight. - |
- Das ElectricityCalculator Modul berechnet den Verbrauch an elektrischer Energie (Stromverbrauch) und den verbundenen Kosten von einem oder mehreren Elektrizitätszählern. - Es ist kein eigenes Zählermodul sondern benötigt eine Regular Expression (regex or regexp) um das Reading mit den Zählimpulse von einem oder mehreren Electrizitätszählern zu finden. - - 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. - - Das ElectricityCalculator Modul berechnet augenblickliche, historische statistische und vorhersehbare Werte von einem oder mehreren Elektrizitätszählern und erstellt die entsprechenden Readings. - - Um zu verhindern, dass man bis zu 12 Monate warten muss, bis alle Werte der Realität entsprechen, müssen die Readings - <DestinationDevice>_<SourceCounterReading>_CounterDay1st ,- <DestinationDevice>_<SourceCounterReading>_CounterMonth1st ,- <DestinationDevice>_<SourceCounterReading>_CounterYear1st und- <DestinationDevice>_<SourceCounterReading>_CounterMeter1st - entsprechend mit dem setreading - Befehl korrigiert werden.- Diese Werte findet man unter Umständen auf der letzten Abrechnung des Elektrizitätsversorgers. Andernfalls dauert es bis zu 24h für die täglichen, 30 Tage für die monatlichen und bis zu 12 Monate für die jährlichen Werte bis diese der Realität entsprechen. - - - Intervalle kleienr als 10s werden ignoriert um Spitzen zu verhindern die von Blockaden des fhem Systems hervorgerufen werden (z.B. DbLog - reducelog). - |
-
Define |
define <name> ElectricityCalculator <regex> |
<name> : | Der Name dieses Berechnungs-Device. Empfehlung: "myElectricityCalculator". |
<regex> : | Eine gültige Regular Expression (regex or regexp) von dem Event wo der Zählerstand gefunden werden kann |
define myElectricityCalculator ElectricityCalculator myElectricityCounter:countersA.* |
Attributes |
-
- Zusätzlich können die globalen Attribute wie room verwendet werden. - |
- | |
BasicPricePerAnnum : | Eine gültige float Zahl für die jährliche Grundgebühr in der gewählten Währung für die Elektrizitäts-Versorgung zum Endverbraucher. - Dieser Wert stammt vom Elektrizitätsversorger und steht auf der Abrechnung. - Der Standard Wert ist 0.00 - |
- | |
ElectricityKwhPerCounts : | Eine gültige float-Zahl für die Menge kWh pro Zählimpulsen. - Der Wert ist durch das mechanische Zählwerk des Elektrizitätszählern vorgegeben. ElectricityKwhPerCounts = 0.001 bedeutet, dass jeder Zählimpuls ein Tausendstel einer kWh ist (=Wh). - Einige elektronische Zähler (Bsp.: HomeMatic HM-ES-TX-WM) stellen die gezählte Menge an elektrischer Energie als Wh bereit. - Aus diesem Grund muss dieses Attribut auf 0.001 gesetzt werden um eine korrekte Transformation in kWh zu ermöglichen. - Der Standard-Wert ist 1 - |
Attributes | |
Zusätzlich können die globalen Attribute wie room verwendet werden. |
- | |
MonthOfAnnualReading : | Eine gültige Ganz-Zahl für den Monat wenn der mechanische Elektrizitätszähler jedes Jahr durch den Elektrizitätsversorger abgelesen wird. - Der Standard-Wert ist 5 (Mai) - |
| : Aktueller Zählerstand am mechanischen Zähler. Bei Unterschied muss das Offset-Attribut entspechend korrigiert werden. |
| : Der erste Zählerstand des laufenden Tages seit Mitternacht. |
| : Der letzte Zählerstand des vorherigen Tages. |
| : Der erste Zählerstand seit Mitternacht des ersten Tages der laufenden Ableseperiode. |
| : Der letzte Zählerstand seit Mitternacht des ersten Tages der vorherigen Ableseperiode. |
| : Der erste Zählerstand seit Mitternacht des ersten Tages des laufenden Monats. |
| : Der letzte Zählerstand des vorherigen Monats. |
| : Der erste Zählerstand seit Mitternacht des ersten Tages des laufenden Jahres. |
| : Der letzte Zählerstand des letzten Jahres. |
| : Elektrische Energiekosten des letzten Tages. |
| : Elektrische Energiekosten der letzten Ableseperiode. |
| : Elektrische Energiekosten des letzten Monats. |
| : Elektrische Energiekosten des letzten Kalenderjahres. |
| : Energiekosten in gewählter Währung seit Mitternacht des laufenden Tages. |
| : Energiekosten in gewählter Währung seit Beginn der laufenden Ableseperiode. |
| : Energiekosten in gewählter Währung seit Beginn des laufenden Monats. |
| : Energiekosten in gewählter Währung seit Beginn des laufenden Kalenderjahres. |
| : Energieverbrauch seit Beginn der aktuellen Tages (Mitternacht). |
| : Energieverbrauch in kWh des vorherigen Tages. |
| : Energieverbrauch seit Beginn der aktuellen Ableseperiode. |
| : Energieverbrauch in kWh der vorherigen Ableseperiode. |
| : Energieverbrauch seit Beginn des aktuellen Monats. |
| : Energieverbrauch in kWh des vorherigen Monats. |
| : Energieverbrauch seit Beginn des aktuellen Kalenderjahres. |
| : Energieverbrauch in kWh des vorherigen Kalenderjahres. |
| : Finanzielle Reserve basierend auf den Abschlagszahlungen die jeden Monat an den Elektrizitätsversorger gezahlt werden. Bei negativen Werten ist von einer Nachzahlung auszugehen. |
| : Anzahl der Monate seit der letzten Zählerablesung. Der Monat der Zählerablesung ist der erste Monat = 1. |
| : Aktuelle elektrische Leistung. (Mittelwert zwischen aktueller und letzter Messung) |
| : Mittlere elektrische Leistung seit Mitternacht. |
| : Maximale elektrische Leistungsaufnahme seit Mitternacht. |
| : Minimale elektrische Leistungsaufnahme seit Mitternacht. |
- | |
ReadingDestination : | Eines der vordefinerten Device als Ziel der errechneten Readings: [CalculatorDevice,CounterDevice]. - Das CalculatorDevice ist das mit diesem Modul erstellte Device. - Das CounterDevice ist das Device von welchem der mechanische Zähler ausgelesen wird. - Der Standard-Wert ist CalculatorDevice. - |
- | |
SiPrefixPower : | Ein Wert der vorgegebenen Auswahlliste: W (Watt), kW (Kilowatt), MW (Megawatt) or GW (Gigawatt). - Es definiert welcher SI-Prefix verwendet werden soll und teilt die Leistung entsprechend durch ein Vielfaches von 1000. - Der Standard-Wert ist W (Watt). - |
- | |
DecimalPlace : | Ein Wert der vorgegebenen Auswahlliste von 3 bis 7. - Es definiert die Genauigkeit in Nachkommastellen mit welcher die Ergebnisse berechnet werden. - Der Standard-Wert ist 3 = 0,001. - |
- | |
<DestinationDevice>_<SourceCounterReading>_CounterCurrent : | Aktueller Zählerstand am mechanischen Zähler. Bei Unterschied muss das Offset-Attribut entspechend korrigiert werden. - |
- | |
<DestinationDevice>_<SourceCounterReading>_CounterDay1st : | Der erste Zählerstand des laufenden Tages seit Mitternacht. - |
- | |
<DestinationDevice>_<SourceCounterReading>_CounterDayLast : | Der letzte Zählerstand des vorherigen Tages. - |
- | |
<DestinationDevice>_<SourceCounterReading>_CounterMeter1st : | Der erste Zählerstand seit Mitternacht des ersten Tages der laufenden Ableseperiode. - |
- | |
<DestinationDevice>_<SourceCounterReading>_CounterMeterLast : | Der letzte Zählerstand seit Mitternacht des ersten Tages der vorherigen Ableseperiode. - |
- | |
<DestinationDevice>_<SourceCounterReading>_CounterMonth1st : | Der erste Zählerstand seit Mitternacht des ersten Tages des laufenden Monats. - |
- | |
<DestinationDevice>_<SourceCounterReading>_CounterMonthLast : | Der letzte Zählerstand des vorherigen Monats. - |
- | |
<DestinationDevice>_<SourceCounterReading>_CounterYear1st : | Der erste Zählerstand seit Mitternacht des ersten Tages des laufenden Jahres. - |
- | |
<DestinationDevice>_<SourceCounterReading>_CounterYearLast : | Der letzte Zählerstand des letzten Jahres. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostDayLast : | Elektrische Energiekosten des letzten Tages. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostMeterLast : | Elektrische Energiekosten der letzten Ableseperiode. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostMonthLast : | Elektrische Energiekosten des letzten Monats. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostYearLast : | Elektrische Energiekosten des letzten Kalenderjahres. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostDay : | Energiekosten in gewählter Währung seit Mitternacht des laufenden Tages. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostMeter : | Energiekosten in gewählter Währung seit Beginn der laufenden Ableseperiode. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostMonth : | Energiekosten in gewählter Währung seit Beginn des laufenden Monats. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostYear : | Energiekosten in gewählter Währung seit Beginn des laufenden Kalenderjahres. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyDay : | Energieverbrauch seit Beginn der aktuellen Tages (Mitternacht). - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyDayLast : | Energieverbrauch in kWh des vorherigen Tages. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyMeter : | Energieverbrauch seit Beginn der aktuellen Ableseperiode. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyMeterLast : | Energieverbrauch in kWh der vorherigen Ableseperiode. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyMonth : | Energieverbrauch seit Beginn des aktuellen Monats. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyMonthLast : | Energieverbrauch in kWh des vorherigen Monats. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyYear : | Energieverbrauch seit Beginn des aktuellen Kalenderjahres. - |
- | |
<DestinationDevice>_<SourceCounterReading>_EnergyYearLast : | Energieverbrauch in kWh des vorherigen Kalenderjahres. - |
- | |
<DestinationDevice>_<SourceCounterReading>_FinanceReserve : | Finanzielle Reserve basierend auf den Abschlagszahlungen die jeden Monat an den Elektrizitätsversorger gezahlt werden. Bei negativen Werten ist von einer Nachzahlung auszugehen. - |
- | |
<DestinationDevice>_<SourceCounterReading>_MonthMeterReading : | Anzahl der Monate seit der letzten Zählerablesung. Der Monat der Zählerablesung ist der erste Monat = 1. - |
- | |
<DestinationDevice>_<SourceCounterReading>_PowerCurrent : | Aktuelle elektrische Leistung. (Mittelwert zwischen aktueller und letzter Messung) - |
- | |
<DestinationDevice>_<SourceCounterReading>_PowerDayAver : | Mittlere elektrische Leistung seit Mitternacht. - |
- | |
<DestinationDevice>_<SourceCounterReading>_PowerDayMax : | Maximale elektrische Leistungsaufnahme seit Mitternacht. - |
- | |
<DestinationDevice>_<SourceCounterReading>_PowerDayMin : | Minimale elektrische Leistungsaufnahme seit Mitternacht. - |