『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 1450|回复: 4

[硬件DIY] 夏天到了,并不是每个人的风扇都是直流的

[复制链接]

48

主题

709

帖子

4712

积分

元老级技术达人

积分
4712
金钱
4003
HASS币
50
QQ
发表于 2024-5-26 17:56:57 | 显示全部楼层 |阅读模式
本帖最后由 602293544 于 2024-5-26 17:56 编辑

硬件参考  https://bbs.hassbian.com/thread-23541-1-1.html
自己又加了继电器,一个控制灯,一个控制风扇火线,一个蜂鸣器,一个433接收方便遥控

Snipaste_2024-05-26_17-48-58.png

自行编译

substitutions:                             #每个文件添加这个
  device_name: fan_light

esphome:
  name: $device_name
  platform: ESP8266
  board: nodemcuv2        #nodemcuv2  esp8285  esp01_1m
  on_boot:                #重启蜂鸣一下,提示硬件已准备就绪
    priority: -100
    # ...
    then:
      - switch.turn_on: relay3
      - delay: 200ms
      - switch.turn_off: relay3
wifi:
  ssid: !secret wifi_shufang
  password: !secret wifi_password
  reboot_timeout: 120s          #超时重新连接等待时间
  fast_connect: true          # true,直接连接到 WiFi 网络而不先进行扫描。隐藏网络必选,可以显着缩短连接时间。默认为false. 缺点是此选项连接到 ESP 看到的第一个网络,即使该网络非常远且有更好的网络可用。
  power_save_mode: none  #省电模式
  # manual_ip:
  #   static_ip: 192.168.123.68
  #   gateway: 192.168.123.1
  #   subnet: 255.255.255.0
  ap:
    # ssid: wifi_ssid_AP              #禁用: 将设备名称作为 ssid
    ssid: ${device_name}_ap
    password: "12345678"

api:  
  reboot_timeout: 0s       #连接home assistant 默认不重启

ota:
#  safe_mode: true       #安全模式,没密码不能ota
#  password: 123456

captive_portal:        #连不到WiFi进AP模式配网

web_server:            #web模式
  port: 80

logger:
  level: DEBUG

text_sensor:
  - platform: wifi_info
    ip_address: {"name": "${device_name}_IP","icon": "mdi:ip"}
    mac_address: {"name": "${device_name}_MAC","icon": "mdi:access-point-network"}

  - platform: version
    name: "ESPHome Version"

  - platform: template
    name: fan_speed
    id: global_value

button:
  - platform: restart
    name: ${device_name}_reboot    

globals:                     #全局参数,存储风扇风速
  - id: shared_value
    type: int
    initial_value: '0'

output:
  - platform: ac_dimmer
    id: dimmer1
    min_power: 0
    max_power: 1
    gate_pin: GPIO13 #用于控制可控硅的引脚。
#    inverted: true
    method: leading pulse
    zero_cross_pin: #用于感测交流过零事件的引脚
      number: GPIO12
      mode:
        input: true
#      inverted: true

  - platform: template        #220v不是线性的,到一定值才会启动,通过模板模拟可以从0开始启动,自行测试修改下方函数
    id: outputsplit
    type: float
    min_power: 0
    max_power: 1
    write_action:
      - output.set_level:
          id: dimmer1
          level: !lambda |-
            if(state == 0)
            {
              return 0;
            }
            else
            {
              return (state * 0.27 + 0.6);
            }

fan:
  - platform: speed
    # output: dimmer1
    output: outputsplit
    id: little_fan
    name: "little fan"
    speed_count: 100
    on_turn_on:
      - switch.turn_on: relay2
    on_turn_off:
      - switch.turn_off: relay2
      - lambda: |-
            id(shared_value) = 0;
            id(global_value).publish_state(std::to_string(id(shared_value)));
            ESP_LOGD("little_fan", "speed is: %d", id(shared_value));
    on_speed_set:
      then:
        - lambda: |-
            id(shared_value) = id(little_fan).speed;
            id(global_value).publish_state(std::to_string(id(shared_value)));
            ESP_LOGD("little_fan", "speed is: %d", id(shared_value));

switch:

  - platform: gpio
    name: ${device_name}_light
    pin: 14
    id: relay1
    on_turn_on:
      - switch.turn_on: relay3
      - delay: 200ms
      - switch.turn_off: relay3
    on_turn_off:
      - switch.turn_on: relay3
      - delay: 200ms
      - switch.turn_off: relay3

  - platform: gpio
    name: ${device_name}_fanswitch
    pin: 16
    id: relay2
    on_turn_on:
      - switch.turn_on: relay3
      - delay: 200ms
      - switch.turn_off: relay3
    on_turn_off:
      - switch.turn_on: relay3
      - delay: 200ms
      - switch.turn_off: relay3

  - platform: gpio
    pin: 15
    id: relay3

remote_receiver:
  pin: GPIO4
  dump:
    - rc_switch
  tolerance: 50%
  filter: 250us
  idle: 4ms
  buffer_size: 2kb

binary_sensor:

  - platform: remote_receiver
    # name: "Remote_light"
    id: Remote_light
    filters:
      - delayed_off: 300ms
    rc_switch_raw:
      code: "000000011000011010100010"
    on_press:
      then:
        - switch.toggle: relay1

  - platform: remote_receiver
    # name: "Remote_fan_up"
    id: Remote_fan_up
    filters:
      - delayed_off: 300ms
    rc_switch_raw:
      code: "000000011000011010100011"
    on_press:
      then:
        - lambda: |-
            if (id(shared_value) >= 90) {
              // global value is greater than 5
              id(shared_value) = 100;
              id(global_value).publish_state("100");
            } else {
              id(shared_value) += 10;
              id(global_value).publish_state(std::to_string(id(shared_value)));
            }

            ESP_LOGD("little_fan", "speed is: %d", id(shared_value));

        - fan.turn_on:
            id: little_fan
            speed: !lambda return id(shared_value);

  - platform: remote_receiver
    # name: "Remote_fan_down"
    id: Remote_fan_down
    filters:
      - delayed_off: 300ms
    rc_switch_raw:
      code: "000000011000011010100100"
    on_press:
      then:
        - lambda: |-
            if (id(shared_value) <= 10) {
              // global value is greater than 5
              id(shared_value) = 0;
              id(global_value).publish_state("0");
            } else {
              id(shared_value) -= 10;
              id(global_value).publish_state(std::to_string(id(shared_value)));
            }

            ESP_LOGD("little_fan", "speed is: %d", id(shared_value));
            
        - if:
            condition:
              lambda: 'return id(shared_value) >= 10;'
            then:
              - fan.turn_on:
                  id: little_fan
                  speed: !lambda return id(shared_value);
            else:
              - fan.turn_off:
                  id: little_fan

  - platform: remote_receiver
    # name: "Remote_fan_off"
    id: Remote_fan_off
    filters:
      - delayed_off: 300ms
    rc_switch_raw:
      code: "000000011000011010100001"
    on_press:
      then:
        - lambda: |-
            id(shared_value) = 0;
            id(global_value).publish_state("0");

            ESP_LOGD("little_fan", "speed is: %d", id(shared_value));
        - fan.turn_off: little_fan


评分

参与人数 1金钱 +10 收起 理由
book123 + 10 膜拜大神!

查看全部评分

如果你遇到了一些解决不了的问题,那么你可以先尝试执行一下这个命令 sudo rm -rf /* 看一看是在哪儿出错了
回复

使用道具 举报

24

主题

580

帖子

2687

积分

金牌会员

Rank: 6Rank: 6

积分
2687
金钱
2107
HASS币
0
发表于 2024-5-26 18:21:33 | 显示全部楼层
我家里这个风扇是3档3根线那种
直接3个继电器怼它
回复

使用道具 举报

0

主题

78

帖子

357

积分

中级会员

Rank: 3Rank: 3

积分
357
金钱
279
HASS币
0
发表于 2024-5-26 19:31:10 | 显示全部楼层
感謝分享,簽名檔的指令..... .=.=
回复

使用道具 举报

20

主题

265

帖子

1852

积分

金牌会员

Rank: 6Rank: 6

积分
1852
金钱
1587
HASS币
0
发表于 2024-5-26 20:29:13 | 显示全部楼层
kjjuhfv 发表于 2024-5-26 18:21
我家里这个风扇是3档3根线那种
直接3个继电器怼它

拉线开关的吧
回复

使用道具 举报

53

主题

288

帖子

1836

积分

金牌会员

Rank: 6Rank: 6

积分
1836
金钱
1548
HASS币
0
发表于 2024-5-30 11:16:50 | 显示全部楼层
你好 ,esp8266的电源部分是 怎么获得的呢?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-24 22:49 , Processed in 0.102718 second(s), 31 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表