Page 1 of 1

converting LUA to dzvents

Posted: Saturday 18 August 2018 11:29
by multinet
Hello i'm considering converting my lua scripts to dzvents

but I don't know how this lua command should be converted :

Code: Select all

        val_QPluieV=os.capture('sqlite3 '..dbPath..' "select TOTAL as TOTAL from Rain_Calendar where devicerowid='..otherdevices_idx[dev_Pluviometre]..' and Date = date(\'now\', \'-1 day\')"')
This is to open the domoticz database and to execute an SQL request

Thanks !
Multinet

Re: converting LUA to dzvents

Posted: Saturday 18 August 2018 11:37
by multinet
Re,

My question is about os.capture more precisely

Thanks

Re: converting LUA to dzvents

Posted: Saturday 18 August 2018 12:54
by waaren
multinet wrote: Saturday 18 August 2018 11:29 Hello i'm considering converting my lua scripts to dzvents

but I don't know how this lua command should be converted :

Code: Select all

        val_QPluieV=os.capture('sqlite3 '..dbPath..' "select TOTAL as TOTAL from Rain_Calendar where devicerowid='..otherdevices_idx[dev_Pluviometre]..' and Date = date(\'now\', \'-1 day\')"')
This is to open the domoticz database and to execute an SQL request

Thanks !
Multinet
The os.capture does not really need to be converted. It is not a standard lua function but more a wrapper around io.popen
somewhere in your current code the function must be defined like something as

Code: Select all

    function os.capture(cmd, raw)
          local f = assert(io.popen(cmd, 'r'))
          local s = assert(f:read('*a'))
          f:close()
          if raw then return s end
          s = string.gsub(s, '^%s+', '')
          s = string.gsub(s, '%s+$', '')
          s = string.gsub(s, '[\n\r]+', ' ')
          return s
    end
you can just use it in dzVents as you use it now in lua (dzVents IS Lua)
The part that need to be converted to dzVents syntax is

Code: Select all

otherdevices_idx[dev_Pluviometre]
That need to change to

Code: Select all

domoticz.devices(dev_Pluviometre).idx