I setup a switch to trigger this automation. I’ve been trying some ai yaml editors and even hired someone on fiver, but can’t seem to get this to work. When the switch is on - it turns on the light and the first effect, but doesn’t change. Maybe random isn’t possible and I should try a list of effects instead?
Yaml code:
alias: Cloud Animation
description: >-
Turns on a light with a random effect every 2 minutes while the switch is on.
Turns off light when switch turns off.
triggers:
entity_id: input_boolean.cloud_ceiling
to: “on”
trigger: state
actions:
Please repost your code using the Preformatted Text option in the composer (icon </>). That will make your code readable.
Even with the broken formatting, though, I can see that you’re trying to use a state-based for condition in a repeat loop, which is probably at least one problem with your current approach. That won’t make the automation stop and wait 1 second to see if the input_boolean stays on; instead, the loop won’t ever happen because the loop condition fails.
It should work if you remove it. Why did you have it there in the first place? If there was something you were trying to achieve, I’m sure there’s a way to do it.
Ok, removing that got the effects to start changing randomly. Except they are changing every 10 seconds instead of 2 minutes. I suppose something isn’t correct in the delay command?
Ah, the looks like another automation was still enabled causing the frequent changes. So now it works, except there is up to a 2 minutes delay turning off/on. Maybe I need another automation to fix that?
Because your automation uses a fixed delay of 2 minutes. If you turn off the Input Boolean while the automation is busy counting down the delay, it isn’t aware of it.
Instead of a delay, use a wait_template with a 2-minute timeout.
It waits up to 2 minutes for the Input Boolean to be turned off. If it’s not turned off, the wait_template simply times out at 2 minutes (thereby behaving like a delay). If the Input Boolean is turned within the 2 minutes, the wait_template exits immediately.