Activating Lifx Scenes


#1

One of my Pistons turns on a Lifx scene at sunset. I have multiple scenes setup through the Lifx app. I was wondering if there is a way to have my piston randomly select a scene from a list of Lifx Scenes.

Example…
What I use currently-
When “Sunset=True” the Lifx scene “Sunset” is activates.

What I’m wanting-
When “Sunset=True” randomly activate “Sunset 1 or Sunset 2 or Sunset 3”

That even possible? How would I got about setting that up?


#2

You could simply create a variable for the name of the scene that you want to activate.
Then you could generate a random number based on the number of sunset scenes you have.
Then set the value of the variable equal to the name of the scene and tack on the value of the random number that was generated (or use an expression to do it all in one go).

Then finally set the scene to be equal to the value of the variable.


#3

Here’s an example of the random part presuming you have 6 scenes to choose from (0 - 5).

Read this for more details:

https://wiki.webcore.co/Functions#random

Or you could even do it this way:


#4

Or…

/**************************************************************
execute
with
Porch 1 Lifx Light, Porch 2 Lifx Light, Porch 3 Lifx Light, and Porch 4 Lifx Light
do
Activate LIFX Scene random(‘halloween’,’easter’,’everyday’)
end with
end execute


#5

This method seems to be the easier route…with the @random variable selected, do I need to list the scenes to select from (Easter, Halloween, everyday) or does that select from ALL available scenes I have setup in the app?


#6

You need to list the scenes that you want to use, case sensitive and watch the spaces. They must be exact as you have them in lifx.


#7

Got everything working perfectly. Thank you guys!


#8

Do you mind sharing a green snapshot of your piston? I’ve been looking for something like this as well. Thanks!


#9

This is what I’m using. Hope it helps.