1.所需硬件,n1盒子尸体一个,pm2.5传感器一个,甲醛浓度检测模块一个,环境光线检测模块一个,温湿度模块一个,esp32模块一个,tm1637两个,如果闲显示太小可以自己换一个0.8寸的
代码比较简单,如下:
esphome:
name: room-sensor
friendly_name: room-sensor
includes:
- winsen_ze08.h
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
wifi:
ssid: 00000000000000
password: 0000000000000
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "room-sensor"
password: "0000000000000"
captive_portal:
web_server:
port: 80
i2c:
#定义温湿度、光线传感器总线
- id: bus_a
sda: GPIO21
scl: GPIO22
scan: true
uart:
#定义pms颗粒物传感器数据脚
- id: uart_pm
rx_pin: GPIO13
tx_pin: GPIO14
baud_rate: 9600
#定有机物传感器数据脚
- id: uart_ze08
tx_pin: GPIO25
rx_pin: GPIO26
baud_rate: 9600
sensor:
#室内温湿度测量
- platform: aht10
temperature:
id: temp
name: "Room Temperature"
humidity:
id: humi
name: "Room Humidity"
update_interval: 60s
#室内颗粒物测量
- platform: pmsx003
uart_id: uart_pm
type: PMSX003
pm_1_0:
name: "Room pm <1.0µm"
pm_2_5:
name: "Room pm <2.5µm"
pm_10_0:
name: "Room pm <10.0µm"
update_interval: 60s
#室内有机物测量
- platform: template
name: "Room Formaldehyde"
id: ze08_ch2o
unit_of_measurement: ppb
accuracy_decimals: 0
update_interval: 60s
#光线测量
- platform: bh1750
name: "Room Illuminance"
address: 0x23
update_interval: 60s
custom_component:
- lambda: |-
auto ze08 = new WinsenZE08Sensor(id(uart_ze08), id(ze08_ch2o));
App.register_component(ze08);
return {ze08};
#时间显示+粉尘传感器定时
time:
- platform: homeassistant
id: homeassistant_time
on_time:
# Every 5 minutes
- seconds: 0
minutes: /10
then:
- switch.turn_on: relay
display:
- platform: tm1637
clk_pin: GPIO19
dio_pin: GPIO18
update_interval: 500ms
lambda: |-
static int i = 0;
i++;
if ((i % 2) == 0)
it.strftime("%H.%M", id(homeassistant_time).now());
else
it.strftime("%H%M", id(homeassistant_time).now());
- platform: tm1637
clk_pin: GPIO18
dio_pin: GPIO19
update_interval: 2s
lambda: |-
static int i = 0;
i++;
if ((i % 2) == 0)
it.strftime("%m.%d", id(homeassistant_time).now());
else
it.printf(0, "%.1fC", id(temp).state);
# it.printf(2, "%.0f", id(humi).state);
#粉尘传感器控制
switch:
- platform: gpio
pin: GPIO27
id: relay
name: "Room PSM sw"
icon: "mdi:weather-dust"
on_turn_on:
- delay: 60s
- switch.turn_off: relay
|