The Vera Community forums have moved!

Advanced => Programming => Scene Scripting => Topic started by: Aaron on December 11, 2012, 07:47:38 pm

Title: Virtual Device as Trigger to Enable/Disable many Scenes at once - LUUP examples?
Post by: Aaron on December 11, 2012, 07:47:38 pm
I have several scenes that are based on Schedules, but 'tied' to a house "status". To simplify things, I'd like to use Virtual Devices (switches) to turn enable/disable them in batches.

For instance...

I have 6 Scenes for AWAY status, and 5 Scenes for VACATION status -- thus, I'd like to have one virtual device for each status, AWAY & VACATION, and have a single scene that monitors for status changes and enables/disables the proper scenes accordingly.

I was thinking something like the below code. If you can help me complete this, or have an easier way, please let me know.

thx for the help!

Code: [Select]
local VACATION=67
local AWAY=68

local AWAYmode = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", AWAY)
local VACATIONmode = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", VACATION)

if (AWAYmode == "1") then
  <code to enable scenes goes here>
  else
  <code to disable scenes goes here>
end
if (GuestMode == "1") then
  <code to enable scenes goes here>
  else
  <code to disable scenes goes here>
end
Title: Re: Virtual Device as Trigger to Enable/Disable many Scenes at once - LUUP examples?
Post by: chixxi on December 12, 2012, 02:51:46 am
What do you mean by "enable/disable a scene"?! Basically you can only "run" these, and not enable or disable these.

I just add these lines to a scene which I want to prevent from running:
Code: [Select]
local autoswitch = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",11)
--disable when autoswitch is off
if (autoswitch == "0") then
  return false
end

If the virtual switch is set to "off" and the scene is triggered, this will prevent the scene from running.
Title: Re: Virtual Device as Trigger to Enable/Disable many Scenes at once - LUUP examples?
Post by: Aaron on December 12, 2012, 10:53:24 am
What do you mean by "enable/disable a scene"?! Basically you can only "run" these, and not enable or disable these.

OK, I thought that might be the case... which sux.

I just add these lines to a scene which I want to prevent from running:
Code: [Select]
local autoswitch = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",11)
--disable when autoswitch is off
if (autoswitch == "0") then
  return false
end

If the virtual switch is set to "off" and the scene is triggered, this will prevent the scene from running.

Thank you, this will help - though, I'd much prefer a way that did not include adding code to each and every Scene. It would be MUCH nicer to have a single "house mode" Scene that enabled/disabled other Scenes.

One other thought I had...
Can we enable/disable 'Schedules" using code?
- if we can, then we could maybe do it using a single Scene?

Title: Re: Virtual Device as Trigger to Enable/Disable many Scenes at once - LUUP examples?
Post by: RichardTSchaefer on December 13, 2012, 05:14:06 pm
You can do this with Program Logic Event Generator plugin.
Have all of your scenes be initiated from the Condition Satisfied outut event of the Program Logic Event Generator plugin.

Scene1Trigger = HOUSE_OCCUPIED and (Existing scene1 trigger expression)
...
SceneNTrigger = (HOUSE_OCCUPIED and (Existing sceneN trigger expression)

Than use a Virtual Switch to set the HOUSE_OCCUPIED trigger.
Title: Re: Virtual Device as Trigger to Enable/Disable many Scenes at once - LUUP examples?
Post by: Aaron on December 13, 2012, 09:36:32 pm
You can do this with Program Logic Event Generator plugin.
Have all of your scenes be initiated from the Condition Satisfied outut event of the Program Logic Event Generator plugin.

Scene1Trigger = HOUSE_OCCUPIED and (Existing scene1 trigger expression)
...
SceneNTrigger = (HOUSE_OCCUPIED and (Existing sceneN trigger expression)

Than use a Virtual Switch to set the HOUSE_OCCUPIED trigger.

I'll definitely look at this method this weekend... and report back.

Thanks!!!