Building a DIY Weather Station with Home Assistant

A DIY weather station is a fantastic project for smart home enthusiasts, combining sensors, microcontrollers, and Home Assistant for real-time weather data collection and automation. In this guide, we’ll walk you through how to build your own weather station, connect it to Home Assistant, and visualize the data.


What You’ll Need

Hardware:

  1. Microcontroller: ESP32 or ESP8266 (NodeMCU) for Wi-Fi connectivity.
  2. Sensors:
    • Temperature & Humidity: DHT22, BME280, or SHT31.
    • Barometric Pressure: BMP280 or BME280.
    • Rainfall: Rain gauge sensor (e.g., tipping bucket).
    • Wind Speed/Direction: Anemometer kit with wind vane.
  3. Power Supply: USB adapter or battery with solar charging for outdoor use.
  4. Enclosure: Waterproof case to protect components from weather.
  5. Wires & Breadboard: For prototyping.

Software:

  • Home Assistant: The central hub for managing and displaying weather data.
  • ESPHome or MQTT: For connecting the microcontroller to Home Assistant.
  • Arduino IDE or ESPHome Add-on: To program the microcontroller.

Step 1: Connect the Sensors

Example Setup Using BME280 (Temperature, Humidity, and Pressure):

  1. Connect the BME280 sensor to the ESP32:
    • VCC → 3.3V
    • GND → GND
    • SCL → GPIO 22 (ESP32 default I2C clock pin)
    • SDA → GPIO 21 (ESP32 default I2C data pin)
  2. For additional sensors like anemometers or rain gauges, follow the sensor-specific wiring diagrams.

Step 2: Program the ESP32 Using ESPHome

ESPHome simplifies connecting ESP-based devices to Home Assistant. Follow these steps:

Install ESPHome:

  1. Go to Home Assistant → Settings → Add-ons → ESPHome → Install.

Create a New Node Configuration:

  1. In ESPHome, create a new configuration:
    • Select your device (ESP32) and give it a name (e.g., weather_station).
  2. Add sensor configurations in YAML:
yamlKopioi koodiesphome:
  name: weather_station
  platform: ESP32
  board: esp32dev

# Wi-Fi Connection
wifi:
  ssid: "YourWiFiSSID"
  password: "YourWiFiPassword"

# Enable Home Assistant API
api:
logger:
ota:

# I2C Setup
i2c:
  sda: 21
  scl: 22
  scan: true

# BME280 Sensor Configuration
sensor:
  - platform: bme280
    temperature:
      name: "Outdoor Temperature"
      oversampling: 16x
    humidity:
      name: "Outdoor Humidity"
    pressure:
      name: "Atmospheric Pressure"
    address: 0x76
    update_interval: 60s
  1. Upload the configuration to your ESP32.

Step 3: Add the Weather Station to Home Assistant

  1. After uploading, ESPHome will automatically detect the new device.
  2. Go to Settings → Devices & Services → ESPHome in Home Assistant.
  3. Your weather station sensors (e.g., temperature, humidity, pressure) will appear as entities.

Step 4: Visualize the Data in Home Assistant

Create a Lovelace Dashboard Card:

Add a new card to your dashboard to display weather data.

yamlKopioi kooditype: entities
title: Weather Station
entities:
  - entity: sensor.outdoor_temperature
    name: Temperature
  - entity: sensor.outdoor_humidity
    name: Humidity
  - entity: sensor.atmospheric_pressure
    name: Pressure

Graph Historical Data:

For historical tracking, use the History Graph card:

yamlKopioi kooditype: history-graph
title: Weather Data Over Time
entities:
  - entity: sensor.outdoor_temperature
  - entity: sensor.outdoor_humidity
  - entity: sensor.atmospheric_pressure

Step 5: Automate Using Weather Data

Home Assistant allows you to create automations based on the weather data from your station. For example:

Example Automation: Turn on a Fan if Temperature Exceeds 25°C

yamlKopioi koodialias: Turn On Fan When Hot
trigger:
  - platform: numeric_state
    entity_id: sensor.outdoor_temperature
    above: 25
action:
  - service: switch.turn_on
    target:
      entity_id: switch.living_room_fan

Optional Enhancements

  1. Add More Sensors: Include rain sensors or wind gauges for comprehensive weather tracking.
  2. Use MQTT Instead of ESPHome: If you prefer MQTT for communication, install the Mosquitto MQTT broker and program the ESP32 using Arduino IDE with libraries like PubSubClient.
  3. Solar Power Setup: Add a solar panel and battery to make your weather station self-sustaining.

Conclusion

Building a DIY weather station with Home Assistant is an exciting project that provides valuable real-time weather insights for your smart home. Whether you’re monitoring outdoor temperature, automating fans, or analyzing weather patterns, integrating sensors with Home Assistant using ESPHome offers flexibility and ease of use.

By following this guide, you’ll have a fully functional weather station up and running in no time!