Scene to turn light on or off depening on its current state

Hi,

I am looking to create a scene to control an in wall dimmer switch that will:

[ul][li]if the light is currently off, turn a light on (and set to a given brightness level)[/li]
[li]if the light is currently on, turn it off[/li][/ul]

I suspect this isn’t too difficult to do?

Honestly I am not a programmer and am not sure where to start. Is this some luup code to insert into the scene or is this something that should be done with pleg?

Any direction/code provided would be greatly appreciated.

Won’t that require create a loop, as soon as it is on, it will need to be turned off again.

You’ll need to think about adding another variable, such as the time of day or if light levels are xx

The plan is to call the scene manually. Basically, I can call vera scenes on my remote. When I hit the pause/play button to pause a movie, I want the lights to turn on. When I hit it again to start playing, I want the lights to turn out.

I may just separate the play and pause into two buttons and tie in the appropriate light on or light off action to each.

Yes, if you have those AV controls running via Vera, then they can certainly act as a trigger for the lights.

Share what you end up doing below, it’ll be good for others to see.

I don’t technically have anything running via vera.

My remote - iphone app called Roomie, can recognize the vera plus on my network and then lets me map vera devices or scenes.

Since I have no idea how to program my request in the initial post, I just ended up adding separate play and pause buttons on the remote. I created a manual scene that turns off all basement lights when run and mapped this as a secondary action on the play button. Created another manual scene that turns on a light to 70 brightness and tied that to the pause button.

If you just want to toggle the state of the light: If on go off, If off go on
You can just use the z-wave Toggle action in the advance scene editor, this will make it so that you only have to map one button to one scene. But that won’t allow you to set the dimmer level on On.
The tricky part of this is that unless your dimmer is a Instant Status dimmer, Vera might not be in a sync with the real world status of the switch.
But you could right some simple LUA code into your scene to check the status of the dimmer (on or off) then either turn off, or set to 70%. The problem is that you might end up having to push the button multiple times until Vera knows the correct state of the light.

The way I like to set my remotes. I have a toggle button (on, off), then a up/down for the dimmer, plus a couple of different mode lighting settings for the media room.

I don’t know if this helps:

  1. Under “Step 1” create a scene as a “Manual Trigger”
  2. Skip “Step 2: Device Actions”
  3. Under “Step 3” go to “Also, execute the following Luup code:” copy and paste the following and replace 79 with your device #ID (the example covers a light, remove the “OPT” lines for other devices since they cover the light’s brightness level)

[tt]
local device = 79 – device #ID via Device → Advanced (example 79)
local lgtsts = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, device)
if(lgtsts==“1”) then – If Device is On
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”, {newTargetValue = “0”}, device) – Device Off
luup.call_action(“urn:upnp-org:serviceId:Dimming1”,“SetLoadLevelTarget”,{ newLoadlevelTarget=“0” },device) – OPT Line if Light: Light Off
else
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”, {newTargetValue = “1”}, device) – Device On
luup.call_action(“urn:upnp-org:serviceId:Dimming1”,“SetLoadLevelTarget”,{ newLoadlevelTarget=“100” },device) – OPT Line if Light: Light On 100%
end
[/tt]

  1. Click “Save Lua,” then name your scene (i.e. Lamp Toggle) and click “Finish”
  2. You can test it by click the “Run” arrow icon and hopefully the light toggles on or off depending on it’s previous state.

[quote=“sfxed, post:7, topic:191148”]I don’t know if this helps:

  1. Under “Step 1” create a scene as a “Manual Trigger”
  2. Skip “Step 2: Device Actions”
  3. Under “Step 3” go to “Also, execute the following Luup code:” copy and paste the following and replace 79 with your device #ID (the example covers a light, remove the “OPT” lines for other devices since they cover the light’s brightness level)

[tt]
local device = 79 – device #ID via Device → Advanced (example 79)
local lgtsts = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, device)
if(lgtsts==“1”) then – If Device is On
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”, {newTargetValue = “0”}, device) – Device Off
luup.call_action(“urn:upnp-org:serviceId:Dimming1”,“SetLoadLevelTarget”,{ newLoadlevelTarget=“0” },device) – OPT Line if Light: Light Off
else
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”, {newTargetValue = “1”}, device) – Device On
luup.call_action(“urn:upnp-org:serviceId:Dimming1”,“SetLoadLevelTarget”,{ newLoadlevelTarget=“100” },device) – OPT Line if Light: Light On 100%
end
[/tt]

  1. Click “Save Lua,” then name your scene (i.e. Lamp Toggle) and click “Finish”
  2. You can test it by click the “Run” arrow icon and hopefully the light toggles on or off depending on it’s previous state.[/quote]

Hello,

Nice luup.
I tried this in my VeraPlus but when the light is off and I push the button there is a delay of aprox 40 sec. to turn the light on.
When its on and I push the button it goes immediately off.

Whats is the problem of this “long” delay??