dzVents and SQL

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

Moderator: leecollings

Post Reply
ChrisKerswell
Posts: 12
Joined: Sunday 17 December 2017 3:05
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

dzVents and SQL

Post by ChrisKerswell »

Hi,

Is there any way to use dzVents to run SQL queries directly on the database?

I tried to search the forum for this but the search ignores "SQL" because it is less than four characters :|
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents and SQL

Post by waaren »

ChrisKerswell wrote: Friday 24 August 2018 1:17 Hi,

Is there any way to use dzVents to run SQL queries directly on the database?

I tried to search the forum for this but the search ignores "SQL" because it is less than four characters :|
Not natively but via popen it can be done

Code: Select all

return {
    
   on = { devices = { "your trigger device" }},
        
  logging =   {   level     =   domoticz.LOG_DEBUG,
                  marker    =   "dataBase query"      },
    
    execute = function(dz)
        local command = 'sqlite3 tempdatabase.db \"select distinct(DeviceRowID) from Temperature_Calendar\" ' 
        local handle = assert(io.popen(command))
        for line in handle:lines() do
            dz.log(line,dz.LOG_DEBUG)
        end
        handle:close()
    end
}
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 0 guests