1、模块介绍

固件:esphome

芯片:esp8266

接入方式:WIFI

功能:三档调速+按钮控制

购买连接:淘宝连接

2、模块样式

尺寸(长宽高):10cm*4cm*3cm

3、接线方式

4、联网方式

设备通电后,模块红色led会点亮。打开手机wifi,找到"Esp-fan Hotspot"的wifi热点。

连接后即可配网!

注意:风扇通电时,按钮3必须是未按下的状态,否则无法正常启动!!!

当模块无法连接到wifi时,会自动生成热点,方便在更换网络时配对。

5、接入苹果homekit、米家

视频教程:https://www.bilibili.com/video/BV15M4m1U7iu/

6、esphome代码

esphome:
  name: esp-fan
  friendly_name: esp-fan

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:
 reboot_timeout: 0s

ota:
  password: "123456"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp-fan Hotspot"
    password: ""

captive_portal:
    
web_server:
  port: 80


switch:
  - platform: gpio
    pin: GPIO14
    name: speed_1
    internal: true
    icon: mdi:fan-speed-2
    id: relay2

  - platform: gpio
    pin: GPIO13
    name: speed_2
    internal: true
    icon: mdi:fan-speed-1
    id: relay1

  - platform: gpio
    pin: GPIO12
    internal: true
    name: speed_3
    icon: mdi:fan-speed-3
    id: relay3

binary_sensor:
  - platform: gpio
    pin: GPIO5
    internal: false
    name: speed1
    id: touch_e
    on_press:
      then:
        - delay: 200ms
        - lambda: |-
            auto call = id(threespeedfan).turn_on();
            call.set_speed(1);
            call.perform();
    on_release:
      then:
        - lambda: |-
            id(threespeedfan_1).set_level(0);
        - fan.turn_off: 
            id: threespeedfan


  - platform: gpio
    pin: GPIO4
    internal: false
    name: speed2
    id: touch_f
    on_press:
      then:
        - delay: 200ms
        - lambda: |-
            auto call = id(threespeedfan).turn_on();
            call.set_speed(2);
            call.perform();
    on_release:
      then:
        - lambda: |-
            id(threespeedfan_1).set_level(0);
        - fan.turn_off: 
            id: threespeedfan

  - platform: gpio
    pin: GPIO15
    name: speed3
    internal: false
    id: touch_g
    on_press:
      then:
        - delay: 200ms
        - lambda: |-
            auto call = id(threespeedfan).turn_on();
            call.set_speed(3);
            call.perform();
    on_release:
      then:
        - lambda: |-
            id(threespeedfan_1).set_level(0);
        - fan.turn_off: 
            id: threespeedfan

output:
  - platform: template
    id: threespeedfan_1
    type: float 
    write_action:
      - if:
          condition:
            lambda: return ((state == 0));
          then:
            # action for off
            - switch.turn_off: relay1
            - delay: 300ms
            - switch.turn_off: relay2
            - delay: 300ms
            - switch.turn_off: relay3
      - if:
          condition:
            lambda: return ((state > 0) && (state < 0.4));
          then:
            # action for speed 1
            - switch.turn_off: relay2
            - delay: 300ms
            - switch.turn_off: relay3
            - delay: 300ms
            - switch.turn_on: relay1
      - if:
          condition:
            lambda: return ((state > 0.4) && (state < 0.7));
          then:
            # action for speed 2
            - switch.turn_off: relay1
            - delay: 300ms
            - switch.turn_off: relay3
            - delay: 300ms
            - switch.turn_on: relay2      
      - if:
          condition:
            lambda: return ((state > 0.7));
          then:
            # action for speed 3
            - switch.turn_off: relay1
            - delay: 300ms
            - switch.turn_off: relay2
            - delay: 300ms
            - switch.turn_on: relay3        

fan:
  - platform: speed
    id: threespeedfan
    output: threespeedfan_1
    name: "风扇"
    speed_count: 3
    restore_mode: ALWAYS_OFF

text_sensor:
  - platform: template
    name: "风扇状态"
    update_interval: 1s
    icon: mdi:fan
    lambda: |-
      if ((id(touch_g).state || !id(touch_g).state) && id(relay3).state == true) {
        return {"三档"};
      } else if ((id(touch_f).state || !id(touch_f).state) && id(relay2).state == true) {
        return {"二档"};
      } else if ((id(touch_e).state || !id(touch_e).state) && id(relay1).state == true) {
        return {"一档"};
      } else {
        return {"待机中"};
      }