罗总的继电器项目https://github.com/qlwz/esp_relay
不知道为什么我用的时候经常无响应或者断开了链接,有的没问题有的就经常断,也许是esp01m的品控问题又或许是mqtt服务器问题,反正就是有问题。。
废话不多说,直接上esphome代码
esphome:
name: 1l-kt-3light
platform: ESP8266
board: esp01_1m
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
password: "315663"
wifi:
ssid: "A1"
password: "65999wlc"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "1L-Kt-3Light Fallback Hotspot"
password: "65999wlc"
captive_portal:
web_server:
port: 80
binary_sensor:
- platform: gpio
pin:
number: GPIO04
mode:
input: true
pullup: true
inverted: true
id: button_1
on_press:
then:
- light.toggle: light_1
on_release:
then:
- light.toggle: light_1
- platform: gpio
pin:
number: GPIO09
mode:
input: true
pullup: true
inverted: true
id: button_2
on_press:
then:
- light.toggle: light_2
on_release:
then:
- light.toggle: light_2
- platform: gpio
pin:
number: GPIO010
mode:
input: true
pullup: true
inverted: true
id: button_3
on_press:
then:
- light.toggle: light_3
on_release:
then:
- light.toggle: light_3
# - platform: status
# name: "Status"
output:
- platform: gpio
pin: GPIO14
id: relay_1
- platform: gpio
pin: GPIO12
id: relay_2
- platform: gpio
pin: GPIO5
id: relay_3
light:
- platform: binary
name: "1l_kt_light1"
id: light_1
output: relay_1
- platform: binary
name: "1l_kt-light2"
id: light_2
output: relay_2
- platform: binary
name: "1l_kt-light3"
id: light_3
output: relay_3
这个是三开的,如需删减成1开2开请注意gpio对应
罗总的原理图
|