Create Your Own Functions

I’m new to the forum, but have started getting into the luup side of micasaverde as it offers much more control of things.

The question is, how and where can I put a bunch of functions I created so that I can use them later.

I have created a few functions to make life much easier on myself when using luup in scenes. I’m not sure about the rest of you, but I have to look up variable names, syntax, etc. every time I want to write some code to control a device.

An example would be, instead of typing all of this:
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },1)
to turn off a light switch, All I have to do is this:

So, it works great if I create a scene and include all of my functions above the function call, but I would like to upload a file with all of my functions to vera2 and be able to reference them in scenes without pasting all of my functions in each scene.

I have been reading for about an hour, and the best I can come up with is to create an xml file with the tag and specify all my functions there. I tried this and could not get anything to work.

Where and how can I do this???

Thanks in advance!

Hi smikk, and welcome to the forum!

You can create an external module ([url=][/url]) and add your functions there. Then, in the scene code, you would “require” the module and use its functions.


module ("my_functions", package.seeall);

function foo()
    luup.log ("Hello World!")

Save the file as my_functions.lua and upload it on Vera to /usr/lib/lua with a software like WinSCP (if you’re on Windows) or the scp command if you’re on Linux or Mac.

In the scene the code would look like this:

local mf = require ("my_functions")

I haven’t tested this with luup functions, so it’s possible it won’t work, but you should give it a try.

Wow very fast reply, thanks!

I was not even aware that I could use ftp. I use filezilla currently. I just tried to connect using vera2’s ip address, and my vera2 username and password.

I am not successful in connecting. any thoughts on maybe what I am doing wrong? I’ve tried ftp, sftp and ftps.

Thanks again for the help!

To connect to Vera you need SCP.

I was able to figure it out after reading a bunch of other forum topics, thanks for pointing me in the right direction.

It does in fact work the way you said it would, this is perfect!

One last question… How do I delete the the functions.xml file I uploaded in the luup files? there are only links to view or download, but not delete. I have also done a search on vera2 with winscp and cannot find the file in any directory there.

Any help on that would be great. Thanks again!

The files uploaded by the users or downloaded by a plugin are in /etc/cmh-ludl.

Perfect thanks for your help, I made a lot of progress this week!