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

 找回密码
 立即注册
查看: 1165|回复: 10

通过编码器控制老吊扇,控制三挡

[复制链接]

37

主题

266

帖子

2135

积分

论坛DIY达人

积分
2135
金钱
1869
HASS币
20
发表于 2023-6-1 13:57:14 | 显示全部楼层 |阅读模式
本帖最后由 shadowba 于 2023-6-1 21:46 编辑

一直想把老吊扇拆了,老婆大人不同意,说最实用的就是它,夏天用风很大,很凉快。算了改造一下吧!1.材料,旋转编码器一个,四联继电器模块,8266.吊扇调速电容
微信图片_20230601135142.png
微信图片_20230601135137.png
用旋转编码器替换波段开关,需要电路基础
WechatIMG27.jpeg



2.实现功能,小爱接入,三挡调速,多余的引脚顺便控制了灯

微信图片_20230601135203.png
3.代码如下:
esphome:
  name: living-room
  friendly_name: living-room

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:


ota:
  password: "0000000000000"

wifi:
  ssid: 0000000000000
  password: 000000000000

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "living_room Fallback Hotspot"
    password: "0000000000000"

captive_portal:



web_server:
  port: 80 # web端口

binary_sensor:
  # 继电器高档二进制取反
  - platform: template
    id: sw3
    lambda: |-
      if (id(relay3).state) {
        return false;
      } else {
        return true;
      }
 # 继电器中档二进制取反
  - platform: template
    id: sw2
    lambda: |-
      if (id(relay2).state) {
        return false;
      } else {
        return true;
      }
  # 开关机、调速
  - platform: gpio
    id: btnpower
    #是否对外隐藏(true/false)
    #internal: true
    pin:
      number: GPIO13
      mode: INPUT_PULLUP
    # on_press:
    #   - switch.toggle: switch0
    filters:
      - invert:
      - delayed_on_off: 40ms
    on_press:
        then:
          - switch.toggle: switch0
  - platform: gpio
    id: btnoff
    #是否对外隐藏(true/false)
    internal: true
    pin:
      number: GPIO14
      mode: INPUT_PULLUP
    # on_press:
    #   - switch.toggle: switch1
    filters:
      - invert:
      - delayed_on_off: 100ms
    on_press:
      - switch.toggle: switch1
  - platform: gpio
    pin:
      number: GPIO0
      mode:
        input: true
        pullup: true
      inverted: true
    name: yiya_light
    on_press:
      - switch.toggle: relay4

switch:
  - platform: template
    name: "fan_H"
    id: relayH
    icon: "mdi:fan-speed-3"
    lambda: |-
      if (id(relay1).state && id(relay2).state && id(relay3).state) {
        return true;
      } else {
        return false;
      }
    turn_on_action:
      - switch.turn_on: relay1
      - switch.turn_on: relay2
      - switch.turn_on: relay3   
    turn_off_action:  
      - switch.turn_off: relay1
      - switch.turn_off: relay2
      - switch.turn_off: relay3      
  - platform: template
    name: "fan_M"
    id: relayM
    icon: "mdi:fan-speed-2"
    lambda: |-
      if (id(relay1).state && id(relay2).state && id(sw3).state) {
        return true;
      } else {
        return false;
      }
    turn_on_action:
      - switch.turn_on: relay1
      - switch.turn_on: relay2
      - switch.turn_off: relay3   
    turn_off_action:
      - switch.turn_off: relay1
      - switch.turn_off: relay2   
      - switch.turn_off: relay3  
  - platform: template
    name: "fan_L"
    id: relayL
    icon: "mdi:fan-speed-1"
    lambda: |-
      if (id(relay1).state && id(sw2).state && id(sw3).state) {
        return true;
      } else {
        return false;
      }
    turn_on_action:
      - switch.turn_off: relay2
      - switch.turn_off: relay3
      - switch.turn_on: relay1

    turn_off_action:
      - switch.turn_off: relay1
  - platform: template
    name: "fan_on"
    id: switch0
    icon: "mdi:ceiling-fan"
    turn_on_action:
      then:
       - if:
          condition:
            and:
             - switch.is_off: relay1
             - switch.is_off: relay2
             - switch.is_off: relay3 
          then:
           - switch.turn_on: relay1
          else:
            - if:
                condition:
                  and:
                   - switch.is_on: relay1
                   - switch.is_off: relay2
                   - switch.is_off: relay3
                then:
                   - switch.turn_on: relay2
                else:
                 - if:
                    condition:
                      and:
                       - switch.is_on: relay1
                       - switch.is_on: relay2
                       - switch.is_off: relay3
                    then:
                     - switch.turn_on: relay3
                    else:
                      - if:
                         condition:
                            and:
                             - switch.is_on: relay1
                             - switch.is_on: relay2
                             - switch.is_on: relay3 
                         then:
                           - switch.turn_off: relay1
                           - switch.turn_off: relay2
                           - switch.turn_off: relay3
  - platform: template
    #全部关闭 
    name: "fan_off"
    #output: realy0
    id: switch1
    icon: "mdi:fan-off"
    turn_on_action:
      - lambda: |-
            id(relay2).turn_off();
            id(relay3).turn_off();
            id(relay1).turn_off();
    turn_off_action:
      - lambda: |-
            id(relay2).turn_off();
            id(relay3).turn_off();
            id(relay1).turn_off();
  - platform: gpio
    name: "fan_H_relay"
    pin: 5
    id: relay3
    icon: "mdi:fan"
    restore_mode: ALWAYS_OFF

  - platform: gpio
    name: "fan_M_relay"
    pin: 4
    id: relay2
    icon: "mdi:fan"
    restore_mode: ALWAYS_OFF

  - platform: gpio
    name: "fan_L_relay"
    pin: 15
    id: relay1
    icon: "mdi:fan"
    restore_mode: ALWAYS_OFF

  - platform: gpio 
    name: "living_room_light"
    pin: 12
    id: relay4
    icon: "mdi:wall-sconce-flat"
    restore_mode: ALWAYS_OFF     
  - platform: restart
    name: "living_Restart"






评分

参与人数 1金钱 +8 收起 理由
kaka0992 + 8 论坛有你更精彩!

查看全部评分

回复

使用道具 举报

0

主题

562

帖子

2183

积分

金牌会员

Rank: 6Rank: 6

积分
2183
金钱
1621
HASS币
0
发表于 2023-6-1 14:12:44 | 显示全部楼层
大佬的都是实用性diy,准备多多学习
回复

使用道具 举报

11

主题

222

帖子

2197

积分

论坛DIY达人

积分
2197
金钱
1965
HASS币
40
发表于 2023-6-1 15:09:15 | 显示全部楼层
这就是个旋转的档位开关啊,不是编码器啊
回复

使用道具 举报

11

主题

222

帖子

2197

积分

论坛DIY达人

积分
2197
金钱
1965
HASS币
40
发表于 2023-6-1 15:10:52 | 显示全部楼层
花落花空 发表于 2023-6-1 15:09
这就是个旋转的档位开关啊,不是编码器啊

yaml里没看见编码器部分啊
回复

使用道具 举报

37

主题

266

帖子

2135

积分

论坛DIY达人

积分
2135
金钱
1869
HASS币
20
 楼主| 发表于 2023-6-1 15:35:03 | 显示全部楼层
花落花空 发表于 2023-6-1 15:09
这就是个旋转的档位开关啊,不是编码器啊

没错,就是利用了编码器的开关特性
回复

使用道具 举报

16

主题

216

帖子

1488

积分

金牌会员

Rank: 6Rank: 6

积分
1488
金钱
1272
HASS币
0
发表于 2023-6-1 16:14:03 | 显示全部楼层
LZ连发很多干货
回复

使用道具 举报

37

主题

266

帖子

2135

积分

论坛DIY达人

积分
2135
金钱
1869
HASS币
20
 楼主| 发表于 2023-6-1 21:50:44 | 显示全部楼层

就是业余爱好,希望对大家有帮助
回复

使用道具 举报

47

主题

702

帖子

4470

积分

元老级技术达人

积分
4470
金钱
3768
HASS币
50
QQ
发表于 2023-6-14 15:14:06 | 显示全部楼层
为什么不是pwm
如果你遇到了一些解决不了的问题,那么你可以先尝试执行一下这个命令 sudo rm -rf /* 看一看是在哪儿出错了
回复

使用道具 举报

37

主题

266

帖子

2135

积分

论坛DIY达人

积分
2135
金钱
1869
HASS币
20
 楼主| 发表于 2023-6-14 16:36:11 | 显示全部楼层

交流风扇,适配的pwm模块有点小贵
回复

使用道具 举报

50

主题

1300

帖子

4890

积分

论坛DIY达人

积分
4890
金钱
3590
HASS币
20
发表于 2023-6-15 14:03:37 | 显示全部楼层
shadowba 发表于 2023-6-14 16:36
交流风扇,适配的pwm模块有点小贵

ESPHome不是可控硅调速组件吗?可控硅不贵呀!
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-4-26 19:50 , Processed in 0.135987 second(s), 36 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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