Set it as the homepageBookmark this site

简体中文 繁體中文 English 日本語 Deutsch 한국 사람 بالعربية TÜRKÇE português คนไทย

 Retrieve your password
 Sign up now
img_loading
Intelligent detection

QQ login

Just one step, get started quickly

Search
Ad delivery contact QQ68610888Ad delivery contact QQ68610888
查看: 3341|回复: 5

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

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

一. 硬件
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.                                                         /*添加识别码,用户修改*/
复制代码

本帖子中包含更多资源

您需要 login 才可以下载或查看,没有账号?Sign up now

×
Only talk about technology, don't talk about politics! (Click for details) | Enshan Wireless Forum welcomes your visit, please respect each other, friendly exchanges, it is recommended to keep a normal mind to look at the comments of netizens, do not overreact.
 楼主| 发表于 2025-2-11 17:01 | Show all floors
原帖HomeAssiatant ESPHome 使用ESP8266控制晾衣架升降-CSDN博客
发个帖子留个档 第一次发 不小心还没编辑完就发出去了
Only talk about technology, don't talk about politics! (Click for details) | Enshan Wireless Forum welcomes your visit, please respect each other, friendly exchanges, it is recommended to keep a normal mind to look at the comments of netizens, do not overreact.
发表于 2025-2-12 10:40 | Show all floors
膜拜大佬。。。。
Only talk about technology, don't talk about politics! (Click for details) | Enshan Wireless Forum welcomes your visit, please respect each other, friendly exchanges, it is recommended to keep a normal mind to look at the comments of netizens, do not overreact.
发表于 2025-4-16 21:20 | Show all floors
大佬,内部接线怎么接?家里也买了个只有遥控没有联网的
Only talk about technology, don't talk about politics! (Click for details) | Enshan Wireless Forum welcomes your visit, please respect each other, friendly exchanges, it is recommended to keep a normal mind to look at the comments of netizens, do not overreact.
发表于 2025-6-12 20:25 | Show all floors
这个牛。。。
Only talk about technology, don't talk about politics! (Click for details) | Enshan Wireless Forum welcomes your visit, please respect each other, friendly exchanges, it is recommended to keep a normal mind to look at the comments of netizens, do not overreact.
发表于 2025-6-19 09:06 | Show all floors
mark下,将来好好研究下。
Only talk about technology, don't talk about politics! (Click for details) | Enshan Wireless Forum welcomes your visit, please respect each other, friendly exchanges, it is recommended to keep a normal mind to look at the comments of netizens, do not overreact.
You'll need to be logged in to reply to posts login | Sign up now

This version of the points rules

Shut down

Welcome to the Enshan Wireless Forum

Only talk about technology, don't talk about politics! Don't spread rumors! For you and for others.
Only talk about technology, don't talk about politics! (Click for details) Remember not to spread rumors at will, just live your life in peace, for your own good and for the good of everyone. Enshan Wireless Forum welcomes your visit, please respect each other, friendly exchanges, it is recommended to keep a normal mind to look at the comments of netizens, do not overreact.

View »

If in doubt, add an administrator QQ86788181|Mobile version|Little dark house|Archiver|Enshan Wireless Forum (Changzhou Enshan Computer Development Co., Ltd. All rights reserved) ( Su ICP No. 05084872 )

GMT+8, 2025-6-26 11:29

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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

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