Furnace Raspi Overview

Smart HVAC control is now possible through Home Assistant with the help of Room Assistant and a Raspberry Pi furnace controller, providing reliable energy savings and consistent temperature throughout your home.

The furnace controller is one of my favorite and most used integrations so far.

This one is located in my furnace connected to the interface to control the fan, heat and AC for the furnace through some 5v relays and a Raspi model B.

On the Raspbian OS running on the pi I have installed Room Assistant following this guide to handle the low level communication stuff back to my Home Assistant server.

Wiring

Wiring diagram for the furnace control devices and connections.

furnace raspi wiring diagram

Not too difficult or complex, though when combined with multiple temperature sensors around the house the functionality is unmatched.

Using some old hardware and a few relays, I have an smart furnace and energy savings!

Furnace Info and Use

One of the issues in the rental home I live in is the inconsistency of HVAC coverage throughout the house. This drove me crazy!

Upstairs is too hot while the downstairs rooms needed mittens and a hat. The main issue being with the main temp reading coming from the stair mid house.

We have a split level 3 bed with a small blower furnace in the crawl space of the house and duct work run all throughout (except the downstairs bathroom for some reason).

The location of the thermostat, while central is not the best representation of the perceived temp felt in the rooms we actually spend time in.

I had enough, time to automate it!

Hardware

Using on old Raspberry Pi that was a dumpster find, I built the controller with (3) 5v relay boards and a DHT11 temp sensor.

These relays are mounted to the top of the controller with DuPont cables connected to GPIO pins on the pi and the temp sensor up on a few stand-offs outside of the case.

Network and Power

Previously I had run a bunch of network cables around the house through the crawl space and luckily I was able to re-purpose one of these for the cause. This hardwired connection provides reliable connectivity.

Power is fed from a 5v android wall charger in the same outlet that feeds the furnace. There was an open socket and it is switched with the furnace by US building code, so it will shutdown if something needs service later.

Furnace Controls

The furnace Pi is connected directly to the 12v furnace interface in parallel with the existing house thermostat controller.

This is due to the lack of confidence in the initial controllers performance and longevity, and due to the function being *fairly important (heat/ac + kids = must_have).

Since the house is a rental, and the landlord likely wont approve, the main t-stat is still connected for immediate control if needed at the wall. Stealth home control!

Mounting

The unit is mounted in the furnace, resting in the return air path due to clearance, cable pathway requirements, and not wanting to modify anything not mine.

This provided an additional benefit of having a dht11 temp/humid sensor in the return air path. More sensor data!!

Software

Everything is controlled and mapped to the home assistant dashboard over MQTT via the room-assistant system.

Room Assistant Config

This config file is the meat and potatoes of the program. Find it in /home/$USER/room-assistant/config/local.yml on the Raspberry Pi.

# ########################
# Raspi Config
#   Crawl Space
#   Above furnace in crawl space 
#   Monitor and control the furnace and crawl space
#   10.0.0.74
# ########################

# ############
# GPIO Pin-Out
# ############
# PIN: 4 AltFunction: | DHT11
# PIN: 17 AltFunction: | heat
# PIN: 22 AltFunction: | Fan
# PIN: 23 AltFunction: | AC
# PIN: 29 AltFunction: | reset

# #######################
# Global Config settings
# #######################
global:
  instanceName: crawlspace
  integrations:
    - homeAssistant
    - gpio
    - shell

# #######################
# Cluster settings
# #######################
# Config options for clustering multiple Room-Assistant
# Give leader more weight
cluster:
  weight: 1
  networkInterface: eth0
  port: 6425
  timeout: 60
  peerAddresses:
    # raspi1 patio
    - 10.10.10.70:6425
    # raspi2 office
    - 10.10.10.71:6425
    # raspi3 sprinkler
    - 10.0.0.71:6425
    #raspi4 kitchen
    - 192.168.1.75:6425 
    # raspi5 crawlspace <-- this pc
#    - 10.0.0.74:6425
    # raspi6 garage
    - 10.10.10.73:6425

# #######################
# home assistant settings
# #######################
homeAssistant:
  mqttUrl: mqtt://10.10.10.21:1883
  mqttOptions:
    username: homeassistant
    password: {LONG_RANDOM_STRING}

# #######################
# GPIO settings
# #######################
gpio:

# #######################
# Switches settings
# #######################  
  switches:

    # Relay 1 - Fan Run
    - name: Fan On
      pin: 22
      icon: mdi:fan

    # Relay 2 - AC RUN
    - name: Air Conditioning
      pin: 23
      icon: mdi:air-conditioner

    # Relay 3 - HEAT RUN
    - name: Heater
      pin: 17
      icon: mdi:fire

    # HARD Reset PIN
    - name: Crawl space reset
      pin: 29
      icon: mdi:power

# #######################
# Shell settings
# #######################
shell:
  sensors:

     # DHT11 Sensor reporting the temp °F result
    - name: Crawl Space Temperature
      command: 'python3.7 /home/pi/room-assistant/script/myDHT.py'
      regex: '(-?[0-9.]+)F'
      cron: '*/2 * * * *'
      icon: mdi:temperature-fahrenheit
      unitOfMeasurement: '°F'
      deviceClass: temperature

     # DHT11 Sensor reporting the humid % result
    - name: Crawl Space Humidity
      command: 'python3.7 /home/pi/room-assistant/script/myDHT.py'
      regex: '(-?[0-9.]+)%'
      cron: '*/5 * * * *'
      icon: mdi:water-percent
      unitOfMeasurement: '%'
      deviceClass: humidity

    # Script to check onboard temp sensor reading
    - name: Crawl Space CPU Temp
      command: '/home/pi/room-assistant/script/cpuTemp.sh'
      cron: '*/2 * * * *'
      unitOfMeasurement: F
      deviceClass: temperature

    # Script to check voltage and return boolean if no errors seen. 
    # See the script for more
    - name: Crawl CPU Voltage
      command: '/home/pi/room-assistant/script/cpuVolt.sh'
      cron: '1 */1 * * *'
      deviceClass: power

    # Report CPU uptime in sec
    - name: Crawl CPU Up Time
      command: '/home/pi/room-assistant/script/cpuUp.sh'
      cron: '* * * * *'
      unitOfMeasurement: 's'

    # Free memory `free -h` results
    - name: Crawl CPU Free Memory
      command: '/home/pi/room-assistant/script/freeMem.sh'
      cron: '*/10 * * * *'
      unitOfMeasurement: 'MB'

Scripts

Some additional helper scripts were also developed to return info on the device for integrations and status’s over in home assistant.

Add these to room assistant using the shell.sensors function like this:

shell:
  sensors:

     # DHT11 Sensor reporting the temp °F result
    - name: Garage Temperature
      command: 'python3.7 /home/pi/room-assistant/script/myDHT.py'
      regex: '(-?[0-9.]+)F'
      cron: '*/2 * * * *'
      icon: mdi:temperature-fahrenheit
      unitOfMeasurement: '°F'
      deviceClass: temperature

cpuUp.sh

return the uptime in seconds formatted as int

#!/bin/bash

echo `cat /proc/uptime |awk '{print $1}' |cut -d '.' -f1`

cpuTemp.sh

return the CPU reported temp

#!/bin/bash

cpuTemp=`vcgencmd measure_temp |cut -d "=" -f2 |cut -d "'" -f1 | awk '{print ($1 *9/5) + 32}'`
echo $cpuTemp

freeMem.sh

returns the remaining RAM on the pi

#!/bin/bash

memfree=`cat /proc/meminfo | grep MemFree | awk '{print $2}'`; 
memtotal=`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`; 


awk '/MemFree/{free=$2} /MemTotal/{total=$2} END{print (free*100)/total}' /proc/meminfo

myDHT.py

adapted DHT11 temp sensor reading temp and humid

import time
import Adafruit_DHT

DHT_SENSOR = Adafruit_DHT.DHT11
DHT_PIN = 4

while True:
    humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)
    if humidity is not None and temperature is not None:
        temperature_f = temperature * (9 / 5) + 32
        print("Temp={0:0.1f}F Humidity={1:0.1f}%".format(temperature_f, humidity))
        exit()
    else:
        time.sleep(.05);

temperature_sensor_code.py

read DS18B20 sensor, report value in F


# Temp DS180b20 reading into F result on raspi
#
# https://pimylifeup.com/raspberry-pi-temperature-sensor/
# Modified from
#   - git clone https://github.com/pimylifeup/temperature_sensor.git

import os
import glob
import time

os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')

base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
device_file = device_folder + '/w1_slave'

def read_temp_raw():
    lines = []
    i = 0
    # try to read the file 20 times, return the result
    while not lines and (i < 19):
        try:
            f = open(device_file, 'r')
            lines = f.readlines()
            i += 1
        except NameError:
            time.sleep(1)
        else:
            if not lines:
                f.close()
            else:
                f.close()
                return lines

def read_temp():
    lines = read_temp_raw()
    if lines[0].strip()[-3:] != 'YES':
        lines = read_temp_raw()
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:]
        temp_c = float(temp_string) / 1000.0
        temp_f = temp_c * 9.0 / 5.0 + 32.0
        return temp_f

# print to reduced decimal place
print('{0:06.3f}'.format(read_temp()))

cpuVolt.sh

return boolean if no issues with voltage (power supply failure)

#!/bin/bash

THROTTLED=`/opt/vc/bin/vcgencmd get_throttled |cut -d "=" -f2`
RESULTS=0

if [[ "$THROTTLED" != *"0x0"*  ]];then
	RESULTS=1
fi

echo $RESULTS

Future Improvements

  • Additional temp sensors affixed to the water pipe lines (hot water usage?)
  • Additional sensor in the crawl space generally (freeze protection).
  • Leak detection around water pipe service connection and sprinkler branch

In conclusion, the Room Assistant and Raspberry Pi furnace controller provides a reliable and efficient solution to HVAC control, allowing for energy savings and consistent temperature throughout the home.

The combination of low-cost hardware and smart automation software makes this project a great example of how to integrate IoT into your home. Whether you’re looking to automate your furnace or just make your home more comfortable, this setup is a great starting point that can be adapted to suit your individual needs.