/ August 3, 2020/ Articles, Home Assistant, Weather/ 0 comments

I have made a Solar Weather Station in a Birdhouse. This is based in this project. I ordered the components and some extra’s to measure lux and rain:

  • The Wemos D1 Mini Pro (had this already)
  • BME280 for Temperature, Humidity, Pressure (AliExpress)
  • BH1750 for Light Luxsensor (AliExpress)
  • SI1145 to measure UV Index, IR Light (raw), Visible Light (raw)
  • FC-37 raindrop sensor with a LM393 converter (AliExpress)
  • Dew Point calculation sensor
  • Absolute Humidity calculation sensor
  • 5V 250mA Solar panel (AliExpress)
  • TP4056 Charger module (AliExpress)
  • The 3-Pin PCB switch (had this already)
  • Screw terminal (had this already)
  • 18650 Lithium 3400mAh Battery (AliExpress)
  • Some header pins (AliExpress)
  • The PCB board at PCBWay (PCBWay)

I didn’t wanted to make it with an Arduino sketch, but want to make it in ESPHome. So is used the following code in ESPHome for the Wemos:

substitutions:
  display_name: SolarWeatherStation

esphome:
  name: solar_weather
  platform: ESP8266
#  board: d1_mini_pro
  board: d1_mini

  includes:
    - SI1145.h
  libraries:
    - "Adafruit SI1145 Library"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_pass

api:

# Enable logging
logger:

mqtt:
  broker: !secret mqtt_broker
  birth_message:
    topic: solarsensor/birthdisable
    payload: disable
  will_message:
    topic: solarsensor/willdisable
    payload: disable

ota:

i2c:
 - id: ic_1
   sda: 4
   scl: 5
   scan: true
   frequency: 100kHz
   
binary_sensor:
  - platform: gpio
    pin: 
      number: D5
      inverted: True
    name: ${display_name} Rain
    device_class: moisture
    filters:
      - delayed_on_off: 10000ms
    
sensor:
  - platform: wifi_signal
    name: "WiFi Signal Sensor"
    update_interval: 25s
    
  - platform: bme280
    address: 0x76
    update_interval: 15s
    temperature:
      name: ${display_name} Temp
      id: bme280_temperature
      oversampling: 4x
      filters:
      - offset: -1.6
    pressure:
     name: ${display_name} Pres
     id: bme280_pressure
     oversampling: 4x
    humidity:
     name: ${display_name} Humi
     id: bme280_humidity
     oversampling: 4x
    
  - platform: bh1750
    name: ${display_name} Lux
    address: 0x23
    update_interval: 15s

  - platform: template
    name: ${display_name} Absolute Humidity
    lambda: |-
      const float mw = 18.01534;    // molar mass of water g/mol
      const float r = 8.31447215;   // Universal gas constant J/mol/K
      return (6.112 * powf(2.718281828, (17.67 * id(bme280_temperature).state) /
        (id(bme280_temperature).state + 243.5)) * id(bme280_humidity).state * mw) /
        ((273.15 + id(bme280_temperature).state) * r); // in grams/m^3
    accuracy_decimals: 2
    update_interval: 25s
    icon: 'mdi:water'
    unit_of_measurement: 'g/m³'
    
  - platform: template
    name: ${display_name} Dew Point
    lambda: return (243.5*(log(id(bme280_humidity).state/100)+((17.67*id(bme280_temperature).state)/(243.5+id(bme280_temperature).state)))/(17.67-log(id(bme280_humidity).state/100)-((17.67*id(bme280_temperature).state)/(243.5+id(bme280_temperature).state))));
    unit_of_measurement: °C
    update_interval: 25s
    icon: 'mdi:thermometer-alert'
    
  - platform: custom
    lambda: |-
      auto UV_sensor = new SI1145_sensor();
      App.register_component(UV_sensor);
      return {UV_sensor->visible_sensor, UV_sensor->ir_sensor, UV_sensor->uvindex_sensor};

    sensors:
    - name: ${display_name} Visible Light
    - name: ${display_name} IR Light
    - name: ${display_name} UV Index
      unit_of_measurement: uvindex
      accuracy_decimals: 2
      
  - platform: adc
    id: bat_vcc
    pin: A0
    name: ${display_name} Battery
    update_interval: 15s
    filters:
      - multiply: 5.37

  - platform: template
    name: ${display_name} Battery Percentage
    unit_of_measurement: '%'
    update_interval: 15s
    lambda: |-
      return ((id(bat_vcc).state /4.25) * 100.00);
    
deep_sleep:
 run_duration: 35s
 sleep_duration: 5min

The above code does need some tuning. For example the ADC multiply. First of all disable the filter. Than a RealValue between 0-1V will be shown in the ESPHome log. Measure the real battery value with a multiple meter. Then BatteryMeasure / RealValue = Multplier.

Also the Battery Percentage needs some tuning, and the Deep Sleep needs tuning. The 35s is enough to drop some sensor readings and i feel ok with an 5 min sleep.
For the binary rain sensor there is a delayed_on_off so the sensor is not bouncing during the sensor reading.

To read an UV index i did use the SI1145, but the first try wasn’t succesfully. I have stacked the sensor on the BH1750 sensor, this is possible because it is a different address.
This is not an integrated sensor so i needed the library for that. I tried it, but i was continous getting 0 values. After all it turnes out that a manual library for a I2C and using the integrated I2C is not working together. So i stopped using it for a while. After a while someone posted on github that the I2C frequency wasn’t the same for this custom sensor and the built in I2C of esphome. I changed the code and added:frequency: 100kHz within in the I2C section and all working now.
To get this working you need to upload the SI1145.h and the library code files to your esphome folder. Get the right SI1145.h here and the library here (upload the Adafruit_SI1145.cpp and Adafruit_SI1145.h file)

I also added the Dewpoint calculation sensor and the Absolute Humidity sensor calculator from the BME280.

To make the project more fun, i decided to create it in a bird house. Did some sawing and nailing, drilled some ventilation holes, made roof protection and divided the electronics part from the bird part. And made it waterproof.
The result:

For Home Assistant i used the following code:

# Weather Station
  - platform: mqtt
    name: Weather Station Temp
    state_topic: "solar_weather/sensor/solarweatherstation_temp/state"
    unit_of_measurement: "°C"
    force_update: true
    device_class: temperature
  - platform: mqtt
    name: Weather Station Humi
    state_topic: "solar_weather/sensor/solarweatherstation_humi/state"
    unit_of_measurement: "%"
    force_update: true
    device_class: humidity
  - platform: mqtt
    name: Weather Station Absolute Humidity
    state_topic: "solar_weather/sensor/solarweatherstation_absolute_humidity/state"
    icon: mdi:water-percent
    unit_of_measurement: "g/m³"
    force_update: true
  - platform: mqtt
    name: Weather Station Pres
    state_topic: "solar_weather/sensor/solarweatherstation_pres/state"
    unit_of_measurement: "hPa"
    force_update: true
    device_class: pressure
  - platform: mqtt
    name: Weather Station Lux
    state_topic: "solar_weather/sensor/solarweatherstation_lux/state"
    unit_of_measurement: "lux"
    device_class: illuminance
    force_update: true
  - platform: mqtt
    name: Weather Station Dewpoint
    state_topic: "solar_weather/sensor/solarweatherstation_dew_point/state"
    unit_of_measurement: "°C"
    force_update: true
    device_class: temperature
  - platform: mqtt
    name: Weather Station UV Index
    state_topic: "solar_weather/sensor/solarweatherstation_uv_index/state"
    force_update: true
    icon: mdi:wall-sconce-round
  - platform: mqtt
    name: Weather Station Battery
    state_topic: "solar_weather/sensor/solarweatherstation_battery/state"
    unit_of_measurement: "V"
    force_update: true
    device_class: battery
  - platform: mqtt
    name: Weather Station Battery Percentage
    state_topic: "solar_weather/sensor/solarweatherstation_battery_percentage/state"
    unit_of_measurement: "%"
    force_update: true
    device_class: battery
  - platform: mqtt
    name: Weather Station Wifi Signal
    state_topic: "solar_weather/sensor/wifi_signal_sensor/state"
    unit_of_measurement: "dB"
    force_update: true
    device_class: signal_strength

At the end it is looking like this:

Edit: Because the sesors are in a Bird house, the temperature is higher then in the ouside air. Also the light (lux) values aren’t correct. Therefore i create some ventilation holes in the bird house. You can also make your own Stevenson screen instead of a bird house. For the light intesity i create a hole with some plexiglass, behind the hole i glued the lux and light sensor.

Share this Post

Leave a Comment

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
*
*

eighteen − seventeen =