How to open/close Covers time-displaced

Hi,

I have a simple automation for opening/closing my covers at sunset/sunrise. But it should not look like an automation, the covers should open/close time-displaced +/- 30 minutes and also the order should be random.

How can I do that? Is there a module principle for coding automations?

This is may current automations config:

id: ‘1538082125402’
alias: Sunset
trigger:
event: sunset
offset: +00:30
platform: sun
condition: []
action:
data:
entity_id: group.all_covers
position: 20
service: cover.set_cover_position
id: ‘1538082797356’
alias: Sunrise
trigger:
event: sunrise
offset: +01:00
platform: sun
condition: []
action:
data:
entity_id: group.all_covers
service: cover.open_cover

What do you mean:

time-displaced from what? And why should it be random?

Also, when posting code, please follow the directions at the top of the forum. No one can read code pased in in the format you did.

See this post: Simple automation question - length of time 'on' - #10 by petro

Hi, sorry about that, I edited my post, hope thats correct now.

Here is an example:

I want my covers to open and close automatically(that is working) fixed to sunset/sunrise but I don’t want it to look like being opened/closed automatically. Let’s call it burglary protection. I want to simulate that a human is opening/closing the covers.
Therefore the covers should open/close at sunset/sunrise +/- 15 minutes and not all at once.

On Monday bedroom cover goes down at 6:00 pm, bathroom at 6:02 pm, living room at 6:04, …
Next day at 6:15,…

Maybe there is a better solution but I hope my plan is now clear.

use the random sensor component, it will create an integer that changes every time you access the integer:

sensor:
  - platform: random
    minimum: 0
    # This number is exactly 1 hour in seconds.
    maximum: 3600

Change your offsets to be 30 minutes before what you currently have.

Make sure you treat your action section as a list of services instead of a single service (by adding - before each service). And add the following delay:

- delay:
    seconds: "{{ sensor.random }}"

In the end, it will add a random delay, ± 30 minutes from your current time. We just changed it to be -30 minutes + up to 60 minutes.

so in the end, your automation will look like this:

  - id: '1538082125402'
    alias: Sunset Cover
    trigger:
      - platform: sun
        event: sunset
    action:
      - delay:
          seconds: "{{ sensor.random }}"
      - service: cover.set_cover_position
        data:
          entity_id: group.all_covers
          position: 20
  - id: '1538082797356'
    alias: Sunrise Cover
    trigger:
      - platform: sun
        event: sunrise
        offset: "+00:30:00"
    action:
      - delay:
          seconds: "{{ sensor.random }}"
      - service: cover.open_cover
        data:
          entity_id: group.all_covers

Thank you, I will try it out!

It didn’t work. I tried it like this. The covers did not move.

    - id: cover_sunset
  alias: Cover Sunset
  initial_state: true
  trigger:
    event: sunset
    offset: +01:00
    platform: sun
  condition: []
  action:
    - delay:
        seconds: "{{ sensor.random }}"
    - service: cover.set_cover_position
      data:
        entity_id: group.covers
        position: 20

Try this:

- delay: '00:00:{{ (range(10, 59)|random|int) }}'

That gives you a random delay between 10 and 59 seconds.

That’s what I did for my covers:

- id: close_cover
  alias: 'Stores : fermeture'
  trigger:
  - platform: numeric_state
    below: '-4'
    entity_id: sun.sun
    value_template: '{{ state.attributes.elevation }}'
  action:
  - delay: '00:{{ (range(1,15)|random|int) }}:00'
  - entity_id: cover.rflink_test
    service: cover.stop_cover
  - service: mqtt.publish
    data:
      topic: hassio/cover
      payload: "down"

It closes the cover a bit after sunset + a random number between 0 and 15 of minutes.