Page 1 of 1

Notify with Username

Posted: Thursday 17 December 2020 13:01
by LeNouveau
Hi,

I would like, when someone opens the garage through the API, to be notified with its username.

I can see the username in the logs, when I watch the garage's history.
But I did not find how to pass this username to my script.

Do someone have information on this point ?

Regards,
LeNouveau

PS : I don't really care about the script language, I can adapt if required.

Re: Notify with Username

Posted: Thursday 17 December 2020 13:42
by waaren
LeNouveau wrote: Thursday 17 December 2020 13:01 I would like, when someone opens the garage through the API, to be notified with its username.
Can you check this?
__________________________________________________________________________________________________________________________
When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents enabled' is checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."
___________________________________________________________________________________________________________________________

Code: Select all

--[[
        triggerinfo.lua
        
        requires:   sqlite3
                    dzVents  >= 3.0.13
                    domoticz >= V2020.2 build 12693 

]]
return
{
    on =
    {
        devices =
        {
            'triggerInfo', -- name of device(s) to be notified on
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'trigger Info', 
    },

    execute = function(dz, item)

        local function getLightingLogData(id)
            local _,rc = dz.utils.osCommand('which sqlite3')
            if rc == 0 then
                local cmd = 'sudo sqlite3  -list -noheader domoticz.db "SELECT DeviceRowID ID, User, Date FROM LightingLog WHERE DeviceRowID = ' .. id .. ' ORDER BY Date  DESC LIMIT 1;" '
                return dz.utils.osCommand(cmd)
            else
                dz.log('sqlite3 not available. Please make sure it is installed (sudo apt install sqlite3) and accessible', dz.LOG_ERROR)
            end
        end
        
        -- main 
        if item.active then
            local lightingLogLine = getLightingLogData(item.id)
            if lightingLogLine:find('|') then 
                local lightingLogLineTable = dz.utils.stringSplit( getLightingLogData(item.id) ,'|')
                local user = lightingLogLineTable[2]
                local modTime = lightingLogLineTable[3]
                dz.log( 'user: '.. user ..  ' opened me at ' ..  modTime,dz.LOG_DEBUG)
                dz.notify(item.name, user ..  ' opened me at ' ..  modTime)
            else
                dz.log( 'Unexpected result from sqlite3 .. ' .. tostring(lightingLogLine),dz.LOG_ERROR)
            end
        end
    end
}

Re: Notify with Username

Posted: Thursday 17 December 2020 14:02
by LeNouveau
Hi,

This looks promising. :)

Thank you.