Page 1 of 1
Convert to LUA, LUA Beginner
Posted: Thursday 25 January 2018 9:24
by straatm
All,
I tried already a various number of options, surfed the forum but I always end up with not finding the correct information.
I try to learn LUA scripting so first of all I search for a beginners explanation of LUA scripting I am familiar with programming. But not with all the parameters and function calls in LUA.
If someone has a good startingpoint that would help me a lot.
And maybe someone is willing to convert the Blocky I present below to a LUA script for my reference. Maybe I can go from there to learn the LUA scripting.
Thanks for your help!
BR,
Marc

- Buiten-verlichting.jpg (285.17 KiB) Viewed 1206 times
Re: Convert to LUA, LUA Beginner
Posted: Thursday 25 January 2018 9:51
by waaren
If you are only going to use LUA in the domoticz environment, you should investigate if dzVents is suited for you. The wiki is an excellent starting point for that.
https://www.domoticz.com/wiki/DzVents:_ ... _scripting
My experience is that it will make LUA coding much easier to do, -understand and maintain by hiding all the complicated structures under the hood. In the end it is pure LUA but an enormous amount of work is already done for you.
Re: Convert to LUA, LUA Beginner
Posted: Friday 26 January 2018 18:21
by triton
First steps in programming in general? What Waaren is saying is true. dzVents will be a lot more friendly then LUA. I got most of my scripts ported over to dzVents now.
That however does not answer your request. I can't give any guaranties that the Lua code below will work. I just wrote it reading your blocky info. DId not test it, don't have your setup. Tried to keep it as close to your orginal for learning purpose. Hope it helps.
Code: Select all
commandArray = {}
local timenow = os.date("*t")
local minutesnow = timenow.min + timenow.hour * 60
local dm0700 = 7 * 60
local dm2200 = 22 * 60
if (minutesnow > dm0700 and minutesnow < timeofday['SunriseInMinutes']) or
(minutesnow > timeofday['SunsetInMinutes'] and minutesnow < dm2200) or
otherdevices['UitNax'] == 'On' then
commandArray['Group:Buiten-Lampen'] = 'On'
elseif otherdevices['Laat-Thuis'] == 'On' and otherdevices['UitNax'] == 'Off' then
commandArray['Laat-Thuis'] = 'Off AFTER 30'
commandArray['UitNax'] = 'On FOR 60'
commandArray['Group:Buiten-Lampen'] = 'On'
elseif otherdevices['Laat-Thuis'] == 'Off' and otherdevices['UitNax'] == 'Off' then
commandArray['Group:Buiten-Lampen'] = 'Off'
elseif minutesnow < dm0700 or minutesnow > dm2200 and otherdevices['UitNax'] == 'Off' then
commandArray['Group:Buiten-Lampen'] = 'Off'
end
return commandArray
Re: Convert to LUA, LUA Beginner
Posted: Sunday 28 January 2018 0:32
by Eoreh
dzVenst is very simple. Look also on new module for compact and simple syntax

- eg10.png (85.55 KiB) Viewed 1140 times
In this sytext script is very short. You can download and read about it here
viewtopic.php?f=59&t=21914