A Nest-Like learning thermostat in 20 minutes

by Stéphane Maruéjouls | Nov 09, 2015 | Tutorial | AI  Behavior Trees  IoT  Smart Home  Visual Programming 

A Nest-Like learning thermostat in 20 minutes

Last week at the Web Summit, we presented our latest demo: a thermostat that learns from its user habits. In this post we’ll explain how it works!

Ever wonder how to get an app that learns from your inputs and your habits? Following the Apps that learns with agent-based modeling blog post, this one will show you how to use craft ai for bringing learning skills to your app.

Introduction

A good demo is better than thousand words, so below you can see the application in action

You can control the thermostat by dragging on it. You can fast forward time if you don’t want to wait 1 week to see the learning in action. You can turn on/off the heaters and change the temperature to see how the application reacts in case of a dysfunctioning heater.

Disclaimer

We use a very basic function to emulate the heating/cooling process, without any external inputs. This is just for simulation purpose.

Behaviors

The main behavior tree

Quite simple, and it can learn your habits and check that your heaters are working!

Learning

Usually, when you install a new thermostat at home, you will setup a schedule on it, usually for every day and every hour, you can set the temperature you want. What if the thermostat can learn from you and you don’t have to setup anything? In the demo above, we have a default planning for working days, and another for non working days. Based on your actions on the thermostat, the correct planning will adapt itself. Every time you change the thermostat, a learning behavior tree will be executed which starts a learning action on the specific planning.

The learning behavior tree

The behavior is pretty simple, it computes the correct planning to learn on (workday vs non workday). Then the action will manage an array of actions {time,temperature} tuples. If it finds an existing event in a 30 minutes time frame, the event is replaced with the new time and new temperature, or if no event is found, a new one is created. Moreover if two consecutive events have the same temperature, the second one is removed.

So far we have hard coded that Saturday and Sunday are non working days and the other days are working days. You can fork the github project and try to connect to a WebService to find holidays for your country, and also use more Connected Objects to learn what is a working day for you (not everybody works from Monday to Friday).

Replaying

As soon as there are some events in the planning, the behavior tree will use them to change the temperature of your home. However we have to compute at what time the thermostat turn on the heating to a specific temperature so it will be reached in correct time.

The compute action

The compute action, will do inplace replacement of the expression with parameters and evaluate it directly.

To compute the time when the thermostat should be changed, we compute how by how many degrees we need to adjust the temperature and how much time it takes to make this change. We have set the demo with a value of 15 minutes for lowering 1 degree, and 20 minutes for raising 1 degree. Again those values can be learned from within the BT, you may try to play with the source code and BTs to do it yourself.

Computing correct time and temperature

Now that we have computed the time to change the thermostat, it is just a matter of doing a comparison with the current time before setting it.

Setting the temperature

The interesting thing about that approach is that it adapts to the actual temperature of the room. So the time of triggering the thermostat will change on a daily basis if you open the window or not for example.

Checking that everything works

Now that we have correctly set our thermostat up based on the planning, we can add some more features. What about making sure our heater works correctly? Again with craft ai, it is quite simple. As you may have noticed in the previous behavior tree, you can see a call to an embedded behavior tree called ComputeControl.bt

Control computation

In order to control if the heater is correctly working, we compute at what time we think the temperature should have raised or lowered by 1 degree (or 0 degree in 10 minutes in case we are already at the right temperature). Then again, it is just a matter of comparison with the current time and the control time to see if we actually reached that temperature. Based on the outcome, we can tell the user to check either if the heater is actually powered on or if it is overheating.

Controlling BT

Homework

Usually, when you lower the temperature with the thermostat, your intention is more ‘I want to lower the temperature to X° now’ than ‘I want the temperature to be X° now’. Thanks to craft ai, this change is quite simple. In the computeTime.bt, after we identify we need to decrease the temperature (ie deltaTemperature < 0), we just set a deltaTime of 0.

Modified BT

Playing

Feel free to modified the BTs and sources to add more great features:

  • taking the weather into account
  • use google calendar to choose the best planning
  • add more connected objects, like windows sensors
  • use real heat convection formulae
  • learn the time to heat/cool the room
  • etc…

Your fork might be on the featured projects page!

Learning and be whitebox

The current trend in AI field is deep learning and big data, these are very interesting tools, but not every app need such big algorithms to learn on knowns criteria. With craft ai, we were able to create an app that learns and still is explainable and understandable.

Share