Ismoh / ESP8266-D1-Mini-DHT22

Humidity and temperature sensor using ESP8266 for Home Assistant integration as a custom device.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ESP8266 using AM2302 with Home Assistant discovery

Table of Contents

Hardware

ESP8266 Espressif Wemos D1 Mini

ESP branding looks like to be a chaotic mess. You can clearly see Espressif brand logo on the board, but it's called ESP8266 Wemos D1 Mini? I bought it on Amazon.de.
Datasheet can be found here.

DHT22 (AM2302) Temperature and Humidity Sensor

AM2302 is the same a s DHT22, but with a plastic cover.
Datasheet can be found here.

Setup

Copy and paste credentials.h-SAMPLE to credentials.h and fill in your credentials appropriately,
but double check to do not store credentials in git.

Circuit diagram

Circuit diagram

VSCode-Arduino extension setup

  • Install VSCode

  • Install Arduino CLI

    • Put the arduino-cli.exe for example in
      C:\Program Files\Arduino-CLI and run
    set PATH=%PATH%;C:\Program Files\Arduino-CLI
  • and/or install Arduino IDE, but I prefer CLI

  • Install the Arduino extension

  • Press F1 and type Select Board select Arduino: Board Manager. Expand Type and select ESP8266. Select the latest version and install it.

  • Press F1 and type Select Port select Arduino: Select Serial Port. Select the port your ESP8266 is connected to.

  • Press Ctrl+Shift+I for rebuilding IntelliSense Configuration.

  • Press Ctrl+Shift+R for compiling the sketch. This will generate a new Arduino configuration in the c_cpp_properties.json file. Then reload VSCode.

  • Use Ctrl+Alt+U to upload the sketch to the board.

VSCode-Arduino Serial Monitor

  • Press F1 and type Open Serial Monitor select Arduino: Open Serial Monitor.

Manually installed libraries

Library management is only easy, when those are provided by Arduino Library Manager, otherwise it's a bit annoying. Further readings!

HARestAPI

Download the HARestAPI v0.3.2 library and extract its content to C:\Users\%USERNAME%\Documents\Arduino\libraries\HARestAPI.

ESPAsyncWebServer

Download the ESPAsyncWebServer-master library and extract its content to C:\Users\%USERNAME%\Documents\Arduino\libraries\ESPAsyncWebServer.

Home Assistant Integration

The sensor will be automatically added as entities in Home Assistant, but not as a device.
Entity IDs will be
sensor.esp8266_thcs_{n}_temperature,
sensor.esp8266_thcs_{n}_humidity and
sensor.esp8266_thcs_{n}_wifi_rssi.

{n} is the number of the device, starting with 1 and can be configured in credentials.h, see #define SECRET_DEVICE_NAME.

Example card

I am using a horizontal-stack card:

title: Garage
type: horizontal-stack
cards:
  - type: tile
    entity: sensor.esp8266_thcs_1_temperature
    name: Temperature
    icon: mdi:thermometer
    state_content:
      - state
      - last-changed
    vertical: true
  - type: tile
    name: Humidity
    icon: mdi:water-percent
    show_entity_picture: false
    vertical: true
    hide_state: false
    state_content:
      - state
      - last-changed
    entity: sensor.esp8266_thcs_1_humidity
  - type: gauge
    entity: sensor.esp8266_thcs_1_wifi_rssi
    unit: dBm
    name: WiFi RSSI
    needle: true
    max: -30
    severity:
      green: -50
      yellow: -70
      red: -90
    min: -90

ESP8266 OTA update

In credentials.h you need to set all #defines to your needs.
Depending on your SECRET_DEVICE_NAME and SECRET_WEB_SERVER_PORT the OTA update URL will be
http://{SECRET_DEVICE_NAME}.local:{SECRET_WEB_SERVER_PORT}/update like so
http://esp8266-thcs-1.local:80/update.

Make sure to adjust your .vscode/arduino.json file with:

{
  ...,
  "output": "build"
}

After the first upload, you can use the OTA update on the same network with http://esp8266-thcs-1.local:80/update and select the build\\main.ino.bin file.

About

Humidity and temperature sensor using ESP8266 for Home Assistant integration as a custom device.


Languages

Language:C++ 90.7%Language:C 9.3%