LUA code to deactivate a scene

Hello

I am totally new to LUA scripting, and came here as I’m looking for a command that would allow to activate (/disarm) a scene (and I don’t mean run the scene). I could not find such a LUA code for this, just indications on a old post that launching a scene from within another scene is not possible.

Here is why I want to do this:

  • I have 2 scenes ongoing:
    #1 if humidity >60%, then fan speed = 2
    #2 if humidity <60%, then fan speed = 1

but I also sometimes want to be able to set manually fan speed to 2 let’s say for 30 minutes (when cooking as the fan is the same). But if I manually set fan speed = 2 and humidity <60%, then next my scene #2 will kick in a set back fan speed to 1 the next time it checks humidity.

So what I do today, is that when I want to set fan speed = 2 manually for 30 minutes:

  • I deasactivate scene #2
  • I manually set fan speed=2
  • and after 30 minutes I re-activate my scene #2

I’m sure there is a better way to do this

Thanks

See this thread:

http://forum.micasaverde.com/index.php/topic,36552.msg272605.html#msg272605

Hello and thanks for pointing to this topic I had not found :-[
I just spent a couple of hours trying to understand the whole thing, and I’m lost:

  • I understand the solution to my problem is to go through a virtual switch
  • I installed the virtual switch app
  • I could not find any introduction to the virtual switch concept (it seems to be just a status button, but not related to any device, so i guess you trigger the status change in a scene, and then the status can be used by another scene)
  • I am not able to design a solution to my problem using a virtual switch: how do I use this virtual switch to deactivate my scene?

sorry, this is probably very basic, but I am lost :slight_smile:

thanks

ok after a couple more hours of effort I finally got it (more or less), so let me share here some findings as it may help others hopefully

  • Running / activating (or deactivating) a scene from within another scene is NOT the right approach considering how Vera and LUUP work (I did not really understand why it is like this but who cares :))
  • A better approach is to use a virtual switch
  • To create a virtual switch, one must install “Virtual ON/OFF Switches” app on the Vera
  • This automatically creates a new virtual switch (to create additional switches, this can be done through the App (/Apps/Myapps/Virtual ON/OFF Switches/Create Another)
  • A virtual switch is not directly linked to any other device (I spent 30 min trying to find out where to include other devices in the Virtual Switch :))
  • A virtual switch has 2 positions (like any switch) ON/OFF
  • Here are an examples of how virtual switches can be used
    • To activate / deactivate a scene: 1? create the virtual switch – 2? create a scene – 3? Include a LUUP code within the scene that will check the status (ON or OFF) of the virtual switch. Scene will run only if condition is met (for instance if switch is ON)
    • Here is the LUUP code used in my example:

local dID = 145 – Device ID of virtual switch to activate / deactivate VMC automation
local allow = true – true runs scene during period, false blocks it
local status = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”,“Status”,dID)
return ((status == “1”) == allow)

In the end,

  • when I turn the virtual switch to ON, my scene actually runs
  • when I turn the virtual switch to OFF, my scene does not run, which is equivalent to deactivating the scene.

pretty poweful stuff for a newby to LUUP like me (which is exactly what I wanted to stay away from…)

One quick question:
in the above LUUP code (I copied from anoth post), what is VSwitch1? Will it be always #1, regardless of the virtual switch and the code uses the device ID (local dID), or should it change for each virtual switch? I coulld not find a Virtual Switch ID other than the Device ID.

Thanks

Well done! Thanks for sharing your solution. This is certainly a problem which has been much discussed on the board.

Here is the LUUP code used in my example:

local dID = 145 – Device ID of virtual switch to activate / deactivate VMC automation
local allow = true – true runs scene during period, false blocks it
local status = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”,“Status”,dID)
return ((status == “1”) == allow)

Just to point out that the extra test for allow is not strictly necessary, since the expression status == “1” yields a logical type anyway …

local dID = 145           -- Device ID of virtual switch to activate / deactivate VMC automation
local status = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",dID)
return status == "1"
One quick question: in the above LUUP code (I copied from anoth post), what is VSwitch1? Will it be always #1, regardless of the virtual switch and the code uses the device ID (local dID), or should it change for each virtual switch? I coulld not find a Virtual Switch ID other than the Device ID.

VSwitch1 is the serviceId which should remain the same for all instances. The VirtualSwitch used to be a plugin which, IIRC, the author withdrew but graciously allowed the continued used of the serviceId which other plugins and, more importantly, remote apps were already using.