Very short delay values in a script

I’ve wired up a relay circuit and a magnetic reed switch to my RPi3 running Hassbian (0.49). My intent is to wire the relay output to the garage door opener button to simulate a button push on the opener so I can create automations to close the garage door when left open for too long.

I have all that wiring and logic worked out, but I’m having an issue with the trigger sequence.

switch:

  • platform: rpi_gpio
    ports:
    18: Garage Door
    invert_logic: true
  • script:
  • triggergarage:
    alias: Trigger Garage Door Relay
    sequence:
    • service: switch.turn_on
      entity_id: switch.garage_door
    • delay:
      seconds: 0.5
    • service: switch.turn_off
      entity_id: switch.garage_door

The seconds: [delay] needs to be less than a second or else the opener misinterprets the signal and stops the door. However, in testing this the sequence seems to pause a random amount between .1 and 1 second, almost like it merely sets a delay until the next second on the clock rather than actually ticking off 500 miliseconds.

Is there another way I could do this?

Thanks in advance.

Have you tried use milliseconds instead?

Okay, duh. Thanks. It still isn’t terribly consistent, but I think it’ll be good enough.

-Andrew