From 5e285b19c700d6f73b60bd86bfc1e0a3c9ae5943 Mon Sep 17 00:00:00 2001 From: sailor-fhem <> Date: Wed, 10 Aug 2016 18:24:48 +0000 Subject: [PATCH] 73_GasCalculator: feature: New Readings "EnergyLastX" and "EnergyCostLastX" git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@11939 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- FHEM/73_GasCalculator.pm | 214 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 214 insertions(+) diff --git a/FHEM/73_GasCalculator.pm b/FHEM/73_GasCalculator.pm index 9e577a53c..256a14f0a 100644 --- a/FHEM/73_GasCalculator.pm +++ b/FHEM/73_GasCalculator.pm @@ -530,6 +530,14 @@ sub GasCalculator_Notify($$) ### Create Log entries for debugging Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - First reading of day detected"; + ### Calculate gas energy of previous day € = (Vprevious[cubic] - V1stDay[cubic]) * GaszValue * GasNominalHeatingValue[kWh/cubic] + my $GasCalcEnergyLastDay = ($GasCountReadingValuePrevious - ReadingsVal($GasCalcReadingDestinationDeviceName, $GasCalcReadingPrefix . "_Vol1stDay", "0")) * $attr{$GasCalcName}{GaszValue} * $attr{$GasCalcName}{GasNominalHeatingValue}; + ### Calculate pure gas cost of previous day GasCalcEnergyLastDay * Price per kWh + my $GasCalcEnergyCostLastDay = $GasCalcEnergyLastDay * $attr{$GasCalcName}{GasPricePerKWh}; + ### Save gas energy and pure cost of previous day + readingsSingleUpdate( $GasCalcReadingDestinationDevice, $GasCalcReadingPrefix . "_CostLastDay", (sprintf('%.3f', ($GasCalcEnergyCostLastDay))), 1); + readingsSingleUpdate( $GasCalcReadingDestinationDevice, $GasCalcReadingPrefix . "_EnergyLastDay", (sprintf('%.3f', ($GasCalcEnergyLastDay))), 1); + ### Save current Volume as first reading of day = first after midnight and reset min, max value, value counter and value sum readingsSingleUpdate( $GasCalcReadingDestinationDevice, $GasCalcReadingPrefix . "_Vol1stDay", $GasCountReadingValueCurrent, 1); readingsSingleUpdate( $GasCalcReadingDestinationDevice, $GasCalcReadingPrefix . "_VolLastDay", $GasCountReadingValuePrevious, 1); @@ -544,6 +552,14 @@ sub GasCalculator_Notify($$) ### Create Log entries for debugging Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - First reading of month detected"; + ### Calculate gas energy of previous month € = (Vprevious[cubic] - V1stReadMonth[cubic]) * GaszValue * GasNominalHeatingValue[kWh/cubic] + my $GasCalcEnergyLastMonth = ($GasCountReadingValuePrevious - ReadingsVal($GasCalcReadingDestinationDeviceName, $GasCalcReadingPrefix . "_Vol1stMonth", "0")) * $attr{$GasCalcName}{GaszValue} * $attr{$GasCalcName}{GasNominalHeatingValue}; + ### Calculate pure gas cost of previous month GasCalcEnergyLastMonth * Price per kWh + my $GasCalcEnergyCostLastMonth = $GasCalcEnergyLastMonth * $attr{$GasCalcName}{GasPricePerKWh}; + ### Save gas energy and pure cost of previous month + readingsSingleUpdate( $GasCalcReadingDestinationDevice, $GasCalcReadingPrefix . "_CostLastMonth", (sprintf('%.3f', ($GasCalcEnergyCostLastMonth))), 1); + readingsSingleUpdate( $GasCalcReadingDestinationDevice, $GasCalcReadingPrefix . "_EnergyLastMonth", (sprintf('%.3f', ($GasCalcEnergyLastMonth ))), 1); + ### Save current Volume as first reading of month and the last reading of the last month readingsSingleUpdate( $GasCalcReadingDestinationDevice, $GasCalcReadingPrefix . "_Vol1stMonth", $GasCountReadingValueCurrent, 1); readingsSingleUpdate( $GasCalcReadingDestinationDevice, $GasCalcReadingPrefix . "_VolLastMonth", $GasCountReadingValuePrevious, 1); @@ -553,6 +569,19 @@ sub GasCalculator_Notify($$) { ### Create Log entries for debugging Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - First reading of month for meter reading detected"; + Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - Current month is : " . $GasCountReadingTimestampCurrentMon; + Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - Attribute MonthOfAnnualReading is : " . $attr{$GasCalcName}{MonthOfAnnualReading}; + Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - Vol1stMeter is : " . $GasCountReadingValueCurrent; + Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - VolLastMeter is : " . $GasCountReadingValuePrevious; + + ### Calculate gas energy of previous meter reading year € = (Vprevious[cubic] - V1stMeter[cubic]) * GaszValue * GasNominalHeatingValue[kWh/cubic] + my $GasCalcEnergyLastMeter = ($GasCountReadingValuePrevious - ReadingsVal($GasCalcReadingDestinationDeviceName, $GasCalcReadingPrefix . "_Vol1stMeter", "0")) * $attr{$GasCalcName}{GaszValue} * $attr{$GasCalcName}{GasNominalHeatingValue}; + ### Calculate pure gas cost of previous meter reading year € = GasCalcEnergyLastMeter * Price per kWh + my $GasCalcEnergyCostLastMeter = $GasCalcEnergyLastMeter * $attr{$GasCalcName}{GasPricePerKWh}; + + ### Save gas energy and pure cost of previous meter year + readingsSingleUpdate( $GasCalcReadingDestinationDevice, $GasCalcReadingPrefix . "_CostLastMeter", (sprintf('%.3f', ($GasCalcEnergyCostLastMeter))), 1); + readingsSingleUpdate( $GasCalcReadingDestinationDevice, $GasCalcReadingPrefix . "_EnergyLastMeter", (sprintf('%.3f', ($GasCalcEnergyLastMeter ))), 1); ### Save current Volume as first reading of month where gas-meter is read and the last measured value of the last meter period readingsSingleUpdate( $GasCalcReadingDestinationDevice, $GasCalcReadingPrefix . "_Vol1stMeter", $GasCountReadingValueCurrent, 1); @@ -565,6 +594,15 @@ sub GasCalculator_Notify($$) ### Create Log entries for debugging Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - First reading of calendar year detected"; + ### Calculate gas energy of previous calendar year € = (Vcurrent[cubic] - V1stYear[cubic]) * GaszValue * GasNominalHeatingValue[kWh/cubic] + my $GasCalcEnergyLastYear = ($GasCountReadingValuePrevious - ReadingsVal($GasCalcReadingDestinationDeviceName, $GasCalcReadingPrefix . "_Vol1stYear", "0")) * $attr{$GasCalcName}{GaszValue} * $attr{$GasCalcName}{GasNominalHeatingValue}; + ### Calculate pure gas cost of previous calendar year € = GasCalcEnergyLastYear * Price per kWh + my $GasCalcEnergyCostLastYear = $GasCalcEnergyLastYear * $attr{$GasCalcName}{GasPricePerKWh}; + + ### Save gas energy and pure cost of previous calendar year + readingsSingleUpdate( $GasCalcReadingDestinationDevice, $GasCalcReadingPrefix . "_CostLastYear", (sprintf('%.3f', ($GasCalcEnergyCostLastYear))), 1); + readingsSingleUpdate( $GasCalcReadingDestinationDevice, $GasCalcReadingPrefix . "_EnergyLastYear", (sprintf('%.3f', ($GasCalcEnergyLastYear ))), 1); + ### Save current Volume as first reading of the calendar year and the last reading of the previous year readingsSingleUpdate( $GasCalcReadingDestinationDevice, $GasCalcReadingPrefix . "_Vol1stYear", $GasCountReadingValueCurrent, 1); readingsSingleUpdate( $GasCalcReadingDestinationDevice, $GasCalcReadingPrefix . "_VolLastYear", $GasCountReadingValuePrevious, 1); @@ -1022,6 +1060,17 @@ sub GasCalculator_Notify($$) +
+ | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostLastDay : | Energy costs of the last day. + |
+ | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostLastMeter : | Energy costs in the chosen currency of the last gas-meter period. + |
+ | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostLastMonth : | Energy costs in the chosen currency of the last month. + |
+ | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostLastYear : | Energy costs of the last calendar year. + |
+ | |
<DestinationDevice>_<SourceCounterReading>_EnergyLastDay : | Total Energy consumption in kWh of the last day. + |
+ | |
<DestinationDevice>_<SourceCounterReading>_EnergyLastMeter : | Total Energy consumption in kWh of the last gas-meter reading period. + |
+ | |
<DestinationDevice>_<SourceCounterReading>_EnergyLastMonth : | Total Energy consumption in kWh of the last month. + |
+ | |
<DestinationDevice>_<SourceCounterReading>_EnergyLastYear : | Total Energy consumption in kWh of the last calendar year. + |
+ | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostLastDay : | Energiekosten in der gewählten Währung des letzten Tages. + |
+ | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostLastMeter : | Energiekosten in der gewählten Währung der letzten Zählperiode des Gas-Versorgers. + |
+ | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostLastMonth : | Energiekosten in der gewählten Währung des letzten Monats. + |
+ | |
<DestinationDevice>_<SourceCounterReading>_EnergyCostLastYear : | Energiekosten in der gewählten Währung des letzten Jahres. + |
+ | |
<DestinationDevice>_<SourceCounterReading>_EnergyLastDay : | Gesamter Energieverbrauch des letzten Tages (Gestern). + |
+ | |
<DestinationDevice>_<SourceCounterReading>_EnergyLastMeter : | Gesamter Energieverbrauch der letzten Zählerperiode des Gas-Versorgers. + |
+ | |
<DestinationDevice>_<SourceCounterReading>_EnergyLastMonth : | Gesamter Energieverbrauch im letzten Monat. + |
+ | |
<DestinationDevice>_<SourceCounterReading>_EnergyLastYear : | Gesamter Energieverbrauch in kWh des letzten Kalender-Jahres. + |