Giter Club home page Giter Club logo

haos_mpc's Introduction

NOTE: THIS IS A WORK IN PROGRESS!

Introduction

The overall mission of this project is to implement advanced control techniques to make the intelligent home a reality that is accessible through Homeassistant. That is, a home that is able to gather data, turn it into information, establish a goal based on that information, and move towards it.

Control Systems

HAOS offers basic automations regarding turning switches on and off, or if the device supports it, tuning a specific variable (such as light intensity). These automations, although user friendly and fairly effective, have only the capabilities to implement condition-based control systems (if temperature <20 turn on heater or if temperature >22 turn off heater and so on). This is prone to unintended consequences if set up incorrectly. Similarly, to account for many conditions, control logic implemented via if statements is tedious to set up.

To develop a true 'intelligent' home, the home needs to be able to automatically control actuators based on goals and constraints set by the user. The vision is to have the user input some relatively basic parameters (for example, keep temperature at 20°C) and some weights (for example, minimise energy consumption (30% priority) and keep me comfortable (70% priority)). The controller then deals with when to turn the heating on, and may use data such as energy price, current room temperature, external temperature etc.

The initial stages of this project will consider home heating systems since they are both expensive and carbon intensive. Similarly, most homes with traditional heating systems consider a house's radiators as a single output. However, the homeowner should be able to switch between choosing whether to heat the house or the people in the house, and potentially let the controller choose when to prioritise which.

Model-predictive Control

MPC is a technique for optimally controlling MIMO systems.

The inspiration came from this post, with the intention to create a real-life version of the controller. Similarly this research has demonstrated the potential for energy and cost savings.

Example MPC Diagram

Example MPC Diagram

Image from here

System Identification / Physics Informed ML

To realise this, there are three key components of the system that need to function properly - the optimiser, the model and the state estimator (see figure). All three rely on an accurate model of the system in question. To get the system model through data, system identification can be used, which requires adequate signal processing methods to minimise modelling errors.

The PySINDy Library

PySINDy emphasises the use of sparse regression, and seems the most appropriate System ID method to use so far. PySINDY also returns models in a state-space format, making it more appropriate for eventual integration within the rest of the control logic.

The EKF-SINDy Paper

The EKF-SINDy paper and the corresponding code provide an approach for creating an Extended Kalman Filter.

Websockets

Live Data

I saw the need to develop my own scripts that would enable me to access live HAOS sensor data in near-real-time. This prevents consistently querying the database to gather live sensor data, which in turn could reduce the sampling rate to below Nyquist frequency depending on the sensor. The websocket API available shows the .json format for communicating with HAOS, but there didn't seem to be any wrapper available in Python.

Control Signals

Control signals can be sent to HAOS via the websocket by calling services.

Finishing Line

This project will be finished when it:

  • Can deployed as a container
  • Can pull data from TimescaleDB that is set up on HAOS
  • Can take user inputs for the optimisation
  • Can perform live system identificaiotn
  • Can perform adaptive control based on the system identificaiton
  • Can adapt to sensor noise

Managing Credentials

Done via python-dotenv. Example file:

HASS_IO_AUTH_TOKEN = YOUR AUTH KEY
HASS_IO_HOSTNAME = ws://homeassistant.local:8123/api/websocket
YAML_NAME = subscriptions.yaml

TODO:

  • Sensor class

    • Methods for cleaning data
    • Methods to output numpy and pandas
    • Create virtual sensors for testing
      • Ensure the dataframes for df and timeseries are exactly the same
      • Unit test to ensure that the timestep of a virtual sensor is the same as what is returned by the get_timestep() method
    • Plotting capabilities
  • Actuator Class

    • Send commands to HAOS via the websocket/api.
    • Implement constraint attributes
  • DatabaseManager class

    • pull data from TimescaleDB
    • Get list of database components from TimescaleDB
  • Signal Processing

    • Implement simple filtering techinques
    • Implement more filtering techniques
    • Functions for optimising filters
    • Implement correlation functions
    • Manage multi-rate timeseries
  • System Identification

    • Use methods from dsp to align different datasets.
    • Validate these using stationarity method
  • Real-time data

    • Use the websocket functionality of HAOS to allow the system to function live
    • Making the sensor class be able to collect real-time data via the websocket

haos_mpc's People

Contributors

sebzuddas avatar daliannys avatar

Watchers

 avatar

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.