Hi All,
I have been researching about the best way to make my own library of functions. I found some information one year ago, but I thinks at that time was the old IU4. In IU5 there is a way to upload lua files APPS / DEVELOP APPS / Luup Files.
I wonder if I can use that interface instead of using FTP or other ways to upload my libraries.
If yes, how can I access the code.
I found this useful info to create Modules, but probably there is a different way to load it.
[url=http://forum.micasaverde.com/index.php?topic=8260.0]http://forum.micasaverde.com/index.php?topic=8260.0[/url]
Probably someone knows a better way to develop libraries and test it in each iteration.
Hi Richard
Thanks for your answer.
How can I find your apps?
If I have to download, then how can I see your code.
I’m sorry but I’m not expert. I just have few months with vera, and still getting used to it.
I want to create a global function to set temperature based in the weather forecast. This function needs to be global to be used in many scenes.
Probably this function will need to be tuned and do that in many spots will be hard.
You can look at the code for plugins loaded on your Vera:
Apps → Develop Apps → Luup Files
Pick a file and download (View does not work for all file types)
You will want to focus on the I_XXX.xml
and the L_XXX.lua files
Thanks Richard,
But, I can infer of what you are saying that If I upload a File using the UI5 interface with Load Files, then I can access my library?
Right now I looking for something very simple:
temp = mymodule.getTemp()
An this function will analyze weather temp, house temp, and the target I would like depending of the time.
This function will be called every hour, and when I turn the alarm ON or OFF, etc for energy saving.
I will check your code, but I was hoping an 1, 2, 3 step. I guess is more difficult than that.
The I_XXXX.xml files load the modules and reference the functions in the L_XXX.lua files.
The first line in the L_XXX.lua file defines the lua file as a module … You can find info on this on the web.
I really need help whit this…
I’m new with Lua, but I was C programmer 15 years ago when I had to program like this.
I can’t see what is the SINTAX problem with my code. It just send me an error when I save it and I dont know any way to know where is the error. I have remove many parts of the code, isolate the problem and thought that the problem was the hour conditions, but when I write them alone, no problem.
I’m getting crazy with this, and have expend 1 hour on this and still dont get it. Please help…
[code]function setTemp()
local maxTemp = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”, “CurrentTemperature”, 38)
maxTemp = tonumber(maxTemp)
local actTemp = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”, “CurrentTemperature”, 36)
actTemp = tonumber(actTemp)
local t = os.date(‘*t’)
local targetTemp = 74
if (outAlarmON == true) then
targetTemp = 79
else
if (t.hour >= 6) and (t.hour < 11) then
if (actTemp <= 68) then
targetTemp =72
else
targetTemp = 74
end
if (actTemp > 78) then
targetTemp =76
end
end
if (t.hour >= 11) and (t.hour < 15) then
if (actTemp <= 70) then
targetTemp =74
else
targetTemp = 76
end
if (actTemp > 84) then
targetTemp =78
end
end
if (t.hour >= 15) and (t.hour<20) then
if (actTemp <= 68) then
targetTemp =72
else
targetTemp = 74
end
if (actTemp > 85) then
targetTemp =76
end
end
if (t.hour >= 20) or (t.hour < 6) then
if (actTemp <= 65) then
targetTemp =70
else
targetTemp = 72
end
if (actTemp > 78) then
targetTemp =76
end
end
end – alarm
targetTemp = tostring(targetTemp)
luup.call_action(“urn:upnp-org:serviceId:TemperatureSetpoint1_Cool”, “SetCurrentSetpoint”, {NewCurrentSetpoint = targetTemp}, 33)
return targetTemp
end
local Temp = setTemp()
luup.log("++++++++++++ TEMP: " … Temp)
return true[/code]
This code uses the Wunderground Weather Plugin to get the max Temperature and Current Temperature in the City and based on that, decide the target Temperature I want in each time.
What I’m trying to do is safe energy adapting the temperature in each season.
The details of the error will be in the LuaUPnP.log file on Vera, and it’ll give you more clues.
The first thing I noticed was that [tt]outAlarmON[/tt] is not defined, so it’ll be nil and will error out when executing that code (not a syntax error though)
That is a global variable. When is nil is not a problem. Beside the problem is not running is just after save this code.
About the logs I use the web interface to see the errors. But can’t find any specific error in the logs.
If you are going to be serious about developing luup plugins you should test your code with a standalone lua interpretter. (Search Google for lua and windows)
You can always create dummy procedures to simulate the luup calls.
For example in the simulator you can do something like the following to simulate vera:
Then you can call your code and debug locally getting nice error messages.
Edit test cycles are seconds instead of minutes and hours!
It will not check that you have the right ServiceIDs and Variable Names … but it will test the rest of your logic.
I downloaded the Lua interpreter [url=http://code.google.com/p/luaforwindows/]Google Code Archive - Long-term storage for Google Code Project Hosting., by the way, everybody should download this and do what Richard said. It Makes the life easier. Even you can debug step by step.
I Loaded my code and added the code that Richard suggested. Add also the Variable_get
And run it step by step and it worked as expected.
The thing is I didn’t have to modify my code, for no reason now I was able to copy it into a test scene and worked as expected.
Well, thank you very much, I have learn a lot, and now have better tools to program with Lua.
I’ve read the above with interest, I was not expecting to find such info/guidance under a post title Global Functions UI5
Do you have to create a section for each of the ‘things’ (sorry not sure of the term) you want to test/make ? e.g one for luup.call_action, one for luup.variable_get etc?
Could this be the beginning of a Vera emulator? (If there is not already such a thing ?)
Also, is anyone aware of an ‘Lua Intepreter’ type app that works on the iPad?
Hi Parker,
Yes that is one of the problems. This forum is full of knowledge and some times you can find amazing things in unexpected places.
Thanks Richard I found this Lua Interpreter, that I really recommend. I have been using it for 2 days, and you can imagine how easy is everything to develop and test my code.
I should create a New Thread just with this Info.
About your comment, well I think an emulator will me much more than this. This is just to “compile” (it is interpreted) without error the same code I have in the Vera.
Of course, the problem, that is easy to solve is with get_variable, because if you want to test, you need to simulate logical values, or test cases. Then more than an emulator, would be better a Test Cases machine to test many scenarios.
Right now, I’m using the Debugger to test all the scenarios I want to control with my New Thermostat.
I’m trying to simulate the algorithm that “How I would set my air conditioning” in Summer or Winter or when I out of the house, based in the forecast temp and actual temperature.
To be honest it has been real fun for me.
But because of this, yesterday I can’t sleep because I set bad the temperature, and the Air conditioner was turning on all the night.
I wake up at 2 am and grab my iPad to change my algorithm, because if I change the temperature in then Thermostat, it will be overridden in half an hour.
Hello and hope this old topic will get some new attention,
Unfortunately I was not able to get an answer to the very question of the title - how to declare some of my functions as “global”, so they can get accessed in scenes, events, etc.
I did read all answers, I did downloaded some of referred plunges, I didn’t manage to see installed .lua.lz files, because they come as zero length files. I’ve tried declaring my lua file as a module, I’ve ‘require’-ed it in the scene, and still - no success.
So, really, how one can upload a simple LUA files of functions to be used elsewhere? Is it a must to have I_XXX.xml file?
I still receive these in the log:
“luup_require duplicate ih_Update” (ih_Update is my module name)
but later I receive:
“LuaInterface::CallFunction_Scene Scene 3 failed [string “function scene_2()…”]:21: attempt to call field ‘ih_UpdateDimmer’ (a nil value)”
and ih_UpdateDimmer does exist in the uploaded file.