Featured image of post Integrating Wind Sensors with ESPHome into Home Assistant

Integrating Wind Sensors with ESPHome into Home Assistant

The wind sensor from the awning manufacturer: €200. My solution with an ESP8266 and ESPHome: €20. Here's how I solved it myself — and which automations have been running automatically ever since.

My awning gave me quite a fright once. A storm rolled in faster than expected — and I wasn’t home. When I got back, it was still up, but just barely. Clearly, the awning needed a wind sensor. The manufacturer conveniently had a solution ready — for €200. For a single sensor.

That was out of the question. An ESP8266 microcontroller, a wind sensor (anemometer) for around €20, and ESPHome solved the problem for a tenth of the price. Since then, the awning retracts automatically when the wind gets too strong — and I no longer have to worry about it.

YouTube Video
To load the video, please click the image. Please note that by doing so, data will be transmitted to YouTube.

What You’ll Need

To get started, you only need a few components:

  • An ESP8266 microcontroller (buy here* - affiliate link)
  • A wind sensor/anemometer (buy here* - affiliate link)
  • A 5V power supply (e.g., an old phone charger)
  • ESPHome (already installed)
  • Your smart home hub — in this example, Home Assistant

If you’re not yet familiar with ESPHome, I recommend checking out this introduction first.

Measuring Wind

The anemometer measures wind movement via rotations. Each rotation generates electrical pulses that the microcontroller captures. Using a formula defined by the sensor model, the current wind speed is calculated and transmitted via Wi-Fi to your smart home hub.

Wiring

Connect the cables of the wind sensor to the GPIO pins of the microcontroller. Use a standard 5V power supply to power the microcontroller — an old phone charger works perfectly. Important: Note which GPIO pin the wind sensor is connected to, as you’ll need this information later for the configuration.

Software Setup — Programming with ESPHome

Creating the Basic Configuration

Start with a simple configuration file in ESPHome. It contains the basic information your microcontroller needs, such as:

  • The device name (e.g., “windsensor”),
  • The platform (ESP8266 or ESP32, depending on your microcontroller),
  • Wi-Fi settings (SSID and password of your network).

All of this happens in lines 1–26 below.

Defining the Sensor for the Anemometer

The wind sensor is configured as a pulse_counter. This module counts the pulses and calculates the wind speed using a filter (starting at line 37). We use the formula provided by the manufacturer in their documentation and apply it here as a lambda function in the sensor definition (line 62).

Calculating Averages and Wind Gusts

In addition to the current wind speed, average values and maximum wind speeds (gusts) are particularly useful. For this, you use template sensors with appropriate filters.

  • Average value (sliding_window_moving_average): Calculates the mean wind speed over the last 30 minutes (line 81)
  • Maximum value (max): Stores the highest speed over the last 5 minutes (wind gusts) (line 96)

Here is the complete configuration:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
esphome:
  name: windspeed
  friendly_name: Windmesser
  
esp8266:
  board: nodemcuv2

# Enable Logging
logger:

# Home Assistant API, required so Home Assistant can access the microcontroller
api:
  encryption:
    key: "xxx"

ota:
  - platform: esphome
    password: "xxx"

web_server:
  port: 80
  
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

# Definition of the sensors that are provided as entities in Home Assistant
sensor:
  # Sensor showing the WiFi signal strength of the microcontroller
  - platform: wifi_signal
    name: "WiFi Signal"
    update_interval: 60s
  # Sensor showing the uptime of the microcontroller
  - platform: uptime
    name: Uptime 
  # Measurement of the current wind speed using "pulse_counter"
  - platform: pulse_counter
    name: 'Wind Speed Realtime'
    icon: "mdi:windsock"
    id: wind_speed
    unit_of_measurement: 'km/h'
    device_class: wind_speed
    state_class: measurement
    # Frequency at which the wind sensor signal is checked
    internal_filter: 1us 
    # Frequency at which the wind speed is updated in Home Assistant
    update_interval: 1s
    accuracy_decimals: 1
    # Wiring of the wind sensor
    pin:
      number: D5
      inverted: true
      mode:
        input: true
        pullup: true
    # Provides an additional entity with the total pulse count (useful for debugging only)
    total:
       name: "Total Pulses"
    # Calculates wind speed using the manufacturer's formula: Wind speed (km/h) = 0.8*Hz + 3
    # The filter definition computes the wind speed using this formula
    # The input variable x corresponds to the number of "pulses per minute"
    filters:
      - lambda: !lambda |-
          if (x == 0) return 0;
          return (x/60)*0.8+3;
      - min:
          window_size: 2
          send_every: 1
  # Sensor providing the "average wind speed"
  - platform: template
    name: "Wind Speed Average"
    icon: "mdi:windsock"
    unit_of_measurement: 'km/h'
    device_class: wind_speed
    state_class: measurement
    lambda: |-
      return id(wind_speed).state;      
    update_interval: 1s
    # Definition: wind speed = average wind over the last 30 min
    filters:
    - sliding_window_moving_average:        
        window_size: 1800
        send_every: 1
  # Sensor providing the maximum gust speed
  - platform: template
    name: "Wind Speed Gusts"
    icon: "mdi:windsock"
    unit_of_measurement: 'km/h'
    device_class: wind_speed
    state_class: measurement
    lambda: |-
      return id(wind_speed).state;      
    update_interval: 1s
    # Gust = instantaneous maximum speed within the last 5 min
    filters:
    - max:        
        window_size: 300
        send_every: 1

Flashing the Configuration

Open ESPHome and connect your microcontroller via USB. Click “Install” and upload the configuration. Once the microcontroller has been programmed once, future updates can be flashed wirelessly (“Over the Air”).

Integration into Home Assistant

ESPHome makes integration particularly straightforward:

  1. Open Home Assistant.
  2. Navigate to “Settings > Integrations > Add Integration”.
  3. Select “ESPHome” and enter the IP address of your microcontroller.
  4. Enter the encryption key from your ESPHome configuration.

Once the integration is complete, you can view the recorded values (current speed, average, gusts) in Home Assistant and use them for automations.

What’s Next

With the collected wind data, you have a wide range of control options, for example:

  • Automatically retract awnings when a critical wind speed is reached.
  • Close roller shutters to protect windows during storms.
  • Send warning notifications when extreme weather conditions are approaching.

Do you have questions or other ideas for what you can do with wind data? Write them in the comments — I’m curious what you’ll build with this.

Note: Links marked with affiliate link are affiliate links. As an Amazon Associate I earn from qualifying purchases. This means I receive a small commission if you purchase through these links — at no extra cost to you. The revenue helps me run this blog and YouTube channel and keep creating content. Thank you for your support!

Joachim
To load the comments, please click 'Show comments'. Please note that by doing so, data will be transmitted to Disqus.
Show comments
Built with Hugo
Theme Stack designed by Jimmy