Need 1 second pauze between switch actions in an automation

I have the following automation switching all the lights in my garden:

- id: '1643143927461'
  alias: Garden lights ON
  description: ''
  trigger:
  - platform: sun
    event: sunset
    offset: '0'
  condition: []
  action:
  - service: homeassistant.turn_on
    target:
      entity_id:
      - switch.buitenkeuken
      - switch.voordeurlicht
      - switch.muurlampen
      - switch.fietsenhok
      - switch.tuinhuislicht
  mode: single

The switches are KaKu 433 legacy devices controlled by RFlink. If I run this automation some times some switches do not go “on”. I know the same behavior from the original KaKu ICS-2000 and could solve this to have 1 second delay between every switch action. How can I do this in my HA automation?

In the action just add a delay

delay: 00:00:01

If I do:

  action:
  - service: homeassistant.turn_on
    target:
      entity_id:
      - switch.buitenkeuken
    delay: 00:00:01
      - switch.voordeurlicht
    delay: 00:00:01
      - switch.muurlampen
    delay: 00:00:01
      - switch.fietsenhok
    delay: 00:00:01
      - switch.tuinhuislicht

I get “duplicated mapping key at line 93, column -15:
delay: 00:00:01”

This would be too simple :slight_smile:

  - service: light.turn_on
    target:
      entity_id: light.light_1
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: light.turn_on
    target:
      entity_id: light.light_2

I am new in HA (and programming anyway :smiley:) Thanks for the example !

Create a variable (called switches) containing a list of the five switch entities. Then use a repeat - count to step through each entity in the switches list, turning it on then pausing for one second before proceeding to the next entity in switches.

- id: '1643143927461'
  alias: Garden lights ON
  description: ''
  trigger:
  - platform: sun
    event: sunset
    offset: '0'
  condition: []
  action:
  - variables:
      switches:
      - switch.buitenkeuken
      - switch.voordeurlicht
      - switch.muurlampen
      - switch.fietsenhok
      - switch.tuinhuislicht
  - repeat:
      count: '{{ switches | count }}'
      sequence:
      - service: switch.turn_on
        target:
          entity_id: '{{ switches[repeat.index-1] }}'
      - delay: '00:00:01'
  mode: single
1 Like

Looks a very appealing solution. Will try this after a good sleep. Thanks a lot!