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

 找回密码
 立即注册
查看: 1002|回复: 3

[技术探讨] esphome接入Home Assistant

[复制链接]

7

主题

110

帖子

836

积分

论坛DIY达人

积分
836
金钱
721
HASS币
20
发表于 2023-2-10 19:01:29 | 显示全部楼层 |阅读模式
esphome接入Home Assistant开关状态不同步?
QQ截图20230207211528.png
在代码中这几个开关是互锁的。哪位大神指点一下
switch:
##卷扬机继电器;
  - platform: gpio
    pin: GPIO25
    name: "3.1${sbm}_上"
    id: sang
    interlock: [xia,tui,la] ##互锁;
#    interlock_wait_time: 500ms
    restore_mode: ALWAYS_OFF  ##上电时默认关闭;
  - platform: gpio
    pin: GPIO26
    name: "3.2.${sbm}_下"
    id: xia
    interlock: [sang,tui,la] ##互锁;
#    interlock_wait_time: 500ms
    restore_mode: ALWAYS_OFF  ##上电时默认关闭; 
    on_turn_on:  ##开启时启动脚本;
     then:
      - script.execute: on_lagan
      - script.execute: w_xiajiang 
      - script.execute: n_xiajiang 
    on_turn_off: ##关闭时,结束脚本;
     then:
      - script.stop: x_x  
##电动拉杆继电器;
  - platform: gpio
    pin: GPIO32
    name: "3.3.${sbm}_推"
    id: tui
    interlock: [la,sang,xia] ##连锁拉回;
#    interlock_wait_time: 500ms
    restore_mode: ALWAYS_OFF  ##上电时默认关闭。
    on_turn_on: 
      then:
      - wait_until:
         -  binary_sensor.is_on: lagan_w  ##检测拉杆推到位##;
      - switch.turn_off: tui
      - logger.log: "拉杆已推到位"      
  - platform: gpio
    pin: GPIO33
    name: "3.4.${sbm}_拉"
    id: la
    interlock: [tui,sang,xia] ##连锁推出;
#    interlock_wait_time: 500ms
    restore_mode: ALWAYS_OFF  ##上电时默认关闭。
    on_turn_on:
      then: 
      - wait_until:
         -  binary_sensor.is_on: lagan_n  ##检测拉杆拉到位##;
      - switch.turn_off: la
      - logger.log: "拉杆已拉到位"  


回复

使用道具 举报

43

主题

1353

帖子

5617

积分

论坛元老

Rank: 8Rank: 8

积分
5617
金钱
4254
HASS币
40
发表于 2023-2-10 22:59:36 | 显示全部楼层
互锁建议使用硬锁
折腾精神永存,感恩感谢论坛每一位愿意分享和帮助过我的大佬,论坛有你更精彩
回复

使用道具 举报

7

主题

110

帖子

836

积分

论坛DIY达人

积分
836
金钱
721
HASS币
20
 楼主| 发表于 2023-2-11 08:38:16 | 显示全部楼层
jjcs 发表于 2023-2-10 22:59
互锁建议使用硬锁

硬锁也是有的,现在的问题是ha上面的开关状态与实际不同步
回复

使用道具 举报

7

主题

110

帖子

836

积分

论坛DIY达人

积分
836
金钱
721
HASS币
20
 楼主| 发表于 2023-2-14 11:02:08 | 显示全部楼层
本帖最后由 cmsj 于 2023-2-14 11:04 编辑

终于搞定了。
原来开关自动化不能马上关闭本身,马上关闭本身就在hass中会出现开关失灵,不能控制。
加了个判断延时脚本,就好了。
script:
##检测并关闭上升##;      
  - id: off_sang  
    mode: restart
    then:
      - if:
          condition:
              - switch.is_on: sang  ##检测上升是否开启##;
          then:
              - delay: 101ms
              - logger.log: "off_sang:关闭上升。"
              - switch.turn_off: sang 


回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-5-19 17:02 , Processed in 0.787621 second(s), 28 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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