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.
Love this thread. I find myself falling into this all the time sadly.
“ How can I turn a 10 second problem into a 10 minute solution?”
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.
“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”.
If you mean can I create an equivalent solution as a YAML automation, with an appropriate template, the answer is no. Maybe it’s possible but, over the 11 months I’ve been hanging around this forum, I’ve never seen it done.
The issue is you can’t iterate (loop) in a YAML automation. It lets you define a sequence of steps, where each step can be tweaked with a template, but you can’t loop through those steps.
So just like speaking and thinking (if you are fortunate enough to be multi-lingual) - pick the programming language for the task at hand.
Latin is much preferred by lawyers due to it’s formal structure, I heard.
I thought i would just pop in here… I have 200 lines of code for turning on my 19 lights of IKEA… Turn on … delay… turn on… delay and it works brilliant.
Even though the automation is long, it is still very easy to see exactly what it does
But loops are possible. e.g.
NM. I see what you are saying. Iteration is not equivalent to a “while true do” loop.
YAML is not Turing Complete. Python is.
I have similar automations that I could combine at the expense of mere mortal (me) understanding, but this is not the way to go for maintainability.
Anecdotally, there’s bugger all gain to be made other than the satisfaction of solving the puzzle. The hardware we run HA on is more than capable of a few inefficiencies, even if configuration length equated to efficiency (I’m guessing it does not, much).
It’s your home automation system. Write it so you can understand it and maintain it.
I’ll be the first to admit that out of necessity I have been guilty of using provided configuration I do not fully understand. But it’s rare.
The worst thing about 5500+ lines of automations is… bugger all. Ctrl+F in most editors will get you there.
I think ‘most’ of us here suffer from it (to a greater or lesser degree or we wouldn’t be obsessing about when it’s appropriate to “turn a light off”). A good coder is hard to find. They need the right level of OCD, but not tooooo much as some of them have to turn the light off 23 times before they leave a room.
"BUT testing is a valuable use of time !!! " ; - ))))))))))))))))
Cheers
Only 10 minutes ! … You’re not trying hard enough ! ; - ))))))))))
No. Thats just so they can charge you $600 per hour !
There is bugger all latin left in the law, I can’t think of the last time I used a latin phrase.
True, if your clients dont need Alibi’s, you’ll get a bonus if that’s the case.
i.e. you can’t let your ego get in the way and cause extra complications even if they are semi-intoxicated e.g. “on exiting one pub we engaged in a physical difference of opinion versus another pub”
Sorry I couldn’t resist a quick stab
Those words are all in common english use, and are english. The type of latin that lawyers are notorious for is a fortiori or ejusdom generis.
English is a bastardisation of other languages, that’s why it’s so flexible.
I had a friend who was thinking of buying a fortiori (though he decided it was a foible excuse) he bought a lamborghini instead. (french fencing derivation from the same root).
and as for ejusdom generis, I think you can get pills for that ! or is that too generic ?
Seriously - I had to look up those words