I’m calculating heating times for my watertank and want to know how much oil I need to heat the tank.
the syntax for:
val Number Temp_t2 = Boiler_Temperatur.historicState(now.minusMinutes(timeONtoOFF)).state as DecimalType
seems to be wrong. entering a value instead of timeONtoOFF works fine. why is now.minusMinutes(timeONtoOFF)).state not working? timeONtoOFF is a value already, isn’t it?
var Number heatON = 0
var Number heatOFF = 0
var Number timeOFFtoON = 0
var Number timeONtoOFF = 0
rule "watertank is heating"
when
Item Boiler_Temperatur changed
then
logInfo("Watertank temp actual: " + Boiler_Temperatur.state +"°", "previous: " + previousState + "°")
if (Boiler_Temperatur.state > previousState as DecimalType ) {
if (Boilerheating.state == OFF) Boilerheating.sendCommand(ON)
}
else if ((Boiler_Temperatur.state < previousState as DecimalType) && Boilerheating.state == ON) Boilerheating.sendCommand(OFF)
end
rule "Boilertemperatur Differenz letzte Stunde"
when
Item Boiler_Temperatur changed
then
val Number Temp_t1 = Boiler_Temperatur.historicState(now.minusHours(1)).state as DecimalType
val Number Temp_t0 = Boiler_Temperatur.state as DecimalType
Tempdiff.sendCommand(Temp_t0-Temp_t1)
end
rule "Heizzeiten"
when
Item Boilerheating changed
then
switch Boilerheating.state {
case ON: {
heatON = now.millis
timeOFFtoON = (now.millis - heatOFF) / 60000
BoilerOFFtoON.postUpdate(timeOFFtoON)
logInfo("testrule", "Boiler hält Temp für: " + timeOFFtoON + " minutes")
}
case OFF: {
heatOFF = now.millis
timeONtoOFF = (now.millis - heatON) / 60000
BoilerONtoOFF.postUpdate(timeONtoOFF)
logInfo("testrule", "Boiler benötigt zum Aufheizen: " + timeONtoOFF + " minutes")
val Number Temp_t2 = Boiler_Temperatur.historicState(now.minusMinutes(timeONtoOFF)).state as DecimalType
val Number Temp_t3 = Boiler_Temperatur.state as DecimalType
val Number kWh = 300 * 4.18 * (Temp_t3 - Temp_t2) * 0.000277777777777778
logInfo("testrule", "Boiler benötigt zum Aufheizen: " + kWh + " kWh")
val Number literoel = kWh / 10.7
logInfo("testrule", "Boiler benötigt: " + literoel + " Liter Öl zum Aufheizen")
val Number OelSumme = (Heizoel_Boiler.state as DecimalType) + literoel
Heizoel_Boiler.postUpdate(OelSumme)
}
}
end