Running random times en scripts in automation

Allright. In my search to a good vacation script and no replies to the topics @ the forum, I’m trying to make some kind of a simple vacation script.

The situation is that I’ve got some scene’s that are running daily right now. Turning lights on at several brightnesses, a script for when going to bed and one for waking up :slight_smile:

Thing is I want to run them when I’m away with in interval of half an hour. This is what I’ve got right now.

- id: '1569353168194'
  alias: Vakantiemodus - lampen aan avond
  trigger:
  - at: '17:{{ (range(30, 59)|random|int) }}:00'
    platform: time
  condition:
  - condition: state
    entity_id: input_boolean.vakantie_modus
    state: 'on'
  - condition: state
    entity_id: sun.sun
    state: below_horizon
  action:
  - data:
      entity_id: script.lampen_fase1
    entity_id: script.lampen_fase1
    service: script.turn_on

Thing I wonder is if the random time between 17.30 / 18.00 will work to run the script if the sun is down? And if so; will it turn on the script? This is what the automation generator from UI spit out, but it looks kinda strange…

You can’t use a template in the time trigger’s at parameter.

What’d I’d suggest is to trigger the script at 17:30:00, then have a delay as the first step that uses a random amount of time from 0 to 30 minutes. Then the second step should run the script. E.g.:

  trigger:
    platform: time
    at: "17:30:00"
  condition:
    ...
  action:
    - delay: "{{ range(0, 31)|random|multiply(60) }}"
    - service: script.lampen_fase1
3 Likes

Thanks. So it will be

- id: '1569353168194'
  alias: Vakantiemodus - lampen aan avond
  trigger:
    platform: time
    at: "17:30:00"
  condition:
  - condition: state
    entity_id: input_boolean.vakantie_modus
    state: 'on'
  - condition: state
    entity_id: sun.sun
    state: below_horizon
  action:
    - delay: "{{ range(0, 31)|random|multiply(60) }}"
    - service: script.lampen_fase1

Thanks!

1 Like

Phil, is it me, or just deja vu, haven’t you answered almost this exact question 3 times in the last 2 months ?

in that case the search function in the forum isn’t working very well…

No, it seems to work fine, I looked for “random timer” and got : -

  1. Automation - random turn off time within time window?
  2. Random Trigger Time not working
  3. Run speed test at random times
  4. Random Time and Duration Generator for Vacation
  5. This thread
  6. Is there a method to have a random time trigger an automation or script? (this guy withdrew his question after a search yielded an answer)
  7. Random Time Trigger?
  8. Set random time for random automatic turning off lights (mimic someone is home)

Then I got bored of cutting and pasting

In that case, @Mutt, sorry I’ve asked…

:roll_eyes:

Perhaps you can also explain to me how to downvote people? Or isn’t that possibel over here?

Dunno, have you tried searching for it ?

It’s number 1 in the FAQ : -