converting LUA to dzvents

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

Moderator: leecollings

Post Reply
multinet
Posts: 97
Joined: Friday 05 December 2014 22:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

converting LUA to dzvents

Post 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
PI 2 - Domoticz 2021.1
RFXCOM - RFXtrx433 USB 433.92MHz Transceiver (5 DIO 54755 + 2 DIO 54756 + 3 DIO 54798)
Z-Wave.Me ZME_UZB1 USB Stick (6 FGSD002 + 2 FGRM222 + 1 FGS223 + 1 FGMS001-ZW5 + 1 FGRGBWM441 + 1 FGBS001 + 2 FGFS101)
6 sondes DS18B20
multinet
Posts: 97
Joined: Friday 05 December 2014 22:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: converting LUA to dzvents

Post by multinet »

Re,

My question is about os.capture more precisely

Thanks
PI 2 - Domoticz 2021.1
RFXCOM - RFXtrx433 USB 433.92MHz Transceiver (5 DIO 54755 + 2 DIO 54756 + 3 DIO 54798)
Z-Wave.Me ZME_UZB1 USB Stick (6 FGSD002 + 2 FGRM222 + 1 FGS223 + 1 FGMS001-ZW5 + 1 FGRGBWM441 + 1 FGBS001 + 2 FGFS101)
6 sondes DS18B20
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: converting LUA to dzvents

Post 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
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: No registered users and 1 guest