找回密码
 立即注册
img_loading
智能检测中

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888广告投放联系QQ68610888
查看: 2901|回复: 4

HomeAssiatant ESPHome 使用ESP8266控制晾衣架升降

[复制链接]
发表于 2025-2-11 16:59 | 显示全部楼层 |阅读模式
家人买了个电动晾衣架,遥控的,按理来说是能直接接入米家的,没想到是阉割版的,遥控模具有配对按钮,但是电路板没有对应原件,每次都要拿遥控按不方便,于是打算加一个语音控制。

一. 硬件
1. ESP8266
2. LD3320语音识别模块
3. 射频发射和接收模块
4.逻辑分析仪

二. 软件
1.esp8266接入esphome

用homeassistant的su或者os版本才有加载项,在docker版没有,不能编译

2.逻辑分析仪捕获



3.esp8266代码

  1. esphome:
  2.   name: esp80266
  3.   friendly_name: esp80266

  4. esp8266:
  5.   board: esp01_1m

  6. external_components:
  7.   - source:
  8.       type: git
  9.       url: https://github.com/esphome/esphome.git
  10.       ref: main
  11.     components: [uart]

  12. # Enable logging
  13. logger:
  14.   baud_rate: 0  # 将串口日志波特率设置为 0,禁用串口日志输出
  15.   #level: INFO  # 设置日志级别,可根据需要调整
  16. # Enable Home Assistant API
  17. api:
  18.   encryption:
  19.     key: "t0Gm/4xUrwPvx36RUgT3Xh8YkXP81YLY9LDwLg0kd0k="

  20. ota:
  21.   - platform: esphome
  22.     password: "123456"

  23. wifi:
  24.   ssid: "XXX"
  25.   password: "12345678"

  26.   # Enable fallback hotspot (captive portal) in case wifi connection fails
  27.   ap:
  28.     ssid: "Esp80266 Fallback Hotspot"
  29.     password: "88888888"




  30.       
  31. uart:
  32.   tx_pin: 5  # 根据实际连接修改TX引脚
  33.   rx_pin: 4  # 根据实际连接修改RX引脚
  34.   baud_rate: 9600  # 波特率,需与单片机设置一致
  35.   debug:
  36.     direction: RX
  37.     dummy_receiver: true
  38.     after:
  39.       delimiter: "\r\n"
  40.     sequence:
  41.       - lambda: |-
  42.           // 将接收到的字节数据转换为字符串
  43.           std::string str(bytes.begin(), bytes.end());
  44.           if (str.compare("A1\r\n") == 0) {
  45.               id(oled_display).fill(COLOR_OFF);
  46.               id(display_text).publish_state("打开 L5");
  47.               id(switch_l3).turn_on();
  48.               id(switch_l3l2).execute();
  49.           } else if (str.compare("A2\r\n") == 0) {
  50.               id(oled_display).fill(COLOR_OFF);
  51.               id(display_text).publish_state("关闭 L1");
  52.               id(switch_l1).turn_on();
  53.           } else if (str.compare("A3\r\n") == 0) {
  54.               id(oled_display).fill(COLOR_OFF);
  55.               id(display_text).publish_state("照明 L4");
  56.               id(switch_l4).turn_on();
  57.           } else if (str.compare("A4\r\n") == 0) {
  58.               id(oled_display).fill(COLOR_OFF);
  59.               id(display_text).publish_state("收衣服 A4");
  60.               id(switch_l4).turn_on();
  61.               id(switch_l4r4l3r3l2r2).execute();
  62.           } else if (str.compare("A5\r\n") == 0) {
  63.               id(oled_display).fill(COLOR_OFF);
  64.               id(display_text).publish_state("收起来 A5");
  65.               id(switch_l1).turn_on();
  66.               id(switch_l1r1l4r4).execute();
  67.           } else if (str.compare("A6\r\n") == 0) {
  68.               id(oled_display).fill(COLOR_OFF);
  69.               id(display_text).publish_state("照明 L4a");
  70.               id(switch_l4).turn_on();
  71.           }
  72. remote_transmitter:
  73.   pin: 2
  74.   carrier_duty_percent: 100%


  75. # 配置 I2C 总线,用于连接 OLED 屏幕
  76. i2c:
  77.   sda: 14
  78.   scl: 12
  79.   scan: true

  80. # 配置 OLED 显示
  81. display:
  82.   - platform: ssd1306_i2c
  83.     model: "SSD1306 128x64"
  84.     address: 0x3C
  85.     id: oled_display
  86.     #update_interval: 10ms  # 缩短更新间隔,提高实时性
  87.     lambda: |-
  88.       it.fill(COLOR_OFF);
  89.       it.print(15, 15, id(my_font), id(display_text).state.c_str());

  90. # 配置字体
  91. font:
  92.   - file: "SIMHEI.TTF" # 用SSH访问esphome 可以直接把电脑的字体拖进去用
  93.     id: my_font
  94.     size: 25
  95.     glyphs: [打开关闭晾衣服收起来上升停止下降照明调试1234567890LRA,"\u0020"]

  96. text_sensor:
  97.   - platform: template
  98.     name: "Display Text"
  99.     id: display_text
  100.    
  101. script:
  102.   - id: switch_l1r1
  103.     then:
  104.       - delay: 500ms
  105.       - lambda: |-
  106.           id(switch_r1).turn_on();
  107.   - id: switch_l2r2
  108.     then:
  109.       - delay: 500ms
  110.       - lambda: |-
  111.           id(switch_r2).turn_on();
  112.   - id: switch_l3r3
  113.     then:
  114.       - delay: 500ms
  115.       - lambda: |-
  116.           id(switch_r3).turn_on();
  117.   - id: switch_l4r4
  118.     then:
  119.       - delay: 500ms
  120.       - lambda: |-
  121.           id(switch_r4).turn_on();

  122.   - id: switch_l3l2
  123.     then:
  124.       - delay: 13000ms
  125.       - lambda: |-
  126.           id(switch_l2).turn_on();
  127.   - id: switch_r3r2
  128.     then:
  129.       - delay: 13000ms
  130.       - lambda: |-
  131.           id(switch_r2).turn_on();

  132.   - id: switch_l3r3l2r2
  133.     then:
  134.       - delay: 500ms
  135.       - lambda: |-
  136.           id(switch_r3).turn_on();
  137.       - delay: 13000ms  
  138.       - lambda: |-
  139.           id(switch_l2).turn_on();
  140.       - delay: 500ms
  141.       - lambda: |-
  142.           id(switch_r2).turn_on();

  143.   - id: switch_l4r4l3r3l2r2
  144.     then:
  145.       - delay: 500ms
  146.       - lambda: |-
  147.           id(switch_r4).turn_on();
  148.       - delay: 500ms
  149.       - lambda: |-
  150.           id(switch_l3).turn_on();
  151.       - delay: 500ms  
  152.       - lambda: |-
  153.           id(switch_r3).turn_on();
  154.       - delay: 13000ms  
  155.       - lambda: |-
  156.           id(switch_l2).turn_on();
  157.       - delay: 500ms
  158.       - lambda: |-
  159.           id(switch_r2).turn_on();

  160.   - id: switch_l1r1l4r4
  161.     then:
  162.       - delay: 500ms
  163.       - lambda: |-
  164.           id(switch_r1).turn_on();
  165.       - delay: 500ms
  166.       - lambda: |-
  167.           id(switch_l4).turn_on();
  168.       - delay: 500ms
  169.       - lambda: |-
  170.           id(switch_r4).turn_on();

  171. switch:
  172.   - platform: template
  173.     name: "Send Data"
  174.     id: send_data
  175.     turn_on_action:
  176.       - uart.write: "Hello, Serial Device!\n"

  177.   - platform: template
  178.     name: Right Pole up
  179.     id: switch_r1
  180.     turn_on_action:
  181.       - remote_transmitter.transmit_rc_switch_raw:
  182.           code: '0100111000100110001100000000000000010001'
  183.           protocol:
  184.             pulse_length: 350
  185.             sync: [14, 4]
  186.             zero: [1, 2]
  187.             one: [2, 1]
  188.           repeat:
  189.             times: 5
  190.             wait_time: 7500us
  191.   - platform: template
  192.     name: Right Pole Stop
  193.     id: switch_r2
  194.     turn_on_action:
  195.       - remote_transmitter.transmit_rc_switch_raw:
  196.           code: '0100111000100110001100000000000001010101'
  197.           protocol:
  198.             pulse_length: 350
  199.             sync: [14, 4]
  200.             zero: [1, 2]
  201.             one: [2, 1]
  202.           repeat:
  203.             times: 5
  204.             wait_time: 7500us
  205.   - platform: template
  206.     name: Right Pole down
  207.     id: switch_r3
  208.     turn_on_action:
  209.       - remote_transmitter.transmit_rc_switch_raw:
  210.           code: '0100111000100110001100000000000000110011'
  211.           protocol:
  212.             pulse_length: 350
  213.             sync: [14, 4]
  214.             zero: [1, 2]
  215.             one: [2, 1]
  216.           repeat:
  217.             times: 5
  218.             wait_time: 7500us
  219.   - platform: template
  220.     name: Right Light
  221.     id: switch_r4
  222.     turn_on_action:
  223.       - remote_transmitter.transmit_rc_switch_raw:
  224.           code: '0100111000100110001100000000000000001111'   
  225.           protocol:
  226.             pulse_length: 350
  227.             sync: [14, 4]
  228.             zero: [1, 2]
  229.             one: [2, 1]
  230.           repeat:
  231.             times: 5
  232.             wait_time: 7500us
  233.   - platform: template
  234.     name: Left Pole up
  235.     id: switch_l1
  236.     turn_on_action:
  237.       - remote_transmitter.transmit_rc_switch_raw:
  238.           code: '1101110110001110000100100000000000010001'
  239.           protocol:
  240.             pulse_length: 350
  241.             sync: [14, 4]
  242.             zero: [1, 2]
  243.             one: [2, 1]
  244.           repeat:
  245.             times: 5
  246.             wait_time: 7500us
  247.   - platform: template
  248.     name: Left Pole Stop
  249.     id: switch_l2
  250.     turn_on_action:
  251.       - remote_transmitter.transmit_rc_switch_raw:
  252.           code: '1101110110001110000100100000000001010101'
  253.           protocol:
  254.             pulse_length: 350
  255.             sync: [14, 4]
  256.             zero: [1, 2]
  257.             one: [2, 1]
  258.           repeat:
  259.             times: 5
  260.             wait_time: 7500us
  261.   - platform: template
  262.     name: Left Pole down
  263.     id: switch_l3
  264.     turn_on_action:
  265.       - remote_transmitter.transmit_rc_switch_raw:
  266.           code: '1101110110001110000100100000000000110011'
  267.           protocol:
  268.             pulse_length: 350
  269.             sync: [14, 4]
  270.             zero: [1, 2]
  271.             one: [2, 1]
  272.           repeat:
  273.             times: 5
  274.             wait_time: 7500us
  275.   - platform: template
  276.     name: Left Light
  277.     id: switch_l4
  278.     turn_on_action:
  279.       - remote_transmitter.transmit_rc_switch_raw:
  280.           code: '1101110110001110000100100000000000001111'   
  281.           protocol:
  282.             pulse_length: 350
  283.             sync: [14, 4]
  284.             zero: [1, 2]
  285.             one: [2, 1]
  286.           repeat:
  287.             times: 5
  288.             wait_time: 7500us
复制代码

4.单片机部分代码
  1. void User_handle(uint8 dat)

  2. {

  3.     if (dat >= BTN_1_CODE && dat <= BTN_6_CODE)

  4.     {

  5.         // 根据 dat 的值直接输出对应的字符串

  6.         switch (dat)

  7.         {

  8.             case BTN_1_CODE:

  9.                 PrintCom("A1\r\n");

  10.                 break;

  11.             case BTN_2_CODE:

  12.                 PrintCom("A2\r\n");

  13.                 break;

  14.             case BTN_3_CODE:

  15.                 PrintCom("A3\r\n");

  16.                 break;

  17.             case BTN_4_CODE:

  18.                 PrintCom("A4\r\n");

  19.                 break;

  20.             case BTN_5_CODE:

  21.                 PrintCom("A5\r\n");

  22.                 break;

  23.             case BTN_6_CODE:

  24.                 PrintCom("A6\r\n");

  25.                 break;

  26.         }

  27.     }

  28.     else

  29.     {

  30.         // 其他无效指令的处理

  31.         // PrintCom("无效指令\r\n");

  32.     }

  33. }

  34. ```



  35. ```c

  36. uint8 code sRecog[DATE_A][DATE_B] = {

  37.                                                                         "da kai",\

  38.                                                                         "guan bi",\

  39.                                                                         "zhao ming",\

  40.                                                                         "shou yi fu",\

  41.                                                                         "shou qi lai",\

  42.                                                                         "kai deng"

  43.                                                                         };       

  44.                                                                         //打开

  45.                                                                         //关闭

  46.                                                                         //照明

  47.                                                                         //收衣服

  48.                                                                         //收起来

  49.                                                                         //开灯

  50. uint8 code pCode[DATE_A] = {

  51.                                                         BTN_1_CODE,\

  52.                                                         BTN_2_CODE,\

  53.                                                         BTN_3_CODE,\

  54.                                                         BTN_4_CODE,\

  55.                                                         BTN_5_CODE,\

  56.                                                         BTN_6_CODE};       

  57.                                                         /*添加识别码,用户修改*/
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
只谈技术、莫论政事!(点击见详情) | 恩山无线论坛欢迎您的来访,请互相尊重、友善交流,建议保持一颗平常心看待网友的评论,切勿过度反应。
 楼主| 发表于 2025-2-11 17:01 | 显示全部楼层
原帖HomeAssiatant ESPHome 使用ESP8266控制晾衣架升降-CSDN博客
发个帖子留个档 第一次发 不小心还没编辑完就发出去了
只谈技术、莫论政事!(点击见详情) | 恩山无线论坛欢迎您的来访,请互相尊重、友善交流,建议保持一颗平常心看待网友的评论,切勿过度反应。
回复 支持 反对

使用道具 举报

发表于 2025-2-12 10:40 | 显示全部楼层
膜拜大佬。。。。
只谈技术、莫论政事!(点击见详情) | 恩山无线论坛欢迎您的来访,请互相尊重、友善交流,建议保持一颗平常心看待网友的评论,切勿过度反应。
回复 支持 反对

使用道具 举报

发表于 2025-4-16 21:20 | 显示全部楼层
大佬,内部接线怎么接?家里也买了个只有遥控没有联网的
只谈技术、莫论政事!(点击见详情) | 恩山无线论坛欢迎您的来访,请互相尊重、友善交流,建议保持一颗平常心看待网友的评论,切勿过度反应。
回复 支持 反对

使用道具 举报

发表于 2025-6-12 20:25 | 显示全部楼层
这个牛。。。
只谈技术、莫论政事!(点击见详情) | 恩山无线论坛欢迎您的来访,请互相尊重、友善交流,建议保持一颗平常心看待网友的评论,切勿过度反应。
回复 支持 反对

使用道具 举报

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

本版积分规则

关闭

欢迎大家光临恩山无线论坛

只谈技术、莫论政事!切勿转播谣言!为了你也为了他人。
只谈技术、莫论政事!(点击见详情) 切记不要随意传播谣言,把自己的日子过安稳了就行,为了自己好也为了大家好。 恩山无线论坛欢迎您的来访,请互相尊重、友善交流,建议保持一颗平常心看待网友的评论,切勿过度反应。

查看 »

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2025-6-13 02:51

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com

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