Wasn’t sure if I should post a new thread or not.
Here goes, then I’ll break some of it up for explanation.
var String PreviousMode = "Off"
rule "Morning Central Heating Rules"
when
Item g_temperature_average received update or
Item check_temperature_min changed or
Item temperature_average changed or
Item heating_powermode changed or
Time cron "0 */5 * * * ?"
then
logInfo("MorningCentralHeating","Command Called")
var boolean heaterState = true;
var boolean withinTimer = false;
logInfo("MorningCentralHeating",String::format("Checking start/end time against current. Start: %s End: %s and current %s",heating_morning_time_on.state,heating_morning_time_off.state,new LocalTime()))
var int timeon = (heating_morning_time_on.state as DecimalType).intValue
var int timeoff = (heating_morning_time_off.state as DecimalType).intValue
logInfo("MorningCentralHeating",String::format("(0) Getting average from manually calulated average as default"))
var float avg = (temperature_average.state as DecimalType).floatValue
logInfo("MorningCentralHeating",String::format("(0) Calculated average: %s",avg))
var String ruleSection = "temp"
if (g_temperature_average.state === NULL)
logError("MorningCentralHeating",String::format("Couldn't get a reading from g_temperature_average: %s",g_temperature_average))
else
{
logInfo("MorningCentralHeating",String::format("(0) Getting average group"))
avg = (g_temperature_average.state as DecimalType).floatValue
logInfo("MorningCentralHeating",String::format("(0) Calculated average from group: %s",avg))
} //if (g_temperature_average.state === NULL)
logInfo("MorningCentralHeating",String::format("(0) Checking start/end time against current. Start: %s End: %s and current %s temp: %s",timeon,timeoff,new LocalTime(),avg))
if (heating_powermode.state == "Schedule" )
{
logInfo("MorningCentralHeating",String::format("(1.1) Got avg: %s, Getting max",avg))
var float max = (heating_morning_maximum_setpoint.state as DecimalType).floatValue
logInfo("MorningCentralHeating",String::format("(1.2) Got max: %s, Getting offset",max))
var float offset = (heating_morning_maximum_offset.state as DecimalType).floatValue
logInfo("MorningCentralHeating",String::format("(1.3) Got offset: %s",offset))
//CheckHeatingSettings.apply( avg , max)
//,(heating_morning_maximum_offset.state as DecimalType).floatValue )
//,(heating_morning_time_on.state as Number).intValue
//(heating_morning_time_off.state as Number).intValue
//)
//logError("MorningCentralHeating",String::format("Completed lambda"))
logInfo("MorningCentralHeating","(1.4) Looking at morning Time on/time off")
//if((new LocalTime().getLocalMillis()) > (new LocalTime(timeon, 0, 0, 0).getLocalMillis()) &&
// (new LocalTime().getLocalMillis()) < (new LocalTime(timeoff, 0, 0, 0).getLocalMillis()))
if (now.getHourOfDay >= timeon && now.getHourOfDay <= timeoff)
{
withinTimer = true
logInfo("MorningCentralHeating","(1.5) Looking at temps")
logWarn("MorningCentralHeating",String::format("(1.6) Within Start and stop time, but checking current temp (%s) below maximum (%s) including offset of (%s) = (%s)",
avg,max,offset,max-offset))
if (avg >= max)
{
logWarn("MorningCentralHeating",String::format("(1.7) Temperature (%s) above maximum (%s) , time to turn off heating - SET HEATER STATE OFF",avg,max))
heaterState = false
ruleSection = "Time = off"
} //if (g_temperature_average.state >= heating_minimum_setpoint.state )
else if (avg < (max-offset))
{
logWarn("MorningCentralHeating",String::format("(1.8) Temperature (%s) is %s below maximum (%s) , time to turn on heating - SET HEATER STATE ON.",avg,
offset,max))
heaterState = true
ruleSection = "Time = On"
} //if (g_temperature_average.state >= heating_
else if (zwave_switch_central_heating.state == OFF)
{
//heaterState = true
logError("MorningCentralHeating",String::format("(1.9) Temperature (%s) should be below max (%s) , but above max - offset (%s) So stay off - SET HEATER STATE OFF",avg,max,max-offset))
heaterState = false
ruleSection = "Time = off"
} //else if (g_temperature_average.state >= heating_minimum_setpoint.state )
else
logInfo("MorningCentralHeating",String::format("(1.10) heater already on"))
} //after morning time on and off
else
{
logInfo("MorningCentralHeating",String::format("(1.11) Outsides time period to run heater. Start: %s End: %s and current %s - SET HEATER STATE OFF this can be overridden",timeon,timeoff,new LocalTime()))
heaterState = false;
ruleSection = "Time = off"
} // //after morning time on and off
logInfo("MorningCentralHeating",String::format("(2.1) Getting minimum temp threshold (%s)" , heating_overnight_minimum_override.state))
var float min = (heating_overnight_minimum_override.state as DecimalType).floatValue
logInfo("MorningCentralHeating",String::format("(2.2) Checking Average Temperature (%s) for cold override (%s) with offset (%s) = %s" , avg,min,offset,min-offset))
if (avg < min-offset && !withinTimer)
{
logWarn("MorningCentralHeating",String::format("(2.3) Current action:(%s Timer: %s), Current average (%s) is below minimum %s and offset %s = %s - SET HEATER STATE ON" ,heaterState,withinTimer,avg,min,offset,min-offset))
heaterState = true
ruleSection = "Min = on"
//Notify_Info.postUpdate(String::format("Turn on heating as current temperature (%s) below minimum override temp: %s", avg,heating_minimum_override.state))
} else if (avg > min && !withinTimer)
{
logWarn("MorningCentralHeating",String::format("(2.4) Current action:(%s Timer: %s), Current average (%s) is above minimum of %s - SET HEATER STATE OFF" ,heaterState,withinTimer,avg,min))
heaterState = false;
ruleSection = "Min = off"
}
//2018-05-28 - Removed this between section as it caused system to cycle on and off
//else if ((avg > (min-offset) && avg < min) && !withinTimer && zwave_switch_central_heating.state == ON)
//{
// logWarn("MorningCentralHeating",String::format("(2.5) Current action:(%s Timer: %s), Current average (%s) is between %s and %s - LEAVING HEATER STATE ON " ,heaterState,withinTimer,avg,min-offset,min))
// heaterState = true;
// ruleSection = "Min = on"
//}
else if (zwave_switch_central_heating.state == ON)
{
heaterState = true;
ruleSection = "Min = stay on"
logInfo("MorningCentralHeating",String::format("(2.6) Current action:(%s) - within timer %s, Current average (%s) is above minimum of %s - LEAVING HEATER ON" ,heaterState,withinTimer,avg,min-offset))
}
logInfo("MorningCentralHeating",String::format("(3) Checking if difference between weather and inside if > 10 Degrees: %s" , heating_diff_weather_internal.state))
if (heating_diff_weather_internal.state >=10)
{
logWarn("MorningCentralHeating",String::format("(3.1) Current Temperature inside (%s) is >= 10 Degrees difference to the weather (%s) = %s." ,avg,weather_temperature.state,heating_diff_weather_internal.state))
//heaterState = true
Notify_Warn.postUpdate(String::format("Maybe look at turning on the heather as the difference to outside > 10°C"))
}
logInfo("MorningCentralHeating",String::format("(4.0) Checking current heater state (%s) and performing action (%s)",zwave_switch_central_heating.state ,heaterState))
if (zwave_switch_central_heating.state == ON && heaterState == false)
{
logWarn("MorningCentralHeating",String::format("(4.1) Turning off heater (%s)",ruleSection))
Notify_Info.postUpdate(String::format("OH - Turn off (%s) heating as between %s and %s Current Temp (%s) above maximum (%s)" ,ruleSection,timeon,timeoff,avg,max))
//replace with pretend_central_heating
zwave_switch_central_heating.sendCommand(OFF)
}
else if (zwave_switch_central_heating.state == OFF && heaterState == true)
{
logWarn("MorningCentralHeating",String::format("(4.2) Turning on heater (%s)",ruleSection))
Notify_Info.postUpdate(String::format("OH - Turn on (%s) heating as between %s and %s Current Temp (%s) below maximum (%s)" ,ruleSection, timeon,timeoff,avg,max))
zwave_switch_central_heating.sendCommand(ON)
}
else
logWarn("MorningCentralHeating","(4.3) Leaving Heater alone: " + zwave_switch_central_heating.state)
} //if (g_temperature_average.state !== NULL)
else
logWarn("MorningCentralHeating","(0) Leaving Heater alone as average temperature is NULL or powerMode != schedule: " + heating_powermode.state)
logInfo("MorningCentralHeating","End of rule: heating state: " + zwave_switch_central_heating.state)
end
So g_temperature_average
is the main driver in terms on should I turn on or not.
heating_morning_maximum_setpoint
is the max temp at which if g_temperature_average
is above, don’t turn on.
offset
is the lower threshold under the average temperature that g_temperature_average must drop to, to start the system.
timeon
and timeoff
are integers, set to 5 and 8 respectively.
heating_powermode
is string item, where it can be On, Off, Schedule, Boost. Schedule is what is used to make the timeon and timeoff active. On is a manual on, off is a manual off. Not shown in this rule, is another endpoint at 2200 that sets the system back to schedule.
The theory is if the temp is between heating_morning_maximum_setpoint and heating_morning_maximum_setpoint -offset and the time is between timeon and timeoff - then turn on the heating system. Otherwise don’t.
You can see it’s quite large, and while I could break it up to the:
am I in between timeon
timeoff
is my temp lower than heating_morning_maximum_setpoint -offset
I’m not really sure if that what I should be doing. I’m just conscious this is a large block of code I have to be quite careful of.