Is the switch state of the home assistant connected to the esphone out of sync?

Is the switch state of the home assistant connected to the esphone out of sync?


These switches are interlocked

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: "拉杆已拉到位"

It shouldn’t be. Are you using mqtt or the api? And what do the logs tell you/us?

API connected. The API log shows that the switch has been turned off by the service. But the switch is still on in the homeassistant

It is found that it is not an interlock problem, but a script component problem.

With the script off switch, out-of-sync and no off will appear in Home Assistant.

It’s finally settled.

The original switch automation can’t be turned off immediately. If it is turned off immediately, it will cause switch failure in hass and can’t be controlled.

Just add a judgment delay script.

script:
##检测并关闭上升##;      
  - id: off_sang  
    mode: restart
    then:
      - if:
          condition:
              - switch.is_on: sang  ##检测上升是否开启##;
          then:
              - delay: 101ms
              - logger.log: "off_sang:关闭上升。"
              - switch.turn_off: sang