GithubHelp home page GithubHelp logo

dan-nadler / thermopi Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 1.23 MB

a thermostat and data collection device using a Raspberry Pi

Python 85.70% Shell 0.28% JavaScript 0.74% HTML 13.28%
raspberry-pi thermostat home-automation python

thermopi's Introduction

thermoPi

A multi-zone thermostat built using the Raspberry Pi

Installation

python setup.py install

Setup

Local

Create a local_settings.py file in thermo/ and add:

from collections import namedtuple
from RPi.GPIO import BCM

def convert(dictionary):
    return namedtuple('GenericDict', dictionary.keys())(**dictionary)

# The database where thermoPi data is stored
DATABASE = {
    'TYPE': 'mysql+___',
    'HOST': 'xxx.xxx.xxx.xxx',
    'PORT': '3306',
    'USERNAME': 'user',
    'PASSWORD': 'password',
    'NAME': 'dbname',
}

DATABASE = convert(DATABASE)

# The path for an SQLite database where a local copy of some information is stored in case the database cannot be reached
# This database is created automatically by thermo.common.models
LOCAL_DATABASE_PATH = '/home/pi/thermo.db'

USER_NUMBER = 1 # Your user ID number from the `user` table
UNIT_NUMBER = 2 # A unique ID number assigned to each Raspberry Pi in the `unit` table

GPIO_MODE = BCM # The mode for designating GPIO pins
GPIO_PINS = {
    'HEAT': 17 # The GPIO pin that the heat control relay is connected to
}

# A local sensor that the heating control algorithm will fall back to in the event that the database cannot be reached
FALLBACK = {
    'LOCATION': 'Sensor Name Here', # the sensor's name
    'SERIAL NUMBER': '28-0416930a31ff', # the sensor's serial number
    'ZONE': 1 # the heating zone the sensor is assigned to
}

# This dictionary is passed to logging.basicConfig via logging.basicConfig(**LOGGING)
LOGGING = {
    'level': logging.DEBUG,
    'filename': '/home/pi/thermoPiLog.log',
    'format': '%(asctime)s %(levelname)s: %(filename)s %(lineno)d: %(message)s'
}

Database

Use python -m thermo.common.models to create the tables in your database.

Update the sensor, unit, user, zone, and action tables with your configuration.

Currently, the only available action is 'HEAT', which controls a heating system (furnace, in my case) via a 2-wire thermostat line attached to a relay.

Usage

Use python -m thermo.control.master on each raspberry pi to run thermo.

This will detect the attached sensors and available actions via the database and local_settings.py file, and perform them in a loop.

Web Interface

If you install uwsgi via apt-get and pip, you can use the following command to host the control UI from the Raspberry Pi:

sudo /usr/local/bin/uwsgi --socket :80 --protocol=http -w wsgi:app

Alternatively, you can host with Flask, or another webserver of your choosing.

Creating a Service

Copy thermo.service to /lib/systemd/system/, then run sudo systemctl enable thermo and sudo systemctl start thermo

This service is configured to automatically restart if the process crashes.

thermopi's People

Contributors

dan-nadler avatar

Stargazers

 avatar Vincent Bauchart avatar Aaron Smith avatar M avatar

Watchers

James Cloos avatar  avatar

thermopi's Issues

Add logging

Create logs to diagnose crashes and other exceptions.

Detect and adjust for unreliable sensor readings

Sensors will sometimes provide bad data. I have noticed 32 degrees (0 C) as a common erroneous data point. Additionally I have seen ~182 degrees F, and some in the 70s.

A solution could be to compare new readings to historical averages to detect outliers in the case where only one sensor is available. A 3 standard deviation outlier, for example, may be ignored in most cases. Edge cases may be a concern.

In cases where multiple sensors are available, cross-sectional outlier detection should be more robust.

Heat toggle does not turn off heat

If the heat is on, the heat toggle API function does not turn off the heat.

The toggle removes the thermostat main function from the control loop, so the heat will remain on indefinitely.

A solution to this could include a secondary 'emergency shutoff' function that both prevents the thermostat main loop from running, and manually sets the GPIO to low.

Add temperature target optimization that learns and accounts for delay in activation

The thermostat should look at previous actions and calculate the average delay from signal to HVAC on/off.

Suggestion: Calculate the average delay time, and then calculate expected temperature after delay based on a simple linear regression. Use the expected temperature in place of the current temperature when determining whether to trigger an action.

Keep in mind that the buffer adjustment must be large enough to prevent immediate reversal of an action. Perhaps the buffer could be adjusted to prevent this from happening. The buffer could solve for the tightest temperature oscillation, subject to a minimum run time, given the expected delay of each action.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.