Hello all,
Fairly new to Vera still but come from a decent programming background so I am slowly getting into it now that I have some free time!
I have a couple of questions regarding Lua in scenes.
Im working on a script that will manage my thermostat based on a few different variables. However, I’m curious on the best way to trigger this.
Is it normal to have the scene scheduled to run say every 15 minutes (for example)? What sort of load will this put on the Vera controller?
Im also curious, if I do go that route and trigger every 15 minutes, say in the Lua code I check the thermostats current inside temperature. Will the code actually poll the thermostat for the info, or will it just get the last reading from the controller itself?
Is it normal to have the scene scheduled to run say every 15 minutes (for example)? What sort of load will this put on the Vera controller?This should not be any significant load. If it did, your Vera would not be much of a controller.
Will the code actually poll the thermostat for the info, or will it just get the last reading from the controller itself?luup.variable_get will get the latest value of the variable as known to Vera. It will not cause a device poll to get the latest device value. Most Z-Wave thermostats push their latest value .. so Vera's values should be up to date.
You could also put luup.variable_watch on your thermostat temperature and other important properties in your Vera LUA startup script and have that trigger your script as opposed to a putting the code in a scene and triggering it from a timer/schedule.
You can also try programming this in PLEG … With the reports it’s easier to see what is going on with the logic.
Perfect, thanks for the reply, and thanks for the tip about luup.variable_get.
luup.variable_watch sounds useful. Would the idea to be create a function in a lua file, upload the file to the Vera, then in the startup script call that function using luup.variable_watch? Sounds a lot more efficient then using a timer for sure, but just want to make sure I’m understanding your suggestion ;D
An additional question, is there anyway to get the outside temperature variable from Vera (since its displayed in the top right corner, it must be stored somewhere), or is an additional plugin such as WUnderground needed?
You can put all your code in the LUA startup script.
I prefer to use LUA files.
Your startup script can load the LUA file.
NOTE: If you put functions in a LUA file … they are not availabe in the GLOBAL Name context.
luup.variable_watch expects to find the name in the GLOBAL Name context.
In an LUA code module you can put a function in the GLOBAL Name context as follows:
function SomeFunction()
end
_G.SomeFunction = SomeFunction
luup.variable_watch( … “SomeFunction”)
If you enter the code directly into the Startup LUA window … the functions WILL be defined in the GLOBAL Name context.
I use the Weather Underground to get at my Weather Info. I have not looked into where UI7 gets the current outside temp. I have my own Weather station and I want Vera to use that info.
Im trying to avoid putting the code in the startup script itself, as some of the stuff I have in mind could potentially get large down the road.
I think I understand what you’re saying now.
Create my lua script, then just load it in the startup script with:
require “my_lua_script”
Does that sound about right?
(Sorry I come from PHP and Java, so Lua and the Vera; while seemingly easy to pick up; are still fairly new to me)