ESPHome custom/external component for Winsen ZH03B laser particulate matter sensor with support for both Initiative Upload (Passive) and Question & Answer (Q&A) modes.
π’ NB: Examples of using uart debug and commands directly in yaml (without custom components) are available in the example folder.
- π PM1.0, PM2.5, and PM10.0 measurements in Β΅g/mΒ³
- β Dual Mode Support: Initiative (Passive) and Q&A modes
- π Battery-friendly Q&A mode with configurable intervals
- π Power efficient: Q&A mode reduces consumption by ~65%
- β³ Extended lifetime: Up to 5+ years with Q&A mode
- π‘οΈ Data validation with checksum verification
- π Home Assistant integration ready
- π‘ UART communication at 9600 baud
- π§ Customizable sensor parameters (filters, device class, etc.)
external_components:
- source: github://Bjk8kds/esphome-zh03b-sensor
components: [ zh03b ]- Clone this repository
- Copy the
components/zh03bfolder to your ESPHome configuration directory - Add the local component reference to your YAML
| ZH03B Pin | Function | ESP32 Pin | Wire Color |
|---|---|---|---|
| VCC | Power Supply | 5V | Red |
| GND | Ground | GND | Black |
| TX | Data Output | GPIO16 (RX) | Green |
| RX | Command Input | GPIO17 (TX) | Yellow |
β οΈ Important: Both TX and RX connections are required for Q&A mode operation
# UART Configuration
uart:
id: uart_zh03b
tx_pin: GPIO17
rx_pin: GPIO16
baud_rate: 9600
# Sensor Configuration
sensor:
- platform: zh03b
uart_id: uart_zh03b
pm_1_0:
name: "PM 1.0"
pm_2_5:
name: "PM 2.5"
pm_10_0:
name: "PM 10.0"# UART Configuration
uart:
id: uart_zh03b
tx_pin: GPIO17
rx_pin: GPIO16
baud_rate: 9600
# Sensor Configuration
sensor:
- platform: zh03b
uart_id: uart_zh03b
mode: QA
update_interval: 2min # Request data every 2 minutes
pm_1_0:
name: "PM 1.0"
pm_2_5:
name: "PM 2.5"
pm_10_0:
name: "PM 10.0"| Parameter | Type | Default | Description |
|---|---|---|---|
mode |
string | PASSIVE |
Operating mode: PASSIVE or QA |
update_interval |
time | 60s |
Update interval for Q&A mode (min 30s) |
pm_1_0 |
sensor | - | PM1.0 sensor configuration |
pm_2_5 |
sensor | - | PM2.5 sensor configuration |
pm_10_0 |
sensor | - | PM10.0 sensor configuration |
uart_id |
id | - | UART bus ID reference |
- Sensor continuously transmits data every second
- Real-time air quality monitoring
- No commands sent to sensor
- Higher power consumption
- ESP32 controls when to request data
- Sensor sleeps between measurements (dormant mode)
- Extends sensor lifetime up to 5x compared to passive mode
- Reduces power consumption by ~65% (from 120mA to ~42mA average)
- Ideal for battery-powered applications
- Minimum 30s update interval, default 60s
| Mode | Current | Description |
|---|---|---|
| Active | <120mA | During measurement |
| Sleep/Dormant | <20mA | Between measurements (Q&A mode only) |
| Q&A Mode Average | ~42mA | With 60s interval (22% duty cycle) |
- MTTF: >10,000 hours continuous operation
- Extended lifetime with Q&A mode: Up to 5+ years
- Passive mode: ~1 year continuous operation
- Q&A mode (60s interval): ~5 years (5x longer than passive mode)
π‘ Tip: Using Q&A mode with dormant periods significantly extends sensor lifetime by reducing laser diode usage and mechanical wear.
mode: PASSIVE # Real-time monitoring
pm_2_5:
name: "Living Room PM2.5"
filters:
- sliding_window_moving_average:
window_size: 10
send_every: 10mode: QA
update_interval: 5min # Extends sensor life while saving power
pm_2_5:
name: "Outdoor PM2.5"
filters:
- median:
window_size: 5mode: QA
update_interval: 15min- β Check 5V power supply to sensor
- β Verify UART pin connections
- β Ensure correct baud rate (9600)
- β Confirm TX pin is connected to sensor RX
- β Verify update_interval β₯ 30s
- β Enable debug logging to see commands
logger:
level: DEBUG
logs:
zh03b: VERY_VERBOSE- Sensor may need power cycle
- Try Q&A mode for more control
- Check for electromagnetic interference
components/
βββ zh03b/
βββ __init__.py # Empty file
βββ sensor.py # Python configuration
βββ zh03b.h # C++ header
βββ zh03b.cpp # C++ implementation
[D][zh03b:123]: Passive mode - PM1.0: 5, PM2.5: 12, PM10: 15 Β΅g/mΒ³
[D][zh03b:234]: Q&A: Sending READ_DATA command
[D][zh03b:345]: Q&A mode - PM1.0: 4, PM2.5: 11, PM10: 14 Β΅g/mΒ³
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Open a Pull Request
MIT License - see LICENSE file for details.
- ESPHome development team
- ZH03B sensor manufacturers
- Community contributors
- π ESPHome Documentation
- π¬ Home Assistant Community
- π Issue Tracker
Made with β€οΈ for the ESPHome community