substitutions: { desc: 传感器, devicename: sensor }
esphome:
name: $devicename
platform: ESP8266
board: nodemcuv2
arduino_version: latest
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "MhXiJqKKyCXTqjZWqtegaP1tQSUpPtbnXP9iV1i2TzE="
ota:
password: "8e9c493c1fda598d0789f514507f3538"
wifi: !include common/wifi.yaml
captive_portal:
web_server:
port: 80
output:
- pin: 2
id: led_pin2
platform: gpio
light:
- id: led
output: led_pin2
platform: binary
name: "${devicename}_led"
上面是示例代码,创建一个开关,控制ESP8266上面的LED灯
目的:在不经过HA的情况下,如何获取这个设备LED的状态?
通过浏览器访问
http://sensor.local/light/sensor_led
会返回Json格式的数据