I’ve been trying to get the current month Kw/h, previous month, current year and previous year for the consumption of the heatpump, but I simply cannot get this working.
This is what I have right now:
rule "Calculate HeatPump Current Month Consumption"
when
Time cron "* * * * * ?" // Every minute
then
val ZonedDateTime startOfMonth = now.withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0).withNano(0)
logInfo("StartOfMonth", new DateTimeType(startOfMonth))
var monthlyConsumption = 0.0
(1..now.dayOfMonth).forEach[ day |
val dayStart = startOfMonth.plusDays(day - 1)
logInfo("EachDay","Day: "+day+" - dayStart: "+dayStart)
val dailyPhase1 = HeatPumpPhase1.averageSince(dayStart)
val dailyPhase2 = HeatPumpPhase2.averageSince(dayStart)
val dailyPhase3 = HeatPumpPhase3.averageSince(dayStart)
val dailyVMC = VMCEnergy.averageSince(dayStart)
logInfo("Debug", "DailyPhase1: " + dailyPhase1)
logInfo("Debug", "DailyPhase2: " + dailyPhase2)
logInfo("Debug", "DailyPhase3: " + dailyPhase3)
logInfo("Debug", "DailyVMC: " + dailyVMC)
if (dailyPhase1 !== null && dailyPhase2 !== null && dailyPhase3 !== null && dailyVMC !== null) {
val dailyTotal = (dailyPhase1 + dailyPhase2 + dailyPhase3 - dailyVMC)
monthlyConsumption += dailyTotal
logInfo("DailyTotal", "Total for day " + day + ": " + dailyTotal)
} else {
logInfo("NullCheck", "One or more values are null for day " + day)
}
]
logInfo("MonthlyTotal", monthlyConsumption)
//HeatPumpCurrentMonthkWh.postUpdate(monthlyConsumption)
end
This is what I see in my log:
2024-01-17 18:44:34.338 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'energy.rules'
2024-01-17 18:44:36.255 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'energy-2' failed: An error occurred during the script execution: Could not invoke method: org.openhab.core.model.script.actions.Log.logInfo(java.lang.String,java.lang.String,java.lang.Object[]) on instance: null in energy
So I’m completely out of ideas. I’ve tried to implement some of the examples here but I haven’t been successfull at all because I am always getting that same error, again and again.