My Home Assistant now controls my HVAC the way I want it to. I’m now super happy about how it works, but man is the code ugly.
To start with, I bought a very basic, Z-Wave thermostat. It has no smarts of its own, but can be controlled via Z-Wave. This means my home automation system can turn on or off the AC or Heat, and set the temperature.
My first step was to just set up a schedule for the thermostat set points, and have it turn on the Heat or AC based on the outside temperature. But this brings me to how Home Assistant gets configured.
Every action that Home Assistant takes, starts with a trigger. Which is great for saying I want to change something on a schedule, or for saying when X happens do Y. But if it’s cold outside, I don’t want to set the AC when the scheduled time comes around. And if it gets hot, I want to go ahead and turn on the AC, not wait until the scheduled time.
As a reasonable workaround, Home Assistant supports an “input number”, which can be set by an action. So I can use those to keep track of the current AC and Heater temperatures. Then, I can set those values on a schedule, and if the thermostat is in the proper mode, set its temperature at the same time.
Additionally, triggers can be based on expressions involving any of the existing entities in the system using a templating system. So I can constantly check if it is hot or cold outside, compared to the AC and Heater set points, then turn on the AC or Heater as appropriate.
So my first setup had a list of triggers to set the AC and heater set-points at scheduled times, and a list of triggers to turn on the Heater or AC based on the outside temperature. This worked okay, but I wanted more.
Next, I wanted to be able to send notifications about certain things to my phone. I went with PushBullet, and I’ve been pretty happy with that so far. Now I could add sending a notification to “Open the windows, it’s nice outside” or “I’m turning on the AC, make sure the windows are closed”.
I figured it would also be nice if Home Assistant could tell if we were home. I started out using OwnTracks, but it didn’t really perform very well. It would stop sending updates when I would get near home, so Home Assistant wouldn’t think I actually made it home, and it wasn’t playing nicely on my wife’s phone. Now I’m using GPSLogger, and I’ve been much happier with it.
Now, I had lots of variables to consider when deciding what the thermostat should be set at. I drew up a table based on:
- Temperature outside
- Is anybody home
- Is it daytime or nighttime
- Temperature inside
It got to be a complicated table because even if it isn’t hot outside, it can still get hot inside, and if nobody is home, or it’s nighttime nobody can open the windows. I ended up with 15 different triggers that fire every 10 minutes, only one of which will actually perform an action at a given time. This was just easier than trying to think about all the different transitions between states. Not to mention the fact the outside temperature fluctuates enough that it could trigger the AC to turn off and on again in a matter of seconds.
This was all working pretty good except for one thing. It would be nice if Home Assistant could tell if the windows were open. So I got a Dome Window/Door sensor and synced it up. Then I modified my automations just a bit. If the window get’s opened, the thermostat gets turned of immediately. If the window is open, it won’t turn on the thermostat. If it’s nice outside, it just sends me a notification, instead of actually turning off the thermostat. And if it gets hot or cold outside, it sends me a notification to close the windows, or turns on the thermostat if they are already closed.
This worked great, but I wanted two more minor tweaks. When somebody arrives home, if it’s hot or cold inside, it should turn on the thermostat immediately to get a jump start on getting the house to the right temperature. Additionally, if somebody pushes the buttons on the thermostat, it should modify the values stored in Home Assistant so that it doesn’t get changed back a few minutes later.
The hardest part of my home automation is now complete. This was a challenging and fun project, and will surely reap rewards on my utility bills. I’ll also keep adding pieces and tweaking. You can find my configuration files here if you actually want to see the code. But TRIGGER WARNING, it’s not pretty.