You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ESPHome双按钮控制卷帘异常:短按始终触发停止函数排查

ESPHome卷帘按钮逻辑异常问题排查与解决

问题根源

你的代码同时配置了on_click、on_press、on_release三个事件处理,直接导致逻辑冲突:

  • 短按按钮时,on_press会立即触发,先执行cover.open命令,让卷帘进入OPENING运行状态。
  • 随后on_click的lambda函数才执行,此时检测到卷帘处于运行状态,必然进入停止分支,完全偏离预期判断逻辑。
  • 冗余的on_press和on_release属于画蛇添足,直接干扰了on_click的条件判断。

修复方案

移除on_press和on_release代码块,仅保留on_click逻辑即可实现预期功能:

binary_sensor:
  - platform: gpio
    internal: True
    pin:
      number: D1
      inverted: true
      mode:
        input: true
        pullup: true
    name: "Taster UP"
    on_click:
      min_length: 0ms
      max_length: 350ms
      then:
        - lambda: |-
            if((id(template_cover).current_operation == COVER_OPERATION_CLOSING)||(id(template_cover).current_operation == COVER_OPERATION_OPENING))
            {
              auto call1 = id(template_cover).make_call();
              call1.set_command_stop();
              call1.perform();
            }
            else
            {
              auto call1 = id(template_cover).make_call();
              call1.set_command_open();
              call1.perform();
            }

修改后,短按按钮会直接检测卷帘当前状态:若正在运行则停止,否则执行开启操作,完全符合预期逻辑。

内容的提问来源于stack exchange,提问作者Toby_Stoe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 17:46:27