From f8a8b423f7499eecebc39bfdcccccad60b6b783f Mon Sep 17 00:00:00 2001 From: Sailor <> Date: Tue, 20 Dec 2016 09:11:53 +0000 Subject: [PATCH] 73_GasCalculator: bugfix: Corrected month of annual reading git-svn-id: https://svn.fhem.de/fhem/trunk@12848 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/73_GasCalculator.pm | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/fhem/FHEM/73_GasCalculator.pm b/fhem/FHEM/73_GasCalculator.pm index 21e42e16b..1491c1724 100644 --- a/fhem/FHEM/73_GasCalculator.pm +++ b/fhem/FHEM/73_GasCalculator.pm @@ -553,6 +553,9 @@ sub GasCalculator_Notify($$) my $GasCountReadingTimestampCurrentRelative = time_str2num($GasCountReadingTimestampCurrent); my($GasCountReadingTimestampCurrentSec,$GasCountReadingTimestampCurrentMin,$GasCountReadingTimestampCurrentHour,$GasCountReadingTimestampCurrentMday,$GasCountReadingTimestampCurrentMon,$GasCountReadingTimestampCurrentYear,$GasCountReadingTimestampCurrentWday,$GasCountReadingTimestampCurrentYday,$GasCountReadingTimestampCurrentIsdst) = localtime($GasCountReadingTimestampCurrentRelative); + ### Correct current month by one month since Unix/Linux start January with 0 instead of 1 + $GasCountReadingTimestampCurrentMon = $GasCountReadingTimestampCurrentMon + 1; + ### Create Log entries for debugging Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - Reading Name : " . $GasCountReadingName; Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - Previous Reading Value : " . $GasCountReadingTimestampPrevious; @@ -689,13 +692,13 @@ sub GasCalculator_Notify($$) ### Calculate the payment month since the year of gas meter reading started my $GasCalcMeterYearMonth=0; - if (($GasCountReadingTimestampCurrentMon + 1 - $attr{$GasCalcName}{MonthOfAnnualReading} + 1) < 1) + if (($GasCountReadingTimestampCurrentMon - $attr{$GasCalcName}{MonthOfAnnualReading} + 1) < 1) { - $GasCalcMeterYearMonth = 12 + $GasCountReadingTimestampCurrentMon + 1 - $attr{$GasCalcName}{MonthOfAnnualReading} + 1; + $GasCalcMeterYearMonth = 12 + $GasCountReadingTimestampCurrentMon - $attr{$GasCalcName}{MonthOfAnnualReading}; } else { - $GasCalcMeterYearMonth = $GasCountReadingTimestampCurrentMon + 1 - $attr{$GasCalcName}{MonthOfAnnualReading} + 1; + $GasCalcMeterYearMonth = 1 + $GasCountReadingTimestampCurrentMon - $attr{$GasCalcName}{MonthOfAnnualReading}; } ### Calculate reserves at gas provider based on monthly advance payments within year of gas meter reading @@ -710,6 +713,7 @@ sub GasCalculator_Notify($$) Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - _______Times__________________________________________"; Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - GasCalcMeterYearMonth : " . $GasCalcMeterYearMonth; + Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - Current Month : " . $GasCountReadingTimestampCurrentMon; Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - _______Energy_________________________________________"; Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - GasCalcEnergyDay : " . sprintf('%.3f', ($GasCalcEnergyDay)) . " kWh"; @@ -795,6 +799,9 @@ sub GasCalculator_Notify($$) ### Write reserves at gas provider based on monthly advance payments within year of gas meter reading readingsBulkUpdate($GasCalcReadingDestinationDevice, $GasCalcReadingPrefix . "_FinanceReserve", sprintf('%.3f', ($GasCalcReserves))); + ### Write months since last meter reading + readingsBulkUpdate($GasCalcReadingDestinationDevice, $GasCalcReadingPrefix . "_MonthMeterReading", sprintf('%.0f', ($GasCalcMeterYearMonth))); + ### Finish and execute Bulkupdate readingsEndUpdate($GasCalcReadingDestinationDevice, 1); } @@ -1246,6 +1253,17 @@ sub GasCalculator_Notify($$) + + + +