在ESPHOME代码中加入MQTT用来检测MQTT与HA是否连接正常这功能是否可行?ESP01S模块刷了ESPHOME固件,通过MQTT与HA连接。想用ESP01S的LED灯来提示MQTT是否连接正常。当MQTT断开时自动开启LED的开关,就可以通过观测LED是否亮起知道MQTT的连接状态。 简单说一下问题:需求MQTT断开后怎样自动开启LED的灯?加什么代码可以实现,请指教,谢谢。
esphome:
name: esp01s
esp8266:
board: esp01_1m
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
password: "e6efc4df7883813a86f2dead09ec5bae"
wifi:
ssid: "youlove"
password: "18622693"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esp01S Fallback Hotspot"
password: "kQ21KLFmZrYC"
captive_portal:
mqtt: #连接家里HA主机的MQTT
broker: tfmen.com
username: loveyou
password: 18622693
switch:
- platform: gpio
pin: 2 # LED灯检测MQTT是否连通
name: "led"
inverted: true
|