Ejemplo n.º 1
0
def liveUpdate():
    ''' Generic form used to update main form via ajax request '''
    status = thermCursor.execute('SELECT * FROM status').fetchone()
    schedule = getModeHTML(status)
    html = '<div id="updateContainer"> \
                <div id="fanModeContainer">{fanMode}</div> \
                <div id="systemModeContainer">{systemMode}</div> \
                <div id="holdTimeContainer">{holdTime}</div> \
                <div id="indoorTempContainer">{temp}</div> \
                <div id="scheduleContainer">{schedule}</div> \
                <div id="weatherContainer">{currentWeather}</div>\
                <div id="weatherAlerts">{alerts}</div> \
                <div id="timeContainer">{time}</div> \
            </div>'.format(fanMode=status['fan_mode'],
                           systemMode=status['mode'],
                           holdTime=calendar.getRemainingHoldTime(),
                           temp=str(
                               round(
                                   tempSensor.getCurrent(
                                       CONFIG['units'],
                                       CONFIG['temperature_offset']), 1)),
                           schedule=schedule,
                           currentWeather=getCurrentWeather(),
                           alerts=getCurrentWeatherAlerts(),
                           time=datetime.now().strftime(
                               '<b>%I:%M</b><small>%p %A, %B %d</small>'))
    return html
Ejemplo n.º 2
0
def info_form():
    status = thermCursor.execute('SELECT * FROM status').fetchone()
    schedule = (getModeHTML(status).replace(
        'targetTemps"', 'targetTemps" style="display:inline-block;"').replace(
            'target-heat"',
            'target-heat" style="display:inline-block;width: 135px;"').replace(
                'target-cool"',
                'target-cool" style="display:inline-block;width: 135px;"'))
    options = [{
        'system Time': datetime.now().strftime('%I:%M %p %A, %B %d')
    }, {
        'temp':
        str(
            round(
                tempSensor.getCurrent(CONFIG['units'],
                                      CONFIG['temperature_offset']), 1))
    }, {
        'Mode': status['mode']
    }, {
        'Fan Mode': status['fan_mode']
    }, {
        'GPIO Status': getWhatsOn()
    }, {
        'Schedule': schedule
    }, {
        'Daemon': getDaemonStatus()
    }, {
        'Hold Time': calendar.getRemainingHoldTime()
    }]

    return render_template("info.html", options=options)
Ejemplo n.º 3
0
def main_form():
    CONFIG = thermCursor.execute('SELECT * FROM settings').fetchone()
    settingsRedirect = not (CONFIG['heater_pin'] or CONFIG['ac_pin']
                            or CONFIG['fan_pin'])
    # redirect if none of the pins are set
    if settingsRedirect:
        flash("You must setup your system before you can continue", "warning")
        flash("HINT: Hover over an item to see a description", "info")
        return redirect(url_for('settings_form'))
        #return render_template("index.html", openSettings = '$( "#settings-btn" ).click();')
    else:
        status = thermCursor.execute('SELECT * FROM status').fetchone()
        schedule = getModeHTML(status)
        temp = str(
            round(
                tempSensor.getCurrent(CONFIG['units'],
                                      CONFIG['temperature_offset']), 1))
        if temp == "-666.0":
            temp = "Err"
        return render_template("index.html",
                               unit=CONFIG['units'],
                               fanStatus=status['fan_mode'],
                               systemMode=status['mode'],
                               targetTemps=Markup(schedule[1]),
                               weatherVisible='visible'
                               if CONFIG['weather_enabled'] else 'hidden',
                               holdTime=calendar.getRemainingHoldTime(),
                               temp=temp,
                               title=Markup(temp + "&deg;"),
                               scheduleTime=Markup(schedule[0]),
                               currentWeather=Markup(getCurrentWeather()),
                               time=Markup(datetime.now().strftime(
                                   '<b>%I:%M</b><small>%p %A, %B %d</small>')),
                               alerts=getCurrentWeatherAlerts())
Ejemplo n.º 4
0
    def run(self):

        errorCount = 0
        self.inPassiveMode = False
        self.thermostatMode = "OFF"
        self.activeTarget = 0
        self.inactiveTarget = 0
        while True:

            self.indoorTemp = tempSensor.getCurrent(
                self.config['units'], self.config['temperature_offset'])
            self.schedule = self.calendar.getStatus()
            self.thermostatMode = self.getMode()
            hvacState = self.getHVACState()

            if not self.inPassiveMode:
                #set cool or heat
                if self.thermostatMode == "COOL": self.cool()
                if self.thermostatMode == "HEAT": self.heat()

                #check if temp target reached + powerdown
                if (self.thermostatMode == "OFF"
                        or self.thermostatMode == "COOL"
                        and self.indoorTemp <= self.activeTarget
                        or self.thermostatMode == "HEAT"
                        and self.indoorTemp >= self.activeTarget):
                    self.inPassiveMode = True
                    self.powerDown()
            else:
                #check if time to turn back on

                if (self.thermostatMode == "COOL"
                        and self.indoorTemp > self.inactiveTarget
                        or self.thermostatMode == "HEAT"
                        and self.indoorTemp < self.inactiveTarget):
                    self.inPassiveMode = False

            self.logData()
            self.checkSystemErrors()
            self.updateWeather()
            time.sleep(5)
Ejemplo n.º 5
0
    def logData(self):
        try:
            now = datetime.now()
            heatStatus = GPIO.input(self.config['heater_pin'])
            coolStatus = GPIO.input(self.config['ac_pin'])
            fanStatus = GPIO.input(self.config['fan_pin'])
            if self.config['debug'] == True:
                msg = ("hvacState = {0} \n".format(self.getHVACState()) +
                       "indoorTemp = {0} \n".format(self.indoorTemp) +
                       "targetTemp = {0} \n".format(self.activeTarget) +
                       "heatStatus = {0} \n".format(heatStatus) +
                       "coolStatus = {0} \n".format(coolStatus) +
                       "fanStatus = {0}".format(fanStatus))
                self.recordDebugLog(msg)

            self.logElapsed = now - self.lastLog
            #logging actual temp and indoor temp to sqlite database.
            #you can do fun things with this data, like make charts!
            if self.logElapsed > timedelta(minutes=6):
                # keep logging data for a month
                self.logsCursor.execute(
                    "DELETE FROM logging where datetime NOT IN (SELECT datetime from logging ORDER BY datetime DESC LIMIT 7500)"
                )
                self.logsCursor.execute(
                    'INSERT INTO logging VALUES(?, ?, ?, ?, ?)',
                    (now, self.indoorTemp, self.activeTarget,
                     self.getHVACState(), "ON" if fanStatus else "OFF"))
                self.logsConn.commit()
                self.lastLog = datetime.now()
                self.indoorTemp = tempSensor.getCurrent(
                    self.config['units'], self.config['temperature_offset'])
                if self.indoorTemp == -666:  #exactly 0 means error
                    self.sendErrorMail(
                        "There is a problem reading the temperature sensor!",
                        frequency=timedelta(hours=6))
        except:
            print("Error while saving log data: ", sys.exc_info()[0])