LUA code assistance needed

I have a scene that has LUA code within it that will prevent the scene from running if a virtual switch is enabled. I’m working on moving my virtual switches into a multi switch to try and reduce the number of vSwitches I have. Until I can get this scene moved into Reactor, I’m in need of some assistance to tweak it. Or is it even possible?

The current LUA code is:

local dID = 56 – Device ID of your VirtualSwitch
local allow = false – true runs scene if switch is on, false blocks it
local status = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”,“Status”,dID)
return ((status == “1”) == allow)

The ID of the multiSwitch is 357. But I think I need help with the local status line. The new multi switch service is

urn:dcineco-com:serviceId:MSwitch1

Event type parameter from the Advanced settings of the device is:

urn:schemas-dcineco-com:device:MSwitch357:1

But how do I include which button it is? SetStatus8.
Or does each button by chance have its own ID, which I don’t see.

TIA

Hi @3rdStng,
You get the status 0/1 of switch 1

luup.variable_get("urn:dcineco-com:serviceId:MSwitch1", "Status1",357)

For Multi Switch this are the commands to change a switch value to 0 or 1.

local newStat = 1 -- 0 = off, 1 = on.
luup.call_action("urn:dcineco-com:serviceId:MSwitch1", "SetStatus1", {newStatus1=newStat}, 357)
luup.call_action("urn:dcineco-com:serviceId:MSwitch1", "SetStatus2", {newStatus2=newStat}, 357)
...
luup.call_action("urn:dcineco-com:serviceId:MSwitch1", "SetStatus8", {newStatus8=newStat}, 357)

Cheers Rene

Ok. I can see within the LUA code where it gets the status, but will that grab the status of all 8 buttons? I also don’t want to change the status of the button. I just need the scene to not run if button 8 is on.

Full disclaimer, I have not tried this but would it work?

luup.variable_get(“urn:dcineco-com:serviceId:MSwitch1”, “Status8”,357)

Hi,

To do that you can add some code to the scene;

local sV, tS = luup.variable_get("urn:dcineco-com:serviceId:MSwitch1", "Status8",357)
return sV == "0"

If your scene Lua code returns True, the scene gets executed, if False it does not.

Cheers Rene

My first inclination would have been to advise you to use the Switchboard plug-in rather than multiSwitch, as it’s newer and authored by the same dev who created Reactor. Switchboard offers some nice bonus features not found in mS.

1 Like

I like this idea. I’ve noticed that multiSwitch has caused a loop reload when toggling a button on or off. Installing it now.

Out of curiosity, is there a way to tell where a virtual switch is used in a scene? I know that Scenes is listed under a physical device, but under the vSwitches, this is not present. Trying to not kill my scenes too bad.

EDIT: I allowed Switchboard to adopt my old vSwitches and that gives me the ability to see the scenes. Now I need to re-create those two I already moved into multiSwitch and remove that plug in.

1 Like