Automation: Trigger duration less than 1s

Hi,

I do have an automationo, whis is based on a sensor that needs about a 0.5s debounce for it to not generate spurious false triggering on other automation.
Currently I have something like that:

trigger:
  - type: opened
    platform: device
    device_id: <something>
    entity_id: <some other thing>
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 1

How can I lower the trigger time to a value lower than 1 second?

Thanks,

Thomas

I have no answer but I do am interested which automation requires this. Can you shed a bit more light on the use case ?

- platform: numeric_state
    entity_id: sensor.ina219_shunt_voltage
    above: "0.3"
    for: "0:00:0.1"

I was able to set to 100 miliseconds

Sorry to repeat myself …learning moment… what / why is the use case? Seeing that HA has challenges in situations with dozens of entities, is HA reliable ?
EDIT: HA issues > environment in which HA runs issues… if HA env. and HA cannot hanlde this frequent changes I mean

Sure.
Mailbox (European style) with two door (magnetic proximity) sensors.
grafik

Automation “New Mail”: magnet stuck on top flap (left side), sensor housing on the left side of the main mailbox body. Triggers whenever the flap opens (magnet moving away from the sensor), AND the door is closed.

Automation “Clear”: Magnet stuck on door (bottom left), with the sensor housing also on the left wall of the left side of the body. Triggers (i.e. clears the “New Mail” flag) when the door opens.
Unfortunately, as the door opens, the magnet from the flap also moves away from the sensor, resulting in a race condition: If the flap sensor triggers before the door sensor, a new trigger of “new mail” is set, even though all of them are cleared immediately as the door opens.

Thats my reason for the 1s debounce, but thats right at the edge what some (“seasoned”) mailmen can drop a letter in the box. So I may miss the new mail trigger.

Hope that clears it up.

Message malformed: expected dict for dictionary value @ data['for']

For:

alias: "Mail: New"
description: Mail flap was opened
trigger:
  - type: opened
    platform: device
    device_id: 59801d45316911757c39b88fd86d8e55
    entity_id: 8555aa2a9e2f132f7ab65b908012ba60
    domain: binary_sensor
    for: "0:00:0.5"
condition:
  - type: is_not_open
    condition: device
    device_id: 7e2331c2fb79feb8306cb72fbee26924
    entity_id: dd3e46122f33bd4fba76b6baeb3f020e
    domain: binary_sensor
action:
  - service: input_boolean.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: input_boolean.mail
  - service: notify.mobile_app_iphone
    metadata: {}
    data:
      message: New Mail
      data:
        tag: new-mail
    enabled: true
  - service: notify.alexa_media_kuche
    data:
      message: Du hast Post
      data:
        type: tts
mode: single

Got it… thanks and this really makes it life-like. As mentioned I have no solution for this setup, beyond my tehc. knowledge. Side info: my mailbox is equiped with a vibration sensor which is usually fine…as long as there is a storm :slight_smile: …about 10 times a year false notif.

delay supports milliseconds:

Try

for: "0.5"

Or

trigger:
  - platform: state
    entity_id:
      - binary_sensor.mailboxwhatever
    for:
      hours: 0
      minutes: 0
      seconds: 0.5
    from: "off"
    to: "on"

Still the same error:

malformed: expected dict for dictionary value @ data['for'] 

That works, but feels like 1s debounce. I think I have to mull the logic over.

I think what you need is to respond immediately, but do not trigger again for at least a second after that. If that is what you need, the simplest solution is: do not use for: and make sure the automation mode is single. then add a delay of one second at the end of the automation.

That way all consecutive triggers within the first second are blocked because the automation is already running. (there are other ways, but this way it can be done without using templates, just using the automation editor).

Have you considered triggering on closing instead? You can use a template condition to make sure the “on” duration was within a range:

{{ timedelta(milliseconds=200) < 
(trigger.to_state.last_changed - trigger.from_state.last_changed) < 
timedelta(milliseconds=600) }}

I think I understand. You don’t want ha to say there is new mail when you open the door to collect mail but opening door sets off the reed switch that indicates there is new mail. What about having a condition that door is closed when mail slot is opened before it will indicate new mail

Correct. I can’t seem to place the sensors in such a way that they fire in the opposite order.

What if when mail sensor fires you set an action to delay 1 second then if door sensor is closed you set that as condition and only then send notification.
Or make automation if door opens it disables mail automation for 30 seconds then turns mail automation back on by which time door is closed.

Completely different solution, but I use a helper to keep track of whether we’ve gotten mail yet for the day and then reset it every night. Keeps it from getting triggered when I actually get the mail as well as wind/weather.

SO here is my solution:
Used a delay in the action part, then a conditional statement and put everything in that if case:

alias: "Mail: New"
description: Mail flap was opened
trigger:
  - type: opened
    platform: device
    device_id: 59801d45316911757c39b88fd86d8e55
    entity_id: 8555aa2a9e2f132f7ab65b908012ba60
    domain: binary_sensor
condition: []
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
    enabled: true
  - if:
      - type: is_not_open
        condition: device
        device_id: 7e2331c2fb79feb8306cb72fbee26924
        entity_id: dd3e46122f33bd4fba76b6baeb3f020e
        domain: binary_sensor
    then:
      - service: input_boolean.turn_on
        metadata: {}
        data: {}
        target:
          entity_id: input_boolean.mail
      - service: notify.mobile_app_iphone
        metadata: {}
        data:
          message: New Mail
          data:
            tag: new-mail
        enabled: true
      - service: notify.persistent_notification
        metadata: {}
        data:
          message: New Mail
        enabled: false
      - service: notify.alexa_media_kuche
        data:
          message: Du hast Post
          data:
            type: tts
    enabled: true
mode: single

The first device is the flap, the second device is the door.
Works like a charm, thanks for all the pointers.

1 Like