I am look for suggestions on cleaning and optimizing the rules i am using.
var Timer aquariumfeedtimer
rule "Aquarium Feed Mode"
when
Item Aquarium_Feedmode changed from OFF to ON
sendNotification("brianllong@gmail.com", "Aquarium - Feed Mode Turning Pumps OFF")
sendCommand(Aquarium_Powerhead, OFF)
sendCommand(Aquarium_Wavemaker, OFF)
aquariumfeedtimer = createTimer(now.plusMinutes(5)) [|
sendNotification("brianllong@gmail.com", "Aquarium - Feed Mode Turning Pumps ON")
sendCommand(Aquarium_Powerhead, ON)
sendCommand(Aquarium_Wavemaker, ON)
sendCommand(Aquarium_Feedmode, OFF)
aquariumfeedtimer.cancel()
]
end
rule "Aquarium Temperature - Fan control ON"
when
Item Aquarium_Sump_Temp changed or
Item Aquarium_Sump_Temp received update
then
if (Aquarium_Sump_Temp.state > 78.1 && Aquarium_Cooling.state == OFF) {
logInfo("AquariumSumpTemp: ","Aquarium Temperature, turning on fan")
sendCommand(Aquarium_Cooling, ON)
}
else if (Aquarium_Sump_Temp.state < 77.7 && Aquarium_Cooling.state == ON) {
logInfo("AquariumSumpTemp: ","Aquarium Temperature, turning off fan")
sendCommand(Aquarium_Cooling, OFF)
}
end
rule "Aquarium Temperature - Secondary Heater control"
when
Item Aquarium_Sump_Temp changed or
Item Aquarium_Sump_Temp received update
then
if (Aquarium_Sump_Temp.state < 77.3 && Aquarium_Heater_2.state == OFF && Aquarium_Manualmode.state == OFF) {
logInfo("AquariumSumpTemp: ","Turning on Secondary Aquarium Heater")
sendCommandAquarium_Heater_2, ON)
}
else if (Aquarium_Sump_Temp.state > 77.8 && Aquarium_Heater_2.state == ON && Aquarium_Manualmode.state == OFF) {
logInfo("AquariumSumpTemp: ","Turning off Secondary Aquarium Heater")
sendCommand(Aquarium_Heater_2, OFF)
}
end
rule "Aquarium Temperature - Primary Heater control"
when
Item Aquarium_Sump_Temp changed or
Item Aquarium_Sump_Temp received update
then
if (Aquarium_Sump_Temp.state < 78 && Aquarium_Heater_1.state == OFF && Aquarium_Manualmode.state == OFF){
logInfo("AquariumSumpTemp: ","Aquarium Temperature under Low, turning on Primary Heater")
sendCommand(Aquarium_Heater_1, ON)
}
else if Aquarium_Sump_Temp.state > 78.5 && Aquarium_Manualmode.state == OFF ) {
logInfo("AquariumSumpTemp: ","Aquarium Temperature to High, turning off All Heater")
sendCommand(Aquarium_Heater_1, OFF)
sendCommand(Aquarium_Heater_2, OFF)
}
end
rule "Aquarium Temperature - Loft Fan control OFF"
when
Item Aquarium_Sump_Temp changed or
Item Aquarium_Sump_Temp received update
then
if ( Aquarium_Sump_Temp.state < 76 && FF_Loft_Fan.state == ON ) {
logInfo("AquariumSumpTemp: ","Aquarium Temperature under 76, turning off fan")
sendCommand(FF_Loft_Fan, OFF)
}
end
// Creates an item that stores the last update time of this item
rule "Records last Aquarim Sump Temp update time"
when
Item Aquarium_Sump_Temp received update
then
postUpdate(Aquarium_Sump_Temp_LastUpdate, new DateTimeType())
end
rule "Records last Turtle Aquarium Water Temp update time"
when
Item Turtle_Aquarium_Water_Temp received update
then
postUpdate(Turtle_Aquarium_Water_Temp_LastUpdate, new DateTimeType())
end
var Timer GF_Kitchen_Motion_Timer = null
var Timer GF_Living_Room_Motion_Timer = null
rule "GF_Kitchen_Lights - Automation"
when
Item GF_Kitchen_Motion changed from OFF to ON or
Item remoteSensors_Kitchen_capability_occupancy changed from OFF to ON or
Item ecobeetest changed
then
if (on_when_dark.state == ON || GF_Kitchen_Luminance.state <= 15) {
if(on_when_sleepstate.state == OFF) {
if(GF_Kitchen_Lights.state == 0) {
if (GF_Kitchen_Motion_Timer == null){
sendCommand(GF_Kitchen_Lights, 60)
sendNotification("brianllong@gmail.com", "Kitchen - Motion Detected")
logInfo("Kitchen", "Motion Detected")
GF_Kitchen_Motion_Timer = createTimer(now.plusMinutes(15)) [|
sendCommand(GF_Kitchen_Lights, OFF)
GF_Kitchen_Motion_Timer.cancel()
sendNotification("brianllong@gmail.com", "Kitchen- Motion Time out")
logInfo("Kitchen", "Motion Time out")
]
}
}else {
GF_Kitchen_Motion_Timer.reschedule(now.plusMinutes(15))
sendNotification("brianllong@gmail.com", "Kitchen- Rescheduling Timer")
logInfo("Kitchen", "Rescheduling Timer")
}
}
}
end
rule "GF_Kitchen_Lights - Automation"
when
Item GF_Kitchen_Lights received update OFF
then
GF_Kitchen_Motion_Timer.cancel()
end
rule "Bedroom Temp control"
when
Item FF_MasterBedroom_Thermostat_TargetTemperature changed or
Item FF_MasterBedroom_Thermostat_ThermostatMode changed or
Item FF_MasterBedroom_Thermostat_CurrentTemp changed or
Item FF_MasterBedroom_Thermostat_CurrentTemp received update
then
var Number setpoint = FF_MasterBedroom_Thermostat_TargetTemperature.state as DecimalType
var Number hysteresis = 1
// get the current temperature in the Bedroom
// var Number tempIn = MasterBedroomThermostatCurrentTemp.state as DecimalType
var Number tempIn = remoteSensors_Bedroom_capability_temperature.state as DecimalType
if (FF_MasterBedroom_Thermostat_ThermostatMode.state =="OFF"){
if (FF_MasterBedroom_Thermostat_Control.state == ON)
FF_MasterBedroom_Thermostat_Control.sendCommand(OFF);
}
if (tempIn < (setpoint - hysteresis) && FF_MasterBedroom_Thermostat_ThermostatMode.state =="HEAT") {
// turn on the heat
if (FF_MasterBedroom_Thermostat_Control.state == OFF)
FF_MasterBedroom_Thermostat_Control.sendCommand(ON);
} else if (tempIn >= setpoint && FF_MasterBedroom_Thermostat_ThermostatMode.state =="HEAT") {
// setpoint has been reached so switch off the heat
if (FF_MasterBedroom_Thermostat_Control.state == ON)
FF_MasterBedroom_Thermostat_Control.sendCommand(OFF);
}
if (tempIn > (setpoint + hysteresis) && FF_MasterBedroom_Thermostat_ThermostatMode.state =="COOL") {
// turn on the heatpump
if (FF_MasterBedroom_Thermostat_Control.state == OFF)
FF_MasterBedroom_Thermostat_Control.sendCommand(ON);
} else if (setpoint >= tempIn && FF_MasterBedroom_Thermostat_ThermostatMode.state =="COOL") {
// setpoint has been reached so switch off the heat
if (FF_MasterBedroom_Thermostat_Control.state == ON )
FF_MasterBedroom_Thermostat_Control.sendCommand(OFF);
}
end
var Timer Presence_timer = null
rule "Presence_AutoAway - Control"
when
Item Presence_Master received update
then
if (Presence_Auto_Away.state == ON && Presence_Master.state == OFF) {
sendNotification("brianllong@gmail.com", "Presences - Starting Away Timer")
Presence_timer = createTimer(now.plusMinutes(5)) [|
sendNotification("brianllong@gmail.com", "Presences - Changing to Away")
ecobeeResumeProgram("317488702664", true)
//sendCommand(SamsungPower , ON)
sendCommand (glights, OFF)
sendCommand (gtvpower, OFF)
Presence_timer.cancel()
//Presence_timer = null
]
}
else
if (Presence_Auto_Away.state == ON && Presence_Master.state == ON) {
if (Presence_timer != null) {
Presence_timer.cancel()
sendNotification("brianllong@gmail.com", "Presences - Cancelled Away Timer")
}
}
end
rule "Presence_Master - Control"
when
Item Presence_Brian_Iphone_Macaddr received update or
Item Presence_Jen_Iphone_Macaddr received update or
Item Presence_Ecobee_Master received update
then
if (Presence_Brian_Iphone_Macaddr.state == OFF && Presence_Jen_Iphone_Macaddr.state == OFF && Presence_Ecobee_Master.state == OFF) {
sendCommand(Presence_Master , OFF)}
else
if (Presence_Master.state == OFF) {sendCommand(Presence_Master , ON)}
end
rule elevation
when
Item astro_sun_local_position_elevation changed
then
if(astro_sun_local_position_elevation.state > 0){
if(on_when_dark.state!=OFF){
// logInfo("houseControl", "Sun is crossing the horizon, switching to daylight mode")
on_when_dark.sendCommand(OFF)
}
} else {
if(on_when_dark.state!=ON) {
// logInfo("houseControl", "Sun is crossing the horizon, switching to night mode")
on_when_dark.sendCommand(ON)
}
}
end
rule "sleepstate"
when
Item on_when_sleepstate received update ON
then
sendCommand (glights, OFF)
sendCommand (gtvpower, OFF)
end
rule "Reset Sleepstate"
when
Time cron "0 0 4 * * ?"
then
sendCommand(on_when_sleepstate, OFF )
end
rule "Resume Program 9PM for sleep "
when
Time cron "0 5 21 * * ?"
then
ecobeeResumeProgram("317433702664", true)
logInfo("Cron Ecobee","EcoBee Resuming Program")
end