本帖最后由 UNtest001 于 2019-11-8 16:54 编辑
硬件还是sonoff basic 引脚用了io1 和io3,本身还有个io2 群里大佬说拉低不能正常开机就没有使用
这里接光敏电阻(5516)没有接光照感应器的目的有两个,1是反映极其迅速,2是只占用一个引脚(光照感应器要占用2个)当然还有就是便宜1块钱买一把的那种.
(ps光敏电阻也是论坛大佬提供的经验,感谢前人栽树,)
代码奉上
esphome:
name: pir501_light
platform: ESP8266
board: esp01_1m
wifi:
ssid: "ZTE-EE5005" #WiFi名
password: "qq731283993z" #WiFi密码
# Optional manual IP
manual_ip:
static_ip: 192.168.0.133 #指定IP,
gateway: 192.168.0.5
subnet: 255.255.255.0
# Enable logging
logger:
#Enable Home Assistant API
api:
password: "33" #接入ha的密码
ota:
password: "33" #OTA空刷密码
switch:
- platform: gpio
name: "开关" #主开关
pin: GPIO12
id: relay #id为后面要用的到
binary_sensor:
- platform: gpio
pin:
number: GPIO0 #io0
mode: INPUT_PULLUP
inverted: True
name: "微动开关"
on_press:
- switch.toggle: relay
- platform: gpio
pin:
number: GPIO3 #io3接光敏电阻
mode: INPUT_PULLUP
inverted: True
name: "光敏"
id: light
- platform: gpio
pin:
number: 1 #io1接人体感应器
inverted: yes
mode: INPUT
name: "人体感应器1"
device_class: motion
id: pir501
filters:
- invert:
- delayed_on: 500ms
- delayed_off: 60s #延时关闭
on_press:
then:
- if:
condition:
and:
- binary_sensor.is_on: pir501
- binary_sensor.is_off: light #同时满足人体感应器感应到人,和光敏电阻为关,才会打开开关(光敏电阻为关为晚上光照度低的时候)
then:
- logger.log: "Detected somebody activity"
- switch.turn_on: relay
else:
- logger.log: "There is no one around"
- switch.turn_off: relay
on_release: #感应不到人关闭开关
then:
- switch.turn_off: relay
status_led:
pin:
number: GPIO13 #LED指示灯
inverted: yes
有个小坑待解决
|