Notify with Username

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
LeNouveau
Posts: 2
Joined: Thursday 17 December 2020 12:53
Target OS: -
Domoticz version:
Contact:

Notify with Username

Post 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.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Notify with Username

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
LeNouveau
Posts: 2
Joined: Thursday 17 December 2020 12:53
Target OS: -
Domoticz version:
Contact:

Re: Notify with Username

Post by LeNouveau »

Hi,

This looks promising. :)

Thank you.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest