Skip to content

hugokernel/esphome-weather-station

Repository files navigation

ESPHome Weather Station

Read this in other language: French

Main photo of the weather station

Introduction

The electronic part of this weather station is based on the model described in an article in Elektor magazine published in May 2020 entitled Remake Elektor weather station (an evolution of ESP32 Weather Station described in an article in the same magazine in January 2019).

The article details the creation of a weather station based on a set of sensors referenced WH-SP-WS02 (Datasheet) whose original electronics are removed to be replaced by a sensor daughter board relaying the information to a motherboard built around an ESP32 (ESP32 Pico Kit).

An OpenSource firmware GitHub - ElektorLabs/191148-RemakeWeatherStation: RemakeWeatherStation is available to run the whole system. Unfortunately, I did not find my happiness with it, it is not yet complete enough and suffers from some shortcomings that make it very difficult to use it as is.

I therefore decided to use ESPHome as a replacement for the original program in order to simplify the development of functionality but above all to greatly extend its capabilities.

The board detailed in Elektor's article is finally limited to a voltage converter and a 5V/3V voltage adaptation for the ESP32.

It is therefore quite simple to recreate this weather station independently of Elektor's PCB. For the connections, please use the data included in the YAML file.

With the kind permission of Elektor, the schematic diagrams are available here: Schematics.

Case photo

Inspirations

Features

  • Measurement of temperature / relative humidity / atmospheric pressure
  • Wind speed / Direction
  • Precipitation daily / per minute
  • Ambient brightness
  • Input voltage
  • Solar panel:
    • Voltage
    • Current
    • Power
    • Daily accumulated power
  • RGB status led with WS2812
  • All ESPHome features

Note: On the main picture of the weather station, there is a box on top, it is an independent rain detection module.

Installation

In order to install the firmware on the ESP32, I invite you to follow the procedure described on the ESPHome website: Getting Started with ESPHome

Electronics

The Elektor electronic board is to be used as is or, in view of its simplicity, to be reproduced on a test board.

The Elektor publication is wrong, in fact, they use GPIO 34 (wind speed) and 38 (precipitation measurement) directly without a pullup resistor, Moreover, these inputs / outputs do not integrate a pull-up resistor, so it is necessary to add a pullup resistor (~10kOhms) on GPIO34 and GPIO38.

Mechanical

For the mast, I used a metal reinforced PVC tube that you can find in any DIY store in the plumbing department. In order to fix it on a wall, I modeled it on OpenSCAD one piece that I then printed in PETG.

Here is the printed piece next to the box containing the solar panel charger controller:

Photo of the power supply box

Powering

One of the flaws that I reproach to the original Elektor board is to have linked the technology of the power source to the motherboard (in this case the lead battery), indeed, a MAX8212 used with some peripheral components allows to cut the power supply when it goes below a threshold defined by the value of 3 resistors. This threshold has been chosen to protect a lead battery.

Since a weather station is supposed to stay on all the time, I don't really understand the above choice because:

  • We use a solar panel to charge the battery but in this case we are obliged to use a charge regulator which also protects the battery and therefore the integrated protection circuit is redundant and can even cause problems.
  • The station is connected to an unlimited power source (domestic power via a regulator) and in this case the protection circuit is useless.

In the 2 cases mentioned above, a strong link is inserted on the motherboard with the battery technology, which should be done, imho, on an independent card / module.

For my part, I chose to power my weather station via a 30W solar panel and a relatively basic charge controller.

If you are using Elektor's motherboard with an independent load controller module, do not forget to lower the cut-off threshold of the MAX8212.

At the output of the solar panel, the INA219 circuit allows the power generated by the solar panel to be measured. I plan to replace it with INA3221 in order to also measure the total consumption of the weather station and help me to refine the global consumption (a RFLink with OpenMQTTGateway and a second ESP32 kit is connected to the station).

I use a 7A lead battery recovered from an old inverter.

To size the whole thing, I recommend the BatteryStuff Tools tool which is very handy.

Currently, I can't say that I have succeeded in making my weather station totally energy independent because of a bad exposure of my solar panel and a too high consumption of an additional module (rain detection module).

Explanations

Measurement of temperature / humidity / atmospheric pressure

These 3 quantities are measured by a Bosch BME280 sensor and its configuration in ESPHome is as follows:

  - platform: bme280
    address: 0x76
    update_interval: 60s
    iir_filter: 16x
    temperature:
      name: "${friendly_name} temperature"
      oversampling: 16x
    humidity:
      name: "${friendly_name} humidity"
      oversampling: 16x
    pressure:
      name: "${friendly_name} pressure"
      oversampling: 16x

The sensor is to be put inside the box containing the original sensor electronics.

Initially, I also included an AM2320 sensor to compare the sensor values with the following configuration:

  - platform: am2320
    setup_priority: -100
    temperature:
      id: am2320_temperature
      name: "${friendly_name} AM2320 temperature"
    humidity:
      id: am2320_humidity
      name: "${friendly_name} AM2320 humidity"
    update_interval: 60s

The temperatures and humidities of the sensors were averaged before being sent to Home Assistant (see below), it was of course possible to access the data of each sensor.

  - platform: template
    name: "${friendly_name} temperature"
    icon: "mdi:thermometer"
    unit_of_measurement: "°C"
    lambda: |-
      return (
        id(bme280_temperature).state
        +
        id(am2320_temperature).state
      ) / 2;

  - platform: template
    name: "${friendly_name} humidity"
    icon: "mdi:water-percent"
    unit_of_measurement: "%"
    lambda: |-
      return (
        id(bme280_humidity).state
        +
        id(am2320_humidity).state
      ) / 2;

At the end of my tests, the BME280 sensor is more reliable and more accurate than the AM2320 sensor.

Wind measurements

Speed

The wind speed sensor is connected to general input 34 and the ESPHome pulse_meter platform is now used to perform the measurement.

You need to add a pulling resistor on the GPIO34 (there is no internal pullup on this GPIO).

Speed calculation
  1. First, check the number of pulses by revolution ($number_of_pulses_by_revolution)
  2. Then, we need the circumference of the anemomenter, to do that, measure the radius of the anemomenter in meter.
    In the example below, the radius is 9cm.
circumference_in_meter = $radius * 2 * π
circumference_in_meter = 0.09 * 2 * 3.14
circumference_in_meter = 0.565486678
  1. Now, we can found the number of rotations per seconds by counting the number of pulses for one rotation
    rotations_per_sec = pulses / $number_of_pulses_by_revolution / 60
  2. Next, we multiply circumference and rotation par second to have the wind speed.
    Note: 1.18 is a calibration factor to compensate the friction (you can adjust it).
meter_per_second = 1.18 * circumference_in_meter * $rotations_per_sec
meter_per_second = 1.18 * circumference_in_meter * 1 / $number_of_pulses_by_revolution / 60
meter_per_second = 1.18 * 0.565486678 / 2 / 60
meter_per_second = 0.005560619

Initial formula from mkuoppa/esphomeweatherstation#2 (comment)

For more information about calculation, see #6

  - platform: pulse_meter
    pin:
      number: GPIO34
      mode: INPUT
    id: wind_speed
    unit_of_measurement: 'm/s'
    name: "${friendly_name} wind speed"
    icon: 'mdi:weather-windy'
    internal_filter: 13us
    timeout: 5s
    filters:
      - multiply: 0.005560619
      - sliding_window_moving_average:
          window_size: 5
          send_every: 5

Direction

The wind direction is made in the sensor by means of magnets (switch reed) that switch resistors. Depending on the final value, the direction is deduced.

An example of the ESPHome configuration:

  - platform: resistance
    sensor: source_sensor
    id: resistance_sensor
    configuration: DOWNSTREAM
    resistor: 10kOhm
    internal: true
    name: Resistance Sensor
    reference_voltage: 3.9V
    accuracy_decimals: 1
    filters:
      - median:
          window_size: 7
          send_every: 4
          send_first_at: 3
    on_value:
      - if:
          condition:
            sensor.in_range:
              id: resistance_sensor
              above: 15000
              below: 15500
          then:
            - text_sensor.template.publish:
                id: wind_dir_card
                state: "N"
            - sensor.template.publish:
                id: wind_heading
                state: 0.0
[...]

Rain

The measurement of precipitation is carried out by a system of pendulum composed of 2 cups, the water runs in the funnel of the sensor and fills the high cup, once the latter is filled, it tips by gravity. This movement is detected by a magnetic sensor (reed switch) and an impulse is generated. The sensor documentation indicates that each pulse corresponds to 0.2794mm of precipitation.

  - platform: pulse_counter
    pin:
      # Don't forget to add a pulling resistor, see README
      number: GPIO38
      mode: INPUT
    unit_of_measurement: 'mm'
    name: "${friendly_name} rain gauge"
    icon: 'mdi:weather-rainy'
    id: rain_gauge
    internal: true
    count_mode:
      rising_edge: DISABLE
      falling_edge: INCREMENT
    internal_filter: 13us
    update_interval: 60s
    filters:
      # Each 0.011" (0.2794mm) of rain causes one momentary contact closure
      - multiply: 0.2794
    accuracy_decimals: 4

In order to have more relevant information, these measurements are converted into precipitation per minute and the daily total is calculated.

  - platform: integration
    name: "${friendly_name} rainfall per min"
    id: rain_per_min
    time_unit: min
    unit_of_measurement: 'mm'
    icon: 'mdi:weather-rainy'
    sensor: rain_gauge

  - platform: total_daily_energy
    name: "${friendly_name} total daily rain"
    power_id: rain_gauge
    unit_of_measurement: 'mm'
    icon: 'mdi:weather-rainy'
    # x60 To convert to aggregated rain amount
    filters:
      - multiply: 60

Brightness

Remember to position the brightness sensor as high as possible on your weather station so that it is not shaded by the mast or any part of the weather station.

  - platform: tsl2561
    id: lux_meter
    name: "${friendly_name} ambient Light"
    address: 0x39
    update_interval: 5s
    integration_time: 14ms
    gain: 1x

Files