Configure automation at sunset/sunrise with +/- random delay (+/-15 minutes) + delay between actions

Hello,

I’m new here, I’ve migrating from my current domoticz setup to home assistant.
I’d like to get everything working the same as with domoticz.

Here’s what I’d like :
(1) I’d like to close my roller shutters at sunset (with a +/- 15 minutes random delay)
(2) I’d like to setup a delay between all those shutters (to simulate a human walking to the buttons and pushing them)

Apparently it’s not possible with th GUI which is fine, I’ve read that it could work by adding some manual code… but I don’t know to which files or how to access them…

I thinck part (1) should work as following

  • event at sunset
  • offset -15min
  • delay random 0-30 min

so something like :

 - event: sunset
    platform: sun
    offset: -00:15:00

[...]

- delay:  "{{ '00:%02i:00'%range(01,30) | random }}"

but in which file ? and how to access the file ?

part (2) - delay between actions in an automation - , honestly no idea so looking for help/pointers here

Thanks in advance :slight_smile:

1 Like

Ok I found the edit in yaml thingy, maybe this’ll work for part 1.

Still not sure how to code part 2

Would you mind sharing your yaml for part 1?
I also migrated (but from openhab) and would like to use this as well.
Thanks in advance.

sorry for the late answer… I was not notified I think.

there’s the code for the whole thing :

Close rollers 20 minutes after sunset + random delay before start + random delay between different rollers

alias: Fermeture volets
description: ""
trigger:
  - platform: sun
    event: sunset
    offset: "00:20:00"
condition: []
action:
  - delay:
      seconds: "{{ range(0, 900)|random|int }}"
  - device_id: xxxx
    domain: cover
    entity_id: cover.nodeid_11_position
    type: set_position
    position: 0
  - delay:
      seconds: "{{ range(15, 45)|random|int }}"
  - device_id: yyyyy
    domain: cover
    entity_id: cover.nodeid_13_position
    type: set_position
    position: 0
  - delay:
      seconds: "{{ range(5, 25)|random|int }}"
  - device_id: zzzzz
    domain: cover
    entity_id: cover.nodeid_12_position
    type: set_position
    position: 0
  - delay:
      seconds: "{{ range(45, 90)|random|int }}"
  - device_id: aaaaa
    domain: cover
    entity_id: cover.nodeid_15_position
    type: set_position
    position: 22
  - delay:
      seconds: "{{ range(15, 45)|random|int }}"
  - device_id: bbbbbbb
    domain: cover
    entity_id: cover.nodeid_14_position
    type: set_position
    position: 40
  - delay:
      seconds: "{{ range(15, 45)|random|int }}"
  - device_id: cccccccc
    domain: cover
    entity_id: cover.nodeid_18_position_1
    type: set_position
    position: 0
mode: single

Open non bedroom rollers upon sunrise, but no earlier then 7h30

alias: Ouverture Volets
description: ""
trigger:
  - platform: sun
    event: sunrise
  - platform: time
    at: "07:30:00"
condition:
  - condition: sun
    after: sunrise
  - condition: time
    after: "07:29:00"
action:
  - delay:
      seconds: "{{ range(0, 900)|random|int }}"
  - device_id: xxxxxxxxxxx
    domain: cover
    entity_id: cover.nodeid_13_position
    type: set_position
    position: 100
  - delay:
      seconds: "{{ range(5, 25)|random|int }}"
  - device_id: zzzzzzzzzzzzzzz
    domain: cover
    entity_id: cover.nodeid_12_position
    type: set_position
    position: 100
  - delay:
      seconds: "{{ range(17, 45)|random|int }}"
  - device_id: yyyyyyyyy
    domain: cover
    entity_id: cover.nodeid_11_position
    type: set_position
    position: 100
mode: restart

No worries.
I have plenty to do anyway :wink:

Thank you very much - I will check it out and might come back with questions :wink: