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($$) + + + + + + + + + + + + + + + +