My thermostat automatically adjusts when I’m away

photo of fireplace

So how can you automate your thermostat? You’ll need a wifi connected thermostat at the very least. I have an older model Honeywell that connects to mytotalconnectcomfort.com. You’ll also need to think about what rules you want to define when creating your own auto HVAC rules.

What Do I Mean by Auto HVAC Rules?

Simply put, what do you want to happen when certain criteria is met? If it is colder than X in the house, do you want the thermostat to kick on at a certain temperature until it reaches that temperature? (This is a pretty poor example, because this is already what a thermostat is designed to do. To make something a little more effective you are going to want to add a couple variables.)

Start by Defining Your Plan

Create a plan on paper. It might not be your final plan. You may end up tweaking it a few times after you roll with it. But at least have some clear goals in mind ahead of time so that you can write the basic structure of your program. I live in an area that has cold winters and hot summers. It can also fluctuate between cold and hot in a single day. I hate having to control things if I can help it. Why do I need to switch the system from A/C to Heat or vice versa? I just want it to stay a certain temperature in my house. Why does my thermostat have to be so complicated to make me choose which system I want to use? I know part of the problem has to do with outdoor temperatures. You don’t want your A/C kicking on in the dead of winter for example. But we have ways of getting the outdoor temperature. Shouldn’t that be enough to drive which system to use? I think so.

My Plan

I decided to setup 2 different profiles so to speak. Profile “Home” and Profile “Away”.

Profile “Home” would be activated when someone is home. Basically I know when household members are home by doing some presence detection. I’ll outline specifically how I tackle the presence detection at a later date. But the short version is that I do a network scan looking for mac addresses of cell phones on my home network. Android Oreo has become great about always making sure I’m on my home wifi that I really don’t ever have to worry about a thing.

Home Profile

When the temperature outside is 60° F or higher,
and the temperature inside is 68° F or higher
and the cool set point is above 68° F
I make sure the system is set to AC and the cool set point is set to 68° F. This means in warmer weather my house should never be above 68 if someone is home.

On the other end of the spectrum…
When the temperature outside is 46° F or lower,
and the temperature inside is 65° F or lower
and the heat set point is lower than 67° F
I make sure the system is set to Heat and the heat set point is set to 67° F. This means that in cold weather my house will never be below 67 when someone is home.

So what about the away profile? This is where I try to save a little money. This probably doesn’t amount to a lot as I only change it a few degrees. But I like to keep the temperature close enough to my preferred temperatures when I get home so that it doesn’t really take long to get back to my comfort level.

Away Profile

When the temperature outside is 60° F or higher,
and the cool set point is NOT 74° F
I make sure the system is set to AC and the cool set point is set to 74° F. This means in warmer weather my house should never be above 74 if someone is no one is home.

When the temperature outside is 46° F or lower,
and the heat set point is NOT 65° F
I make sure the system is set to Heat and the heat set point is set to 65° F. This means that in cold weather my house will never be below 65 when no one is home.

So How Do I Do All This?

I setup a PHP cron script on my raspberry pi to run every 15 minutes. It performs a few sanity checks to make sure nothing weird is being reported by the API. It runs the profiles and then it logs the data to a database so that I have a complete picture of all the events.

For my project I downloaded an unofficial api here:
https://github.com/cjmaio/honeywell-tcc-api

Then I put together a cron script that looks something like this to run every 15 minutes:

$honeywell->login();
$thermostat = $honeywell->checkStatus();

if(is_array($thermostat)){

	//print_r($thermostat);

	$temp['outside'] = $thermostat['latestData']['uiData']['OutdoorTemperature'];
	$temp['inside'] = $thermostat['latestData']['uiData']['DispTemperature'];
	$coolSetPoint = $thermostat['latestData']['uiData']['CoolSetpoint'];
	$heatSetPoint = $thermostat['latestData']['uiData']['HeatSetpoint'];
	$current_mode = $thermostat['latestData']['uiData']['SystemSwitchPosition'];

	if($current_mode == 1){
		$set = $heatSetPoint;
	}else{
		$set = $coolSetPoint;
	}

	//sanity checks
	if($temp['outside'] > 110 || $temp['outside'] < -40){
		die("Outside temperature out of range");
	}

	if($temp['inside'] > 90 || $temp['inside'] < 50){
		die("Inside temperature out of range");
	}

	if($temp['outside'] == 0 && $temp['inside'] == 0){
		die("0 temperature?");
	}

	if($presence->count > 0){

		if($temp['outside'] >= 60 && $temp['inside'] >= 68 && $coolSetPoint > 68 ){ //set the AC for 68
			$honeywell->setThermostat(3);
			$honeywell->setCoolTemperature(68);
		}elseif($temp['outside'] <= 46 && $temp['inside'] <= 65 && $heatSetPoint < 67){ //set the Heat for 67
			$honeywell->setThermostat(1);
			$honeywell->setHeatTemperature(67);
		}
		

	}else{ //no one is home

		if($temp['outside'] >= 60 && $coolSetPoint !== 74){ //set the AC for 74
			$honeywell->setThermostat(3);
			$honeywell->setCoolTemperature(74);
		}elseif($temp['outside'] <= 46 && $heatSetPoint !== 65){ //set the Heat for 65
			$honeywell->setThermostat(1);
			$honeywell->setHeatTemperature(65);
		}
		
	}


	$query = "
		INSERT INTO `hvac_log` (
			`id`,
			`datetime`,
			`tinside`,
			`toutside`,
			`mode`,
			`setpoint`
		) VALUES (
			NULL,
			NOW(),
			'".db_escape_string($temp['inside'], $CFG->write_dbh['site'])."',
			'".db_escape_string($temp['outside'], $CFG->write_dbh['site'])."',
			'".db_escape_string($current_mode, $CFG->write_dbh['site'])."',
			'".db_escape_string($set, $CFG->write_dbh['site'])."'
		)
	";

	$qid = db_query($query, $CFG->write_dbh['site']);
}

I use my own database functions so you can omit the logging section if you want or revise it to suit your needs. I just wanted to demonstrate the data that I do log to give you an idea how it fits together in my charting. What kind of auto HVAC rules would you write?


Leave a Reply

Your email address will not be published. Required fields are marked *