One Button Press, cycle through 3 Yeelight Colours

Hi. I have one RF Button that publishes the same payload on MQTT.
How to make every button press, cycle an Yeelight through: White, Green, Purple, OFF and repeat...
Input MQTT, example: home/OpenMQTTGateway/RFtoMQTT with payload 123456.

What have you tried? Have you something already to share? It really is "multipart question" so it will be long story to explain all possible solutions to develop this kind of logic.

Unfortunately i haven't tried anything. I am using on home assistant, where i've found some solutions using input_select and automation.
Thinking it could be easier on Node-Red...

What part do you need help with?

As @hotNipi said this is a multi part question.

Part 1...
As your button already publishes an MQTT message, you can easily subscribe to that. That will be the start of your flow - an MQTT in node that listens to the appropriate topic.

Part 2...

This part is bread and butter stuff for node red.
Break the problem down in your head then use a series of delay nodes to create your logic.

Part 3...
Controlling yeelight. I'm sorry I have no knowledge of this - I'm sure you can figure this part out.

1 Like

Part 3 additional...
Seems there is a contrib node for controlling the yeelight.

So to answer your question, node red is an excellent fit for this project.

1 Like

Hi. The input and output parts, are already kind easy for me. What i dont know, is the processing part. Which receives the same input, but need to cycle through 4 states.
Thanks! :smiley:

High level solution logic explanation:
Hold current state in node red as index in array of all possible states.
On input add 1 to index but check If new index is equal with array length set index to 0.
Store index as current index
Send new state got from array from that index.

Made correction in order of steps. Asking array elements by index should always stay in boundaries.

1 Like

This sounds like a perfect application for a finite state machine, so you might try node-red-contrib-dsm. The node has a bit of a learning curve, but it could be worth the effort. I suggest you skip most of the README and go straight to the examples. The Traffic lights example, despite having "no practical use," seems to be almost what you need.

1 Like

Hi! I am very bad on coding. :blush: This Traffic Lights example, using dsm seems what i was looking for. Few coding and quick results. I will try and post results. Thanks! :smiley: