# Thermostat automation, where to even start?

I’m just getting started with the automation side of hass, and I’m not even sure that it can do what I’m wanting to do. My Python skill level very closely approximates zero, so bear with me here.

What I’d like to do is have my thermostat’s set points adjust automatically depending on the outside temperature, sun state, and whether someone is actually home, and shut the HVAC off entirely if someone has a door open. On a really hot day, don’t run the A/C so hard; if nobody is home, the thermostat really shouldn’t do more than keep the chocolate from melting and the pipes from freezing. Cooler at night. “Simple” stuff like that.

I’ve scratched out some meta-code that looks like it would basically do what I want. Can anyone walk me through the basics of how to accomplish this? From the limited reading I’ve done here, it seems that the scripting language can’t even do basic arithmetic, which has me rather puzzled as to how I’d even begin with this thing.

—metacode—
iterate through this every 60 seconds or so {
if a door or window has been open for more than 60 seconds, turn thermostat cooling and thermostat heating to off
if all windows are closed turn thermostat heating and thermostat cooling to auto
}

trigger this whenever someone arrives at home, whenever someone leaves home, and once per 10 minutes
set thermostat routine {
if someone is home {
if outside_temp > 90 {
day_max_temp = ((outside_temp-90)/2)+75
night_max_temp = ((outside_temp-90)/2)+72
day_min_temp = 70
night_min_temp = 65
}
if 90 >= outside_temp > 35 {
day_max_temp = 75
night_max_temp = 72
day_min_temp = 70
night_min_temp = 65
}
if outside_temp <= 35 {
day_max_temp = 75
night_max_temp = 72
day_min_temp = 70-((35-outside_temp)/2)
night_min_temp = 65-((35-outside_temp)/2)
}
}
else (nobody is home) {
day_max_temp = 87
night_max_temp = 85
day_min_temp = 45
night_min_temp = 40
}
if sun=up {
thermostat.cooling.setpoint = day_max_temp
thermostat.heating.setpoint = day_min_temp
}
if sun=down {
thermostat.cooling.setpoint = night_max_temp
thermostat.heating.setpoint = night_min_temp
}
}
—/metacode—

With my profuse apologies for our utterly stupid use of degrees Fahrenheit.

Check out appdaemon. It will allow you use regular python code to control your AC. Here is my AC automation appdaemon “app”: https://github.com/aneisch/home-assistant/blob/master/extras/appdaemon/apps/ac_automation.py

That is beautiful, thank you!

This is how I automate my thermostat https://github.com/Danielhiversen/home-assistant_config/blob/master/automation/heating.yaml

1 Like

@Danielhiversen Thanks for sharing your code about heating system as I have myself lot of difficulties to setup mine as I want
Just a little question if you don’t mind ? How does it work in your automation when you have multiple triggers one after another ? Just one of them true triggers the whole think ? same questions for conditions !

Thanks