Building an ESPHome environmental multi-sensor

Envirosense ESP8266 take 2

Sometime early last year I replaced my SmartThings home automation hub with a Home Assistant VM running on an Intel NUC.

Not long after that I converted my Envirosense boards (see previous post) to run the ESPHome firmware and started scraping Prometheus metrics from Home Assistant.

There was one thing I wasn’t happy about with my original design. The PIR sensor was frequently showing false positive motion events.
This seems to have gotten worse with the switch to the ESPHome firmware. It appears to be a known issue that these HC-SR501 modules are easily triggered by Wifi interference.

So I decided to redesign the board and enclosure to use a better PIR sensor and also added an ambient light sensor.

I used some Perf+ 2 wire free electronic prototyping board that I had picked up a while back. Unfortunately it looks like this is no longer available anywhere. There’s a simple windows .NET based circuit design program called Perfy, that I used for the board layout.

Here’s the main parts list:

  • NodeMCU ESP8266
  • Bosch BME280 breakout board
  • Panasonic EKMC1609111
  • Adafruit BH1750 Light Sensor
  • 1 x 47KΩ resistor (used as a pull-down on the PIR breakout)

Example ESPHome configuration below:

 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
# EnviroSense ESPHome device configuration
esphome:
  name: sense2

esp8266:
  board: nodemcuv2

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  power_save_mode: HIGH

logger:

api:
  encryption:
    key: !secret api_key

ota:
  password: !secret ota_password

switch:
  - platform: restart
    name: Workshop restart

i2c:
  sda: D2
  scl: D1

sensor:
  - platform: bme280
    temperature:
      name: Workshop Temperature
      oversampling: 1x
      accuracy_decimals: 1
    pressure:
      name: Workshop Pressure
      oversampling: 1x
      accuracy_decimals: 0
    humidity:
      name: Workshop Humidity
      oversampling: 1x
      accuracy_decimals: 0
    address: 0x77
    update_interval: 60s

  - platform: bh1750
    name: "Workshop Illuminance"
    address: 0x23
    measurement_duration: 69
    resolution: 4.0
    accuracy_decimals: 0
    update_interval: 60s

  - platform: wifi_signal
    name: Workshop WiFi Signal
    update_interval: 60s

binary_sensor:
  - platform: gpio
    name: Workshop PIR Motion
    pin:
      number: D6
      mode:
        input: true
        pullup: false
    device_class: motion
    filters:
      - delayed_on: 10ms
      - delayed_off: 60000ms
    on_press:
      then:
        - light.turn_on: led
    on_release:
      then:
        - light.turn_off: led

  - platform: status
    name: Workshop Status

output:
  - platform: esp8266_pwm
    id: onboard_led
    pin:
      number: D0
      inverted: true

light:
 - platform: monochromatic
   output: onboard_led
   id: led

Note that you’ll also need an an additional secrets.yaml file that has matching entries for the various !secret variables referenced in the above example.