安装ESPHome
pip install esphome -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
生成32key
openssl rand -base64 32
编写yaml配置文件
- DHT11温湿度传感器
esp01_dht11.yaml
esphome:
name: esp01s-test
friendly_name: ESP01S模块
esp8266:
board: esp01_1m
restore_from_flash: true
wifi:
ssid: "WIFI名"
password: "WIFI密码."
ap:
ssid: "ESP01S-热点"
password: "12345678"
captive_portal:
api:
encryption:
key: "刚刚的32位key"
web_server:
port: 80
ota:
platform: esphome
password: "ota123456"
logger:
baud_rate: 115200
time:
- platform: homeassistant
id: ha_time
mqtt:
broker: mqtt.bemfa.com
port: 9501
username: "bemfa私钥"
password: ""
client_id: bemfa私钥
will_message:
topic: "订阅主题004"
payload: "offline"
retain: true
on_connect:
then:
- mqtt.publish:
topic: "订阅主题004"
payload: "online"
retain: true
sensor:
- platform: dht
pin: GPIO2
model: DHT11
update_interval: 60s
temperature:
name: "室内温度_temp"
id: temp_val
filters:
- round: 1
on_value:
then:
- mqtt.publish:
topic: "eh73qf4H7004"
payload: !lambda 'return "temp:" + to_string(id(temp_val).state);'
retain: true
humidity:
name: "室内湿度_humi"
id: humi_val
filters:
- round: 1
on_value:
then:
- mqtt.publish:
topic: "eh73qf4H7004"
payload: !lambda 'return "hum:" + to_string(id(humi_val).state);'
retain: true
编译
esphome compile esp01_dht11.yaml
刷录
esphome run esp01_dht11.yaml
暂无评论,还不快来坐沙发...