Pick Random scene / variable from list

Hi

This one may be a little unusual and not sure its possible, but most things seem to be with PLEG with a little imagination, so worth asking!

I use the double / triple click features of the Fibaro dimmers extensively in our house to control various things - mainly the Sonos systems, as my wife moans about having to use the Sonos App. What I would love to be able to do is to apply different logic to what gets played based on different conditions - eg different times of the day = different radio stations / playlists - but ideally from a “picklist” of variables where one is selected at random. So I might pass a list of 10 playlists (or 10 scene numbers that control playing them) against a schedule and PLEG would randomise the one it plays. This could also be useful for picking random lighting mood scenes for example. Has anyone done anything like that or can you think of a way? Unfortunately the Sonos plugin does not natively support any randomisation.

Cheers

The easiest way would be to use Lua on a PLEG Action. The following code will randomly pick one of the scene numbers from scenelist and run it. scenelist can be any length and in any order.

local scenelist = {21,22,23,24,25} local index = math.random(1,#scenelist) luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = scenelist[index]}, 0)

Ah excellent I knew there would be a way! Is there any way in PLEG or Vera that you can manage Variables / lists separately so that I could call a list from multiple PLEG actions via a variable, rather than having to code the list each time?

If you make the variable global (by omitting local) and place the definition in PLEG’s Startup Lua, all your Action Lua will be able to use it.

You could even place the whole function in Startup Lua and just call it from the Actions:

function runRandomScene() local scenelist = {21,22,23,24,25} local index = math.random(1,#scenelist) luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = scenelist[index]}, 0) end

Then in each Action Lua:

runRandomScene()

Perfect, thanks I will give it a go.