Light Levels

Hi all I have a zwave dimmer and a motion detector in my kitchen. I would like to capture what the light level is and jack it up to 100% when motion is detected, Then after 30 seconds return the light to its state (before motion was detected) - ie- if light is at 50% and someone walks in, light with move up to 100% for 30 seconds and then return to 50% … Can someone please show me the code to have this accomplished?
Thank You!

Running VeraEdge UI7.

Did you ever get working code for this you could share? I am working on something similar and need more examples how to do things… always appreciate good working code to reference :slight_smile:

I use PLEG for the automation. Are you just looking for LUA or any options to do this?

I did something similar at my old house with a “Movie Time” virtual switch. Turn it on, and it would store the state of all the lights in the living room to a variable container and then set the lights to the proper levels for watching and when turned off, it would read back those variables and set the devices to what they used to be. I’m not sure if I still have the code, but I can look when i’m back at home.

Here is the code I used, it uses the MultiString plugin for storing the variables. Change your device IDs to match (54 for the dimmer, 65 for the plugin in this example). I set up two scenes that triggered on my virtual switch off and on but PLEG can certainly be used as well.

Store the existing state and change to what is needed (in my case, 0 or Off)

local lul_Var1 = luup.variable_get("urn:upnp-org:serviceId:Dimming1","LoadLevelStatus", 54)

luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = 0},54)

Restore to previously stored state:

local lul_Var1 = luup.variable_get("urn:upnp-org:serviceId:VContainer1","Variable1", 65)
luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = tonumber(lul_Var1)}, 54)

Also an interesting idea … so many ways to do things! I’m just getting started with my system, still experimenting with ways to do things and what I want to achieve. Thanks for the idea.

BTW, just curious why a plugin is needed to store a variable … isn’t it stored when you define "local lul_var1 = … "

Like I could read a current light level , then set it to 100% for 2 min, and then use the variable to write it back to the original value when done.

Have I over simplified it?

My understanding is you need it for variable persistence. Local variables like that (to my knowledge) do not exist anymore after the code is executed, and at the worst case are lost during an engine reload anyway. By storing the values in a device, you have them until you set them to something else or delete the device. Your example should work if you stored the values, did the delay, and recalled them in the same block of code on one scene - assuming such a long running script like that wouldn’t trigger a reload (not sure).

OK, so for quick storage in a piece of code it’s OK to use the local variable, but for actions with longer persistence or across scenes it seems the plugin is good practice - I’ll give it a try. Thanks

Actually there are three types of variables: Local, Global, and those stored in a plugin/virtual switch.

Local variables (by including “local” in front of the variable declaration) are for that procedure or that scene only.

Global variables (variables that do not have “local” in front of them) are available to all scenes. However, global variables are lost when Vera reboots, or the LUA engine reloads.

Plugin/Virtual switch variables will survive a reboot.

I use global variables all the time. However, if you do use global variables, it is a good idea to initialize them in your LUA startup code section.

Good to know, thanks!