Can you please format the code section of your post so that the indentations are displayed properly.
Makes it much easier for anybody to help and takes a lot of guesswork out of possible suggestions.
So I’m pretty sure the example in the documents is 90% complete and avoids an issue that may or may not be required.
The typicaly format for time based entries is xx:xx:xx. I’m not sure if it will accept xx:x:xx, I don’t believe it does but I could be wrong. Anyways, to account for that:
- delay: "{{ '00:%02i:00'%range(01,20) | random }}"
This could not be related to your issue, and it could not be a problem at all but it may be worth a shot to update.
Also, for testing purposes, you may want to decrease your time range because you could be waiting upwards of 20 minutes for the action to fire based on the random delay being between 1 minute and 20 minutes.
This allows random delays from seconds to hours. Just replace the first parameter to range with the lowest number of seconds, and the second parameter with the highest number of seconds + 1.
EDIT: Well, I’ve learned a lot since I posted the above! Currently I’d recommend:
- delay: "{{ range(0, 20*60+1)|random }}"
The delay action accepts a time period specified in any of these formats:
The last form allows any or all of those components, and all forms accept templates. And, FWIW, I’m actually right now working on a PR that makes it accept fractional values (such as “delay: 0.5”) as well (except for HH & MM.)
Noob here having a similar issue. Anyone spot the config error? My kitchen lights and study switch come on just fine, but anything after the first delay never happens. Have set to 1-2 mins for testing purposes.
You’re using the wrong kind of quote characters. Also, range(1, 2) always returns 1. (The range starts with the first argument, and ends with one less than the second argument.) Oh, and the |int and outside parentheses aren’t needed in this case. Try:
- delay: '00:{{ range(1, 3)|random) }}:00'
EDIT: I should also add, this will delay either 1 or 2 minutes. If you want it to range between 1 and 2 minutes, try this instead:
@pnbruckner thank you sir. Didn’t realize there was a difference in quotes. That’s what I get for copy-pasting from the innerwebs. Working now. Cheers!
I am successfully using the random delay but would like to know what the actual delay amount is each time. Is there a way of seeing what the random delay value is with each run of the automation?
Thanks. I see that after the automation has finished but is it possible to know the delay value at the time it is run? For example, could I get a notification that says it was delayed by x minutes each time?