ArieBaba
(Arie)
January 28, 2022, 9:52pm
1
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?
myle
(StePhan McKillen (Other kiwi Here))
January 28, 2022, 9:57pm
2
In the action just add a delay
delay: 00:00:01
ArieBaba
(Arie)
January 28, 2022, 10:28pm
3
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
- 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
ArieBaba
(Arie)
January 28, 2022, 10:41pm
5
I am new in HA (and programming anyway ) Thanks for the example !
123
(Taras)
January 28, 2022, 10:45pm
6
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
ArieBaba
(Arie)
January 28, 2022, 10:52pm
7
Looks a very appealing solution. Will try this after a good sleep. Thanks a lot!