1.5 second timer?

Hello All,

My question is there anyway to set a 1.5 second timer? Instead of 00:00:01 can I do 00:00:01:50?

I have an outdoor cat that lives in our garage, but we like to let her out during the day. I currently have an automation that triggers a script at 9am that opens my Garage and starts a 1 second timer. Then a separate automation watching that 1 second timer and when it changes from active to idle it sends a stop command to my garage. This has worked perfect for a long time. However, my naughty cat went and got herself pregnant. As she’s gotten bigger she can’t fit under the space of the garage anymore. I changed the timer to 2 seconds but that leaves it open like a full 12 inches and I don’t want a person slipping in under the garage. My question is there anyway to set a 1.5 second timer? Instead of 00:00:01 can I do 00:00:01:50?

1 Like

The delay service takes milliseconds.

1500ms should work ok. Sub second delays can be affected by how long it takes HA to react though.

You would only need the one automation.
Start your door opening.
Delay 1500ms
Stop your door.

Hey Tom,

Feel like an idiot! Haha that’s exactly what i’m looking for. I’m not sure how to set a delay using the frontend script builder. Any pointers there?

I dont use it.

In yaml it would be specified like this:

delay:
  milliseconds: 1500

So I suspect you want milliseconds: 1500 in the delay field rather than seconds: 1500ms.

So I pulled up the scripts.yaml and i tried a variation of options and couldn’t get anything to work. Finally found that delay: 00:00:01.5 works perfect.

1 Like

Well done. I thought about suggesting decimal seconds (as timestamps use them) but wasn’t sure if it would work.

Just an FYI, the resolution of delays in scripts (or actions of automations) is only one second. I.e., when it gets to a delay step, it will try to “wake up” the amount of time specified later. But the “wake up” only happens once every second. So let’s say you just missed a wake-up time, and you delay 1.5 seconds. That will actually delay 2 seconds, because it will wake up about 1 second later, and it will discover that 1.5 seconds has not gone by. So it will sleep another second, and when it wakes up this time it will see that at least 1.5 seconds has gone by, so the next step of the script/action will run. So in this case the delay was not really 1.5 seconds but (roughly) 2 seconds. Bottom line – if you have a delay step of 1.5 seconds, it will delay at least that much, but it might delay up to 2.5 seconds, depending on where it falls in the one second “wake up” period.

Now the good part is, if the automation or script is started by a timer, it will also be based on the one second resolution, so it should be fairly consistent … until you add more “stuff” and things get delayed a bit, and pow, you miss a window and go another whole second.

BTW, have you ever seen the “Timer got out of sync. Resetting” error message? Yeah, it has to do with this one second scheduling underlying the system timing. That basically means the one second period was blown, and that means that delays can go even longer sometimes than usual.

Hey, this is “just” Python running on a non-real-time OS. You can’t expect very accurate timing control. :slight_smile:

You can fudge it though :slight_smile:

Here’s another idea. Use a python_script. Something like:

hass.services.call('cover', 'open_cover', {'entity_id': 'cover.garage_door'})
end = datetime.datetime.now() + datetime.timedelta(seconds=1.5)
while datetime.datetime.now() < end:
    pass
hass.services.call('cover', 'stop_cover', {'entity_id': 'cover.garage_door'})
2 Likes

THANK YOU!!
This error has been irritating me forever. I can live quite contently with it now I understand it!!

THIS ^^^ is awesome! :smiley: