2 seconds delay to enable each device when enabling switch

Hi

I got a switch in dashboard which can enable all the lights in the garden. Sometimes the fuse will be activated to interrupt the power. When I enable or disable each device individually I do not get the issue. So it looks that I have a high current when enabling all lights together by the switch.

Is it possible to create some code, that when the switch will be enabled, each light in the switch group will be enabled after the next with a delay of 2 seconds? With this scenario I might can fix the issue by reducing the switch-on current.

Many Thanks,
Chris

You could make an automation that triggers the lights in sequence with a 2 second delay between each light. You could also have it trigger at a certain time or by sundown so that you don’t need to do it manually.

You could probably also create a script.

if you label all of those lights with ‘your_lights’ (replace it with whatever you want and the code below) then the below code should do it.

  - repeat:
      sequence:
        - delay:
            seconds: 2
        - service: light.turn_on
          target:
            entity_id: >
              {{ label_entities('your_lights') | expand | selectattr('state',
              'eq', 'off') | map(attribute='entity_id') | first }}  
          data: {}
      while:
        - condition: template
          value_template: >-
            {{ label_entities('your_lights') | expand | selectattr('state',
            'eq', 'off') | count > 0 }}  

ok I did create a label, where do I need to embedd your code?
In the dashboard the existing code looks like this:

type: entities
entities:
  - entity: light.hauswandlampe_garten
  - entity: light.garten
  - entity: light.shellydimmer2_349454724a39
  - entity: switch.shellyplus1_3c610572ed5c_switch_0
  - entity: light.led_whirlpool
  - entity: light.garten_steckdose_einfahrt
    name: Steckdose Einfahrt
  - entity: binary_sensor.shellymotion2_8cf68108a3b1_motion
  - entity: binary_sensor.shellymotion2_8cf68108a3b1_vibration
  - entity: sensor.shellymotion2_8cf68108a3b1_luminosity
  - entity: sensor.shellymotion2_8cf68108a3b1_temperature
  - entity: sensor.shellymotion2_8cf68108a3b1_battery
title: Garten

you should put my code in a script and then have the dashboard trigger the script.
the script is an entity, so you could have a dashboard card that points to the script as an enttiy.

In addition to the above: you can no longer use the switch on top of the entities card: that won’t call the script but just do them all at once.

oh… my code assumes everything is a light… but i notice you have a switch in there. you can use this instead if you have a mix of lights and switches… and as edwin says, your dashboard should only point to the script. it cannot also point to the light and switch entities:

- repeat:
      sequence:
        - delay:
            seconds: 2
        - service: homeassistant.turn_on
          target:
            entity_id: >
              {{ label_entities('your_lights') | expand | selectattr('state',
              'eq', 'off') | map(attribute='entity_id') | first }}  
          data: {}
      while:
        - condition: template
          value_template: >-
            {{ label_entities('your_lights') | expand | selectattr('state',
            'eq', 'off') | count > 0 }}

There is no service called homassistant.turn_on.

I get the error when I want to save the script: Message malformed: expected dictionary @ data[‘sequence’][0] and No visual editor support for this action

my code looks like this:

- repeat:
      sequence:
        - delay:
            seconds: 2
        - service: homeassistant.turn_on
          target:
            entity_id: >
              {{ label_entities('Gartenlampen') | expand | selectattr('state',
              'eq', 'off') | map(attribute='entity_id') | first }}  
          data: {}
      while:
        - condition: template
          value_template: >-
            {{ label_entities('Gartenlampen') | expand | selectattr('state',
            'eq', 'off') | count > 0 }}`Preformatted text`

where Gartenlampen is my Label name. I did use a script called switch, and in the code I also tried to use the service name switch.toogle which is the given name when I choose a switch for a new script. but I got the same error.