[Share] Piston to cycle a selection of LIFX scenes with one button

Below is a piston that does the following:

Cycle a selection of LIFX scenes (four scenes in the example) with one button (don’t hold the button, but press and release).

  • If light is off it just turns it on again without changing scene.
  • if light is already on it will change to the next pre-defined LIFX scene.
  • You need to create a dynamic global variable called “lastlifxscene” (default value doesn’t matter).
  • My scene consist of 5 bulbs: RGB Bulb 2, RGB Bulb 3, RGB Bulb 5, RGB Bulb 6, RGB Bulb 8
  • In the check to see if scene light is on, I just check if one of the bulbs (RGB bulb 5) are turned on, as they are usually synchronized anyway.
  • The scenes that will be cycled are four scenes setup in LIFX, named after different countries (Greece, Sweden, Norway, Denmark) they use the same bulbs. But you can of course add more or less scenes using the same syntax.
  • You need to have LIFX integrated with your webCoRE (generate a token in LIFX website paste it to webCoRE settings). Search forum here how to do this.
  • If you want it to also turn off the light either modify the code to do that, or make one of the scenes it cycles, to have the lights turned off (I use another button for that).

The code could definitely be optimized, but gets the job done. Maybe someone has an easier approach?