Looking for Vera Luup snippets and programming examples

Could some kind soul give me a link to examples of snippets and programs written in Luup for the Vera box?

I have been through these forums and the vera wiki but can find no actual examples of code that I can start to learn from and actually implement in my vera system. I am eager to get started with Luup but all I read about is what it can do, not how to actually do it.

Please don’t refer me to the Luup reference manual or generic Luup rescources. Been there - not helpful. I want to look at code written specifically for Vera.

Thanks,

~ John

Go to Devices, Luup plugins in Vera’s web ui. All the files starting with I_ are Lua samples. I_GC100 is a good sample of a fully functional plugin. There’s some dummy I_TestSerial and I_TestIR that just shows the framework.

MCV - thanks for the pointer to the samples.

For those of us that are not highly involved with Luup programming, but want to start the process of learning and using Luup to enjoy our investment in Vera, would it be possible to have some sample Luup code that is relatively simple, like turning on a light switch, or triggering a scene to start for example? That way I / we can get a sense for how Luup code is structured for talking to Vera as well as see it actually doing some of the very basic ( but critically important) tasks that we bought Vera for in the first place?

Trying to sort through the relatively unstructured wiki and its pointers to generic Luup references that have nothing or little to do with Vera is a huge task, simply to learn how to write a snippit of code to turn a light on or off.

Please get us all started with some simple snippits to:

Turn an appliance switch on and off
Read the status of a switch
Set a dimming level for a dimmable switch
Arm/disarm a motion sensor
Trigger a scene to start

Thanks from all of us folks eager to learn and wanting to use Vera to its full potential

~ John

Did you see the sample here already: http://wiki.micasaverde.com/index.php/Luup_Scenes_Events

Turn an appliance switch on for device #5:
lu_CallAction(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },5)

Turn an appliance switch off:
lu_CallAction(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },5)

Do something if switch device #5 is on:
if( lu_GetVariable(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,5)==“1” ) then
–something to do goes here
end

Dim switch #6 to 30%
lu_CallAction(“urn:upnp-org:serviceId:Dimming1”,“SetLoadLevelTarget”,{ newLoadlevelTarget=“30” },6)

Arm motion senor #7:
lu_SetVariable(“urn:micasaverde-com:serviceId:SecuritySensor1”,“Armed”,“1”,7)

Disarm:
lu_SetVariable(“urn:micasaverde-com:serviceId:SecuritySensor1”,“Armed”,“0”,7)

Note, arming and disarming isn’t a concept within UPnP or Z-Wave. It’s just a flag that the Luup engine uses, and is stored in a variable we created called “Armed”.

Run Scene #5:
lu_CallAction(“urn:micasaverde-com:serviceId:HomeAutomationGateway1”,“RunScene”,{ SceneNum=“5” })

In this case we left the device number off (the 4th parameter to lu_CallAction), because the “RunScene” action is handled by the Luup engine itself–not by some device within Z-Wave, etc.

P.S.

However, normally you don’t need to lu_CallAction in Lua code. Rather, whatever actions, or commands, you want to run, you put into the scene itself, and the only Lua code is to simply check if some condition is true and abort the scene if the condition isn’t met.

I put this in the wiki too.

Thanks MCV, that helped a lot. Now will start playing with Lua coding

~ John

Thanks a lot for examples - it’s really great!

I am running version 1.0.988 and am having some issues with the luup code.

First, let me be clear that I am trying to write conditionals. I am working in the SCENES tab so basically it’s SCENE>New Scene>LUUP CODE.

The device I want to control is a wall wart nondimmable light or light appliance switch.

Under the ADVANCED tab for the DEVICE it is listed as:
urn:schemas-upnp-org:device:BinaryLight:1

From the examples I enter a line like this:

lu_CallAction(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },20)

After I UPDATE>SAVE and then press the GO button for the scene, I get the following error in the log:
01 03/16/10 23:45:29.621 LuaInterface::CallFunction-3 Scene 30 failed [string “function scene_30()…”]:4: attempt to call global ‘lu_CallAction’ (a nil value) <0x2c0c>

I have tried the same thing using: luup.call_action

I don’t get an error but I get no response.

Now I can write the conditional:

local lul_tmp = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,20)
if( lul_tmp==“1” ) then
luup.call_action(“urn:upnp-org:serviceId:Dimming1”,“SetLoadLevelTarget”,{ newLoadlevelTarget=“99” },19)
end

and it works if I manually tell it to GO.

First, which is the correct way to call these statements (luup.call_action or lu_CallAction)?

Second, is there any way for Vera to poll this scene automatically and not have to manually execute it?

Hi,

Accurate examples can be found on this wiki pages: http://wiki.micasaverde.com/index.php/Luup_Scenes_Events

Also, most of the plugins have Lua code in them, so nby clicking “View” on the Luup File it will show some examples as well.

The Lua code gets run anytime the scene is run. You can use timers or events to envoke a scene.

So the answer is yes. Just use a timer.

'm trying my hands on a first lua script, now I’ve upgraded to version 1.0.996

I’m trying to add this code to a scene:

local entry_state = luup.variable_get("urn:upnp-org:serviceId:Dimming1","Status",23)
luup.log("Debug Entry light=" .. entry_state)
if( entry_state=="1" ) then -- Is the light turned on?
	local entry_level = luup.variable_get("urn:upnp-org:serviceId:Dimming1","LoadLevelStatus",23)
	luup.log("Debug Entry light level=" .. entry_level)
 	if( entry_level<=50 ) then -- Is light brightness less then 50% ?
		luup.log("Debug abandon scene")
 		return false -- Then don't execute the scene
 	end
end

But it does not work.
I tested it in the Test Luup code button and gave a “[font=Verdana]code failed[/font]” error.
What am I doing wrong?

Tried this as well in the Test Luup code button:

local entry_state = luup.variable_get("urn:upnp-org:serviceId:Dimming1","Status",23)
luup.log("Debug Entry light=" .. tostring(entry_state))

then got “message sent” and found this in the log:

luup.log("Debug Entry light=" .. tostring(entry_state))
50	05/31/10 20:35:50.692	luup_log:0: Debug Entry light=nil <0x340e>

How come I get this nil value?

I don’t have an dimmable devices myself, but a look through the dimming service file and I don’t see a “Status” variable. You probably want

luup.variable_get("urn:upnp-org:serviceId:Dimming1","LoadLevelStatus",23)

Tanks Mike,

I just skipped the outer check all together and it’s now working:

-- Set condition that brightness level needs to be over 75%
-- Then this scene will bring brightness level down to 30% after 1 minute
-- If the brightness level is set to anything below 75%, it remains untouched

local entry_level = luup.variable_get("urn:upnp-org:serviceId:Dimming1","LoadLevelStatus",23)
luup.log("Debug Entry light level=" .. entry_level)
if( tonumber(entry_level)<=75 ) then -- Is light brightness lees then 75% ?
	luup.log("Debug abandon scene ''Entry light to 30'' ")
	return false -- Then don't execute the scene
end

For anyone interested…

Hi Everybody
How can I learn using LUUP for making scenes?
I mean I want to learn programing

Best way is to look at Rexbeckett’s sticky in the scene scripting folder. Good examples to learn from.

Sent from my iPad using Tapatalk