I have rules that calculates how long my air conditionning works in a day. I calculate the time between the starting hour and the finnishing hour. After that, I would like to add the difference to the previus value
val DateTimeType startVMC = vmcStart.state as DateTimeType
val DateTimeType stopVMC = vmcStart.state as DateTimeType
val Number workTime = Minutes::minutesBetween(new DateTime(startVMC.calendar.timeInMillis), now).getMinutes()
vmcDuree.postUpdate(workTime)
Thank you Vincent. Unfortunately it is not working.
In the log I have an error
Rule ‘VMC Last Stop’: An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.postUpdate(org.eclipse.smarthome.core.items.Item,java.lang.Number) on instance: null
vmcDuree.postUpdate(workTime)
val Number vmcduration = vmcDureeTot.state //This line gives me a probleme
val Number duration = workTime + vmcduration
vmcDureeTot.sendCommand(duration)
If I replace vmcDureeTot.state by a number (12 for exemple), everything works well
rule "Last Start"
when
Item VMCslow changed to ON
then
vmcStart.sendCommand(new DateTimeType)
end
rule "VMC Last Stop"
when
Item VMCslow changed to OFF
then
vmcStop.sendCommand(new DateTimeType)
val DateTimeType startVMC = vmcStart.state as DateTimeType
val DateTimeType stopVMC = vmcStart.state as DateTimeType
val Number workTime = Minutes::minutesBetween(new DateTime(startVMC.calendar.timeInMillis), now).getMinutes()
vmcDuree.postUpdate(workTime)
val Number vmcduration = VmcDureeTot.state
val Number duration = workTime + vmcduration
VmcDureeTot.sendCommand(duration)
end
and logs :
Rule 'VMC Last Stop': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.lib.NumberExtensions.operator_plus(java.lang.Number,java.lang.Number) on instance: null
rule "Last Start"
when
Item VMCslow changed to ON
then
vmcStart.sendCommand(new DateTimeType)
logInfo("vmc.rules", "Start")
end
rule "VMC Last Stop"
when
Item VMCslow changed to OFF
then
vmcStop.sendCommand(new DateTimeType)
val DateTimeType startVMC = vmcStart.state as DateTimeType
val DateTimeType stopVMC = vmcStart.state as DateTimeType
val Number workTime = Minutes::minutesBetween(new DateTime(startVMC.calendar.timeInMillis), now).getMinutes()
vmcDuree.postUpdate(workTime)
logInfo("vmc.rules", "1")
val Number vmcduration = VmcDureeTot.state
logInfo("vmc.rules", "2")
val Number duration = workTime + vmcduration
logInfo("vmc.rules", "3")
VmcDureeTot.sendCommand(vmcduration)
logInfo("vmc.rules", "4")
end