cancel
Showing results for 
Search instead for 
Did you mean: 

openClose door sensor automation not always executed

Leonardo-R
Community Member

I have a scripted automation updating an helper sensor accordingly to the status openClose on some contact physical sensor. The automation looks like this:

metadata:
  name: Porta ingresso handler
  description: Scripted automation

automations:
  - starters:
      - type: device.state.OpenClose
        state: openPercent
        is: 100
        device: Porta Ingresso - Ingresso

    actions:
      - type: device.command.OnOff
        on: true
        devices: Sensore porta ingresso - Ingresso

  - starters:
      - type: device.state.OpenClose
        state: openPercent
        is: 0
        device: Porta Ingresso - Ingresso

    actions:
      - type: device.command.OnOff
        on: false
        devices: Sensore porta ingresso - Ingresso

 

The problem is that often, when the door is opened and closed quickly, the physical sensor switch back to closed as normal but the helper sensor does not get updated resulting in the helper remaining true even if the door is actually closed.

I would really appreciate any help.

2 REPLIES 2

iqbal1
Community Member

It is likely due to your automation not catching those rapid state changes. When the door opens and closes in quick succession, the physical sensor might correctly switch states, but the automation might not execute fast enough to keep up, resulting in the helper sensor getting stuck in an incorrect state (often remaining "on" even when the door is actually closed).

 

To fix this, you can introduce a delay condition in your automation logic. This ensures that the door must stay in the "open" or "closed" state for a few seconds before the automation reacts. For example, you can require the door to remain open or closed for at least 5 seconds before updating the helper sensor. This prevents brief, unintended or transient state changes from triggering your actions. In YAML, this is done by adding a for: 5s parameter to the starters block, so the system only runs the command if the door remains in that state for a full 5 seconds.

 

If your automation platform doesn’t support using for directly in the trigger, you can instead introduce a short delay within the action block itself. This way, after the door changes state, the automation waits a few seconds before updating the helper sensor. During that wait, if the door changes back, the action will not execute, effectively filtering out quick toggles.

 

Lastly, make sure all devices involved are reliably connected and responsive. Missed or delayed automation steps can also happen due to network lags or hardware performance issues. Checking logs or event history might help identify if the automation is even firing when expected.

Hi @iqbal1 thanks for your reply.

I already tried using a "for: 5sec" into che close starter. I thought that if the automation would for the door to be closed fro 5 seconds this would do the trick. Unfortunately with no luck. I'll try to use 1 min delay for the closing starter even if it seems that closing the door to quickly will stop the script execution no matter what.

what do you think?