Help with automation to call stop service after few seconds that was execute

Hi to everyone,

In my configuration of HA i have a automation configured, that when the sun is below horizon, my cover get down.

The automation is this one:


- id: '1596487290477'
  alias: persiana_bajar
  description: ''
  trigger:
  - below: '-5.0'
    entity_id: sun.sun
    platform: numeric_state
    value_template: '{{ state.attributes.elevation }}'
  condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
  action:
  - data: {}
    entity_id: cover.shellies_shsw_25_5db870
    service: cover.open_cover

This automation works well, and yes to download my cover i need to use the service cover.open_cover, because i’m using a shelly 2.5 and my rollershutter only works with 1 wire (every pulse of 220V go up or down), so i can’t use the 100% of the shelly option. The only thing that i can use to cover down a 80%, i need to do it by time.

My question is what i need to add in my automation, that after few seconds of was triggered, call a service to stop it.

I tried adding a delay of 4 seconds to call the service stop.cover, but doesn’t work, because when passed the 4 seconds, the rollershutter continue to down until the end.

- id: '1596487290477'
  alias: persiana_bajar
  description: ''
  trigger:
  - below: '-5.0'
    entity_id: sun.sun
    platform: numeric_state
    value_template: '{{ state.attributes.elevation }}'
  condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
  action:
  - data: {}
    entity_id: cover.shellies_shsw_25_5db870
    service: cover.open_cover
  - delay: 'seconds: 4'
  - data: {}
    entity_id: cover.shellies_shsw_25_5db870
    service: cover.stop_cover

What i’m doing wrong?

thanks