Please Critique HVAC Control Script

Posted on
Fri Dec 27, 2013 9:26 pm
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Please Critique HVAC Control Script

Starting to work on some more robust climate control, but I'm not confident enough to just turn this script loose on my HVAC. I would appreciate any advice on how this thing will work, or if I'm somehow setting myself up for a massive utility bill! :)

Thanks in advance.

Code: Select all
broken code deleted.

UPDATE:
Okay, 'while' statements are not what I wanted. This script (which contains nested 'if' statements instead of nested 'while' statements) seems to operate as intended:

Code: Select all
from datetime import datetime, time

# ========================================================================
# Set up some variables
# ========================================================================
tstatUp = indigo.devices[1002786935] # "Thermostat - Upstairs"
tstatDown = indigo.devices[1696201155] # "Thermostat - Downstairs"
vacation = indigo.variables[531082641].value # "vacation"
day_of_week = datetime.today().weekday()
time_of_day = datetime.now().time()

# ========================================================================
# Determine weekday or weekend
# ========================================================================
if 0 <= day_of_week <= 4:
   weekday = "Weekday"
else:
   weekday = "Weekend"

# ========================================================================
# Determine AM or PM
# ========================================================================
if time(00,00) <= time_of_day <= time(11,59):       
   am_pm = "AM"
else:
   am_pm = "PM"

indigo.server.log("vacation is set to: " + vacation)
indigo.server.log("weekday is set to: " + weekday)
indigo.server.log("am_pm is set to: " + am_pm)
indigo.server.log("Initial thermostat settings:")
indigo.server.log("   Upstairs heat: " + str(tstatUp.states["setpointHeat"]))
indigo.server.log("   Upstairs cool: " + str(tstatUp.states["setpointCool"]))
indigo.server.log("   Upstairs HVAC mode is: " + str(tstatUp.states["hvacOperationMode"]))
indigo.server.log("   Upstairs fan mode is: " + str(tstatUp.states["hvacFanMode"]))
indigo.server.log("   Downstairs heat: " + str(tstatUp.states["setpointHeat"]))
indigo.server.log("   Downstairs cool: " + str(tstatUp.states["setpointCool"]))
indigo.server.log("   Upstairs HVAC mode is: " + str(tstatUp.states["hvacOperationMode"]))
indigo.server.log("   Downstairs HVAC mode is: " + str(tstatDown.states["hvacOperationMode"]))
indigo.server.log("   Downstairs fan mode is: " + str(tstatDown.states["hvacFanMode"]))

# ========================================================================
# While we're home:
# ========================================================================
if vacation == "false":
   if weekday == "Weekday":
      if am_pm == "AM":
         indigo.server.log("Firing: weekday morning setpoints")
         if tstatUp.states["setpointHeat"] < 68:
            indigo.thermostat.setHeatSetpoint(tstatUp, value=68)
         if tstatDown.states["setpointHeat"] < 65 and tstatDown.states["hvacOperationMode"] == 1:
            indigo.thermostat.setHeatSetpoint(tstatDown, value=65)
         if tstatUp.states["setpointCool"] > 72:
            indigo.thermostat.setCoolSetpoint(tstatUp, value=72)
         if tstatDown.states["setpointCool"] > 74 and tstatDown.states["hvacOperationMode"] == 2:
            indigo.thermostat.setCoolSetpoint(tstatDown, value=74)
      if am_pm == "PM":
         indigo.server.log("Firing: weekday evening setpoints")
         if tstatDown.states["hvacOperationMode"] == 1:
            indigo.thermostat.setHeatSetpoint(tstatDown, value=64)
         if tstatDown.states["hvacOperationMode"] == 2:
            indigo.thermostat.setCoolSetpoint(tstatDown, value=75)
         # At night time, leave upstairs setpoints alone.

   if weekday == "Weekend":
      if am_pm == "AM":
         indigo.server.log("Firing: weekend morning setpoints")
         if tstatUp.states["setpointHeat"] < 68:
            indigo.thermostat.setHeatSetpoint(tstatUp, value=68)
         if tstatDown.states["setpointHeat"] < 65 and tstatDown.states["hvacOperationMode"] == 1:
            indigo.thermostat.setHeatSetpoint(tstatDown, value=65)
         if tstatUp.states["setpointCool"] > 72:
            indigo.thermostat.setCoolSetpoint(tstatUp, value=72)
         if tstatDown.states["setpointCool"] > 74 and tstatDown.states["hvacOperationMode"] == 2:
            indigo.thermostat.setCoolSetpoint(tstatDown, value=74)
      if am_pm == "PM":
         indigo.server.log("Firing: weekend evening setpoints")
         if tstatDown.states["hvacOperationMode"] == 1:
            indigo.thermostat.setHeatSetpoint(tstatDown, value=64)
         if tstatDown.states["hvacOperationMode"] == 2:
            indigo.thermostat.setCoolSetpoint(tstatDown, value=75)
         # At night time, leave upstairs setpoints alone.

# ========================================================================
# While we're away:
# ========================================================================
if vacation == "true":
   indigo.server.log("Firing: vacation setpoints")
   indigo.thermostat.setHeatSetpoint(tstatUp, value=60)
   indigo.thermostat.setCoolSetpoint(tstatUp, value=79)
   if tstatDown.states["hvacOperationMode"] == 1:
      indigo.thermostat.setHeatSetpoint(tstatDown, value=60)
   if tstatDown.states["hvacOperationMode"] == 2:
      indigo.thermostat.setCoolSetpoint(tstatDown, value=79)

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 11 guests