ESPHome on Wemos D1 Mini
This guide covers the installation and configuration of ESPHome for the Wemos D1 Mini, a popular and affordable ESP8266-based development board.
Prerequisites
Section titled “Prerequisites”- Hardware: Wemos D1 Mini (or clone), Micro-USB cable (ensure it supports data, not just charging).
- Software: Python installed (for CLI) or a browser with Web Serial support (Chrome/Edge) for the web dashboard.
Installation
Section titled “Installation”Option 1: Web Dashboard (Recommended for Beginners)
Section titled “Option 1: Web Dashboard (Recommended for Beginners)”- Connect your Wemos D1 Mini to your computer via USB.
- Go to web.esphome.io.
- Click Connect and select the COM port associated with your device.
- Follow the on-screen instructions to prepare your device for the first time.
Option 2: Command Line Interface (CLI)
Section titled “Option 2: Command Line Interface (CLI)”If you prefer the terminal, you can install ESPHome via pip:
pip install esphomeBasic Configuration
Section titled “Basic Configuration”Create a new YAML file (e.g., living-room.yaml) with the following basic configuration for a Wemos D1 Mini.
esphome: name: living-room-sensor friendly_name: Living Room Sensor
esp8266: board: d1_mini
# Enable logginglogger:
# Enable Home Assistant APIapi:
# Enable Over-The-Air updatesota: - platform: esphome
wifi: ssid: "YourWiFiName" password: "YourWiFiPassword"
# Enable fallback hotspot (captive portal) in case wifi connection fails ap: ssid: "Living-Room-Sensor Fallback Hotspot" password: "fallback_password"
captive_portal:Pinout Reference
Section titled “Pinout Reference”The Wemos D1 Mini pins map to ESP8266 GPIOs as follows:
| Label | GPIO | Function |
|---|---|---|
| D0 | GPIO16 | Wake |
| D1 | GPIO5 | I2C SCL |
| D2 | GPIO4 | I2C SDA |
| D3 | GPIO0 | Flash |
| D4 | GPIO2 | TX1 / LED |
| D5 | GPIO14 | SPI CLK |
| D6 | GPIO12 | SPI MISO |
| D7 | GPIO13 | SPI MOSI |
| D8 | GPIO15 | SPI CS |
Best Practices
Section titled “Best Practices”1. Use secrets.yaml
Section titled “1. Use secrets.yaml”Never hardcode passwords in your main configuration files, especially if you commit them to Git. Use a secrets.yaml file.
secrets.yaml:
wifi_ssid: "MyHomeNetwork"wifi_password: "SuperSecretPassword"living-room.yaml:
wifi: ssid: !secret wifi_ssid password: !secret wifi_password2. Static IP Address
Section titled “2. Static IP Address”Assigning a static IP can make connections faster and more reliable, although mDNS (.local address) usually works well.
wifi: # ... existing config ... manual_ip: static_ip: 192.168.1.50 gateway: 192.168.1.1 subnet: 255.255.255.03. Safe Mode / Fallback
Section titled “3. Safe Mode / Fallback”Always keep the captive_portal and ap (Access Point) configuration. If your WiFi credentials change or the device cannot connect, it will spawn its own WiFi network that you can connect to and upload a new configuration.
4. Power Management
Section titled “4. Power Management”The Wemos D1 Mini has a small 3.3V regulator.
- Do not power high-current devices (like motors or long LED strips) directly from the 3.3V pin.
- Use the 5V pin (connected to USB power) for relays or sensors that support 5V, or use an external power supply.
5. Logging
Section titled “5. Logging”Keep the logger: component enabled. When debugging, you can view logs wirelessly:
esphome logs living-room.yamlExample: Adding a DHT11 Sensor
Section titled “Example: Adding a DHT11 Sensor”Connect a DHT11 sensor to pin D2 (GPIO4).
sensor: - platform: dht pin: D2 temperature: name: "Living Room Temperature" humidity: name: "Living Room Humidity" update_interval: 60s