Shutters up/down by automation

Hi,

I spent a lot of time to get it, but it went me crazy, I couldn’t found any good advices.

I have:

  • Sensors at Doors / Windows to check if they are open
  • Rollershutters
  • Free@Home integration

In manually everything is working well.

I do want to achieve the following:

  • driving shutters down at sun.sunset with offset +/- [a slider at gui]-minutes + x-minutes random (set by a slider and enabled by true/false-switch in GUI [off means no extra+offset, on means random minutes offset)
  • if door is open, than shutter’s position stop at 50%, exit from driving, till door is closed
  • if door is closed, first step, drive shutters to 50%
  • if shutters is at e.g. 60%, than do not drive to 50%, stay at this position (60%) without moving
  • wait for x-minutes (set by a slider and enabled by true/false-switch in GUI) + x-minutes random (set by slider and enabled by true/false-switch in GUI)
  • drive to 100% down
  • have a button in gui to enable/disable whole automation for this specific shutter

In other programming languages I would get it to go, but in YAML I am a totaly noob.
Please advice me to more about learning YAML to achieve my goal.

This is my “code” so far:

alias: "Shutter door down 2 steps"
description: ""
trigger:
  - platform: time
    at: "23:10:00"
  - platform: sun
    event: sunset
    offset: 0
condition: []
action:

# get current_position, for check if > 50%
# tried to have a number-helper-entity, but do not know ho to set state / value to

# delay for waiting to execute step 1
  - delay: "{{ (range(0, 2)|random|int) | multiply(60) }}" 

# step 1
  - device_id: 1e8bb6503abc322a8771c70a8e4f4144
    domain: cover
    entity_id: cover.shutter_door
    type: set_position
    position: 50


# wait for step 2 (for testing in seconds
  - delay: "{{ range(2, 5)|random|int }}"

# step 2
  - device_id: 1e8bb6503abc322a8771c70a8e4f4144
    domain: cover
    entity_id: cover.shutter_door
    type: set_position
    position: 100

mode: single

Regards