Learn LUA for Domoticz

Moderator: leecollings

Post Reply
Evelen
Posts: 234
Joined: Thursday 09 July 2015 12:03
Target OS: Linux
Domoticz version: 2.4538
Location: Norway
Contact:

Learn LUA for Domoticz

Post by Evelen »

I can se Blockly now is just too limited to do the home automation on.
So I have to choises, buy the very expensive HomeSeer to replace Domoticz, or learn LUA.
The problem is that I do not have much programmering experience, yust a little powershell (windows) and batch (windows), but not much more.

So how to learn it? And not just in general, but for use with Domoticz.

Maybe first just like "If BUTTON1 = off and TEMP < 20C set BUTTOM2 = on"
But also like "If ENERGY > 10W for 10 minutes turn BUTTON2 off"
and like: "If BUTTON1= off Set BUTTON2 = off, else if BUTTON1=on set BUTTON2= on"

And things like that?

I think some easy examples and description of what all the commands and symbols in the script do will helt alot.
Eks: I see many people write "commandArray" someplaces in the script, what does that meen?

EDIT: Got this to work :D

Code: Select all

commandArray = {}
if (devicechanged['1 - Stue, Stålampe'] == 'On') then 
   commandArray['21 - Kjøkken, Taklampe']='On'
end
return commandArray
But why does this meen:
commandArray = {}

and this:
return CommandArray
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Learn LUA for Domoticz

Post by Egregius »

I think PHP is easier to learn and it can do much more then lua in a simpler way and it's even faster.
simonrg
Posts: 329
Joined: Tuesday 16 July 2013 22:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8807
Location: North East England
Contact:

Re: Learn LUA for Domoticz

Post by simonrg »

Evelen wrote:

Code: Select all

commandArray = {}
if (devicechanged['1 - Stue, Stålampe'] == 'On') then 
   commandArray['21 - Kjøkken, Taklampe']='On'
end
return commandArray
But why does this meen:
commandArray = {}

and this:
return commandArray
commandArray = {}
is simply defining an empty list, then
return commandArray
is giving the list, which you have now written commands into, back to Domoticz, so Domoticz can execute those commands.

It would worthwhile reading some introductory information on Lua, so you have an idea of the way in which it handles data, the fact it is case sensitive so Commandarray is a different variable to commandArray etc..

Code: Select all

https://awesome.naquadah.org/wiki/The_briefest_introduction_to_Lua
Then have a look around the Wiki there are quite a lot of commented scripts and information on how Lua works with Domoticz - probably start with http://www.domoticz.com/wiki/Domoticz_and_Scripting and then have a look at

Code: Select all

http://www.domoticz.com/wiki/Events
.

Personally, I think Lua is probably the eaisest scripting to start with Domoticz, as your script shows Domoticz does all the set up for you and is well linked to Lua. I came from classic computer languages like Pascal / DOS-Windows scriptting etc. with little web programming experience and learning Lua purely to use with Domoticz and found it not too hard. However, Lua is quite clever so things like being able to have '1 - Stue, Stålampe' as index (key) to an array are very powerful.

Obviously if you already knew another language then that would be easier. Python / Php all look more difficult to me, but I would any hints in forum posts or Wiki articles on how to get started would be great.
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Learn LUA for Domoticz

Post by dannybloe »

Just take a look at dzVents. Very easy and lots of documentation and examples.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest