PIR Sensor for Energy-Saving HVAC Control

Project Overview

This project creates an energy-saving HVAC control system that automatically adjusts temperature settings based on room occupancy. When a room is occupied, the system maintains normal temperature; when the room is empty for a set period, it enters an energy-saving mode with a temperature setback. This can reduce heating and cooling costs by 10-20% annually.

Difficulty: Intermediate
Estimated time: 3-4 hours
Estimated cost: $30-50

How It Works

PIR sensors placed in key rooms detect occupancy. When no motion is detected for a set period, the system sends a signal to the HVAC system to adjust the temperature setpoint (higher for cooling, lower for heating). When occupancy is detected again, the system returns to the normal setpoint.

Materials Needed

  • ESP32 or ESP8266 (1)
  • HC-SR501 PIR sensors (1-5)
  • Jumper wires
  • Power supply (5V 2A)
  • Smart thermostat with API (Nest, Ecobee, or Home Assistant)

Home Assistant Setup

  1. Install Home Assistant on a Raspberry Pi or server
  2. Add your thermostat integration
  3. Note the entity ID for your thermostat (e.g., climate.living_room)
  4. Enable ESPHome integration for PIR sensors

ESPHome Configuration

esphome:
  name: occupancy_sensors

esp32:
  board: esp32dev

wifi:
  ssid: "YourWiFiSSID"
  password: "YourWiFiPassword"

api:
  password: "YourAPIPassword"

binary_sensor:
  - platform: gpio
    pin: GPIO4
    name: "Living Room Motion"
    device_class: motion
    filters:
      - delayed_on: 100ms
      - delayed_off: 60000ms
  
  - platform: gpio
    pin: GPIO5
    name: "Bedroom Motion"
    device_class: motion
    filters:
      - delayed_on: 100ms
      - delayed_off: 60000ms

Home Assistant Automations

# configuration.yaml
automation:
  - alias: "HVAC - Enter Away Mode"
    trigger:
      - platform: state
        entity_id: 
          - binary_sensor.living_room_motion
          - binary_sensor.bedroom_motion
        to: "off"
        for: "00:30:00"
    condition:
      - condition: state
        entity_id: binary_sensor.house_occupied
        state: "on"
    action:
      - service: climate.set_temperature
        target:
          entity_id: climate.main_thermostat
        data:
          temperature: 62
      - service: input_boolean.turn_off
        target:
          entity_id: input_boolean.house_occupied

  - alias: "HVAC - Return to Normal"
    trigger:
      - platform: state
        entity_id: 
          - binary_sensor.living_room_motion
          - binary_sensor.bedroom_motion
        to: "on"
    condition:
      - condition: state
        entity_id: binary_sensor.house_occupied
        state: "off"
    action:
      - service: climate.set_temperature
        target:
          entity_id: climate.main_thermostat
        data:
          temperature: 68
      - service: input_boolean.turn_on
        target:
          entity_id: input_boolean.house_occupied

Standalone Arduino Version

// Standalone HVAC Controller with PIR
const int pirPin = 4;
const int relayPin = 5;

unsigned long lastMotionTime = 0;
const unsigned long setbackDelay = 1800000;
bool inSetback = false;

void setup() {
  pinMode(pirPin, INPUT);
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW);
  delay(60000);
}

void loop() {
  bool motion = digitalRead(pirPin) == HIGH;
  
  if (motion) {
    lastMotionTime = millis();
    if (inSetback) {
      digitalWrite(relayPin, LOW);
      inSetback = false;
    }
  }
  
  if (!inSetback && (millis() - lastMotionTime > setbackDelay)) {
    digitalWrite(relayPin, HIGH);
    inSetback = true;
  }
  
  delay(100);
}

Installation Steps

  1. Place PIR sensors in key rooms at 2m height
  2. Connect sensors to ESP32 with long cables if needed
  3. Configure Home Assistant with ESPHome integration and thermostat
  4. Create automations for occupancy-based setback
  5. Test system to verify enters setback after no motion and returns when motion detected

Conclusion

This occupancy-based HVAC control system automatically reduces energy waste when rooms are empty, lowering utility bills without sacrificing comfort.

Leave a Reply

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