Best way to turn on multiple lights one-by-one

Hi

I have 17 outdoor lights along my house, and im thinking of making something fancy that fades them in one by one, but im not sure what the best way of doing this is.

The “bad” solution ( in my head ) would just to make a sequence, with delays in between all light_on, but then i need to copy/paste delay+light_on 17 times, which seems … unnecessary. ( and the same for light off )

So, i thought since the lights are named: light.outdoor_front_1, light.outdoor_front_2…
Maybe you could make something dynamic? Or if they are in the same light group? But How?
An example would very much be appreciated.

What kind of lights are they ? Hue, on a Zwave dimmer, …

Copy and paste 17 times? You could have done that in the time it took to post.

2 Likes

Ikea Trådfri Gu10 ( zigbee )

The point was not the copy/paste part, but if i could avoid ~200 lines of code to turn on/turn off 17 lights i would be glad

Why, are you that short of disk space?

1 Like

I want to do it the right way, not the easy way.
I want to make it dynamic, i guess its some kind of a OCD thing :stuck_out_tongue:

Fair enough, everyone likes elegant code. However sometimes you just need to copy and paste.

Stuff like this might be more elegant in appdaemon, which allows you to automate HA in python.

1 Like

Have you tried to call the turn off service with all your lights IDs?

I think this way, the service switch off the lights one by one

I use this to turn on/off all lights in a room, and they do it in parallel

Nick is right. HA does not do this sort of thing well. You would be better off using Appdaemon or a python script.

Hi,
I would do it using node-red.

  1. get all entities matching a pattern
  2. a loop based on those names
  • turn on one light
  • delay x ms
  • continue

Added bonus if you add some more lights using the same name pattern or within the same group they will be added to the loop without further effort.

I have migrated all my automations to node red and I love it!!

GV

1 Like

I would think you would be able to leverage the for loop as shown in the template development section of UI, run it as a script or a scene

I mean it can be done. You could adapt this:

@Terp
Here’s a very basic python_script that iterates through a group of lights and turns on each one in sequence with a delay of 15 seconds between each activation. Modify it to suit your needs:

sequence.py

items = hass.states.get('group.my_lights').attributes['entity_id']

for item in items:
  service_data = {'entity_id':'{}'.format(item)}
  hass.services.call('light', 'turn_on', service_data, False)    
  time.sleep(15)

The order the lights are activated is based on the order they are listed within the group.


EDIT

The advantage of using this python_script, as opposed to copy-pasting code 17 times in a script, is less maintenance. If you ever add more lights to the group they will be automatically handled by the python_script.

3 Likes

Love this thread. I find myself falling into this all the time sadly.

:thinking: How can I turn a 10 second problem into a 10 minute solution?”

4 Likes

I’ve said it before and I’ll likely say it again, compact configuration does not necessarily equate to easily understandable and maintainable configuration and probably has little effect on execution efficiency (zero facts available to back that last bit up). I do understand the fascination with simplicty compaction though.

I love this table.

e.g.

Q: How often do I switch lights on and off?
A: Between 50 and 5 times a day.

Q: how much time would I save by automating it?
A: 1 Second.

Therefore I should spend no more than 2 hours to 1 day attempting to automate it to save time over 5 years.

2 Likes

“I would have to agree Captain Kirk” says Mr Spock
But… Some people have built the most beautiful objects, because they can, they take pride in it, they take pleasure from knowing that behind this cover plate (that no-one will take off in the next 20years) is an (insert object here) that has been crafted to meet and often exceed its requirement.
Also, people like to do puzzles, people have hobbies and sometimes they intersect. Should I insert a Venn diagram here ??? ; - )))

When I said I “understood” the fascination with it, I meant I suffer from it and can empathise with OP, Mr Spock.
Also. I’m. Not. Capt. Kirk.

That is quite an elegant solution @123. Just out of interest, is it possible to do it anywhere as elegantly in jinja (I do not require proof just y/n if you have the time)?

Reminds me of my French friend who said she prefers thinking in English as it is “free-er”.