Cycle light colors depending on multiple input toggles on/off state

I’m currently trying to sort out the easiest way to automate an indicator light based on on/off state of various toggles. I have a light in my kitchen I’d like to use to notify for things like feeding the dog, emptying the dishwasher and taking out the recycling. Right now, I have it turn on for each one individually, each one overriding the previous (if the previous was on already). I’d like to sort out a way to cycle the lights at ~10 second intervals if multiple toggles are on.

For example, if the dog needs to be fed the light is blue, and if the recycling needs to go out it’s green. If both the dog toggle and recylcing toggle are on, I’d like the light to cycle between blue and green for the duration until the respective toggle is turned off, at which point it goes back to only whatever toggle is still on. If all three are on and one turns off, it would go back to just the remaining two. I’m thinking a loop that checks which toggles are on when another turns on, then again when something turns off, but not quite sure if that’s the easiest method.

To add to the mix, I also have the indicator light turn red when a door is open, which I wouldn’t need to cycle but the red light would override the others and not need to cycle, but the cycle would need to start again when the door is closed.

Any help is apprecaited!

You can do this through scripts but it can be a bit tricky to dial in. Without writing this entire system for you it’s difficult to demonstrate, but the concept could be something like this:

Your script evaluates all the conditions (dog hungry, dishwasher full) and sets the value of a script variable to be a list of all light colors to set as a result of the analysis. Let’s say that the evaluation produce a value like this:

['red','blue','green']

You could then have your script run a repeat command dynamically set to iterate for as many elements are on the list (i.e., 3) and then uses the current loop number as the index to set the color dynamically with the normal change color commands within the loop, i.e.:

color: {{ variable_name[index] }}

This is just a concept, like I said it would take me writing the whole thing to demonstrate the concept. It’ll be a bit tricky but not overly so, but in an hour I bet you would have something working.

There are other creative ways to do this that you could entertain as well. For instance you could set up a helper entity that contains the color loop sequence you want, built dynamically from other automations that detect the conditions (dog hungry) and then use automation to read that value in and loop over the colors.

1 Like

Very cool thanks. I think I will have to dive in a make a script with a repeat loop, checking all the toggles and setting the light accordingly. Appreciate it!

Give it a crack and if you run into troubles post your code here for review. Good luck!

1 Like