本帖最后由 gmshiwoge 于 2021-3-6 18:31 编辑
天气越来越热了,心想怎么把普通风扇接入ha,学习了几遍论坛的diy改造风扇帖子确定亲自动手试试 esp8266----------- 一个 5v变压器---------- 一个 3路继电器-------- 一个 风扇开关改造一下 拆开把里面的卡扣拿出来,原本按一下会卡着,需要按第一个按钮才可以回弹,现在一下自动回弹。 软件的是esphome。按键设定 按一下开/关。 长按1秒上面3个任意按键关 现在有个小问题, 风扇在第一次通电,GPIO16回接通0点几秒后关闭,不知道怎么解决
esphome:
name: esp8266_fan
platform: ESP8266
board: esp01_1m
wifi:
ssid: "XXX"
password: "XXXXXXXXXXXX"
fast_connect: on
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esp32 01 Fan"
password: "1355955z"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
#esp32_ble_tracker:
web_server:
port: 80
css_url: https://esphome.io/_static/webserver-v1.min.css
js_url: https://esphome.io/_static/webserver-v1.min.js
switch:
- platform: restart
name: "rst_esp32_fan"
- platform: gpio
name: "fanlow"
pin: 15
id: low
interlock: [mid, fast]
- platform: gpio
name: "fanmid"
pin: 16
id: mid
interlock: [low, fast]
- platform: gpio
name: "fanfast"
pin: 04
id: fast
interlock: [low, mid]
#- platform: gpio
#name: "quanguan"
#pin: 4
#inverted: yes
#id: qg
#interlock: [low, mid,fast]
binary_sensor:
#- platform: status
#连接状态
#name: "esp32_fan"
- platform: gpio
pin:
number: 5 #io1接人体感应器
inverted: yes
mode: INPUT
name: "人体感应器1"
device_class: motion
id: pir501
filters:
- invert:
- delayed_on: 500ms
- delayed_off: 30s
- platform: gpio
pin:
number: GPIO14
mode: INPUT_PULLUP
inverted: True
name: "fasttouch"
on_click:
min_length: 10ms
max_length: 500ms
then:
- switch.toggle: low
- platform: gpio
pin:
number: GPIO12
mode: INPUT_PULLUP
inverted: True
name: "fasttouch"
on_click:
min_length: 10ms
max_length: 500ms
then:
- switch.toggle: mid
- platform: gpio
pin:
number: GPIO13
mode: INPUT_PULLUP
inverted: True
name: "fasttouch"
on_click:
min_length: 10ms
max_length: 500ms
then:
- switch.toggle: fast
- platform: gpio
pin:
number: GPIO13
mode: INPUT_PULLUP
inverted: True
name: "fasttouch"
on_click:
min_length: 600ms
max_length: 5000ms
then:
- switch.turn_off: fast
- switch.turn_off: mid
- switch.turn_off: low
- platform: gpio
pin:
number: GPIO14
mode: INPUT_PULLUP
inverted: True
name: "fasttouch"
on_click:
min_length: 600ms
max_length: 5000ms
then:
- switch.turn_off: fast
- switch.turn_off: mid
- switch.turn_off: low
- platform: gpio
pin:
number: GPIO12
mode: INPUT_PULLUP
inverted: True
name: "fasttouch"
on_click:
min_length: 600ms
max_length: 5000ms
then:
- switch.turn_off: fast
- switch.turn_off: mid
- switch.turn_off: low
sensor:
- platform: template
sensors:
fan_speeds:
value_template: >
{% if states('switch.fanlow') == 'unavailable' %}
unavailable
{% elif states('switch.fanfast') == 'on' %}
高速
{% elif states('switch.fanmid') == 'on' %}
中速
{% elif states('switch.fanlow') == 'on' %}
低速
{% else %}
关闭
{% endif %}
fan: #建立一个fan元件
- platform: template
fans:
fan_speed:
value_template: >
{% if is_state("sensor.fan_speeds", "unavailable") %}
off
{% elif states('sensor.fan_speeds') == '关闭' %}
off
{% else %}
on
{% endif %}
speed_template: '{{ states("sensor.fan_speeds") }}'
turn_on:
- service: switch.turn_on
entity_id: switch.fanlow
turn_off:
- service: switch.turn_off
entity_id: switch.fanlow
- service: switch.turn_off
entity_id: switch.fanmid
- service: switch.turn_off
entity_id: switch.fanfast
set_speed:
- service: switch.turn_on
data_template:
entity_id: >
{% if speed == '低速' %}
switch.fanlow
{% elif speed == '中速' %}
switch.fanmid
{% elif speed == '高速' %}
switch.fanfast
{% elif speed == '关闭' %}
switch.off
{% endif %}
speeds:
- '关闭'
- '低速'
- '中速'
- '高速'
homekit:
filter:
include_domains:
- fan
|