Syntax examples wiki  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
jkimmel
Posts: 129
Joined: Monday 25 November 2013 17:51
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Mallorca
Contact:

Syntax examples wiki  [Solved]

Post by jkimmel »

Code: Select all

return
{
    on =
    {
        devices = {
            'myDetector',
            'roomTemp'
    }
},
    execute = function(domoticz, device)
        if ((device.name == 'myDetector' and device.active) or
            (device.name == 'roomTemp' and device.temperature >= 45)) then
            domoticz.notify('Fire', 'The room is on fire', domoticz.PRIORITY_EMERGENCY)
        end
    end
}
Is the comma after 'myDetector correct?

And is a comma missing after

Code: Select all

  {
        devices = {
            'myDetector',
            'roomTemp'
    }
Rfxcom
Raspi 4
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Syntax examples wiki

Post by waaren »

jkimmel wrote: Saturday 16 May 2020 11:58
Is the comma after 'myDetector correct?
Yes
And is a comma missing after
No

devices is here the name of a table and myDetector and roomTemp are values in that table. Values in a table constructor are separated by a comma or a semicolon.

In Lua (dzVents = Lua) "you can always put a comma after the last entry. These trailing commas are optional, but are always valid:"
source


Below constructor examples are all valid

Code: Select all

myTable = {x=10, y=45; "one", "two", "three"} 

print (myTable[1]) -- > one
print (myTable.x)--> 10

myTable = { ["domoticz scripting framework"] =  "dzVents"  }

print (myTable["domoticz scripting framework"]) --> dzVents

myTable = { scriptTypes = { "blockly" ;  "python", "dzvents", "Lua" ,},  }

print (myTable.scriptTypes[2]) --> python
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest