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.

4 thoughts on “Triggered

  1. I actually got the same thermostat! Funny we picked the same one. Even though we aren’t using the same software, I had the same problem and I had to write a script as well, rather than use the built in event system for temperature control. I didn’t go to quite the lengths you did though. I just focused on whether someone is home and keeping it within a certain temperature range (switching to heat/ac appropriately). I also added a bypass button to stop running my script if I need manual control. We don’t have as many days here where it makes sense to open the windows as you do though :).

    For notifications, I just use email to text. I setup an email account to use for my smart stuff to send from and then just send to the email->text gateway for my cell provider (which all of them have). It is free and works as well as push notifications without any app.

    For presence detection we use our iPhones and HomeKit (which talks to my home automation). I never looked to hard for another gps based solution because this setup also gave me voice control. I really wanted to avoid gps somehow to save phone battery, but I haven’t really noticed an impact. How do you get your location data into Home Assistant?


    1. The GPSLogger app just sends an http request to my Home Assistant server with all of the relevant parameters in the url.


      1. Ok cool, so pretty much how my script interacts with Domoticz (json api).

        Also, are you using the Aeotec Z stick and does HA use openzwave? If so, you might be on the lookout for an issue I’ve seen with that thermostat where occasionally the config file for openzwave would just drop a line related to setting the heat setpoint. When that happened I would have to go in and re add the line manually. I don’t know for sure if it’s still an issue since it hasn’t been cold enough yet this year.

        Sounds like your system is coming along nicely!


  2. Yes, I am using an Aeotec Z stick. I don’t know exactly how HA talks to the Z stick, but I don’t think I’ve had any problems.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s