Page 1 of 1

Which action triggered my device ?

Posted: Wednesday 07 April 2021 18:31
by jpr105
Hello,

For my automated watering I have 4 electrovalves corresponding to my 4 watering zones.
Each electrovalve can be controlled either :
  • manually via the smartphone
  • for a specific duration via a scenario
  • within the framework of a weekly schedule
My question is the following:
In the dZVents language, is it possible to know HOW my electrovalve has been activated?
Thank you in advance for your help
Regards - Jean-Paul

Re: Which action triggered my device ?

Posted: Wednesday 07 April 2021 19:27
by waaren
jpr105 wrote: Wednesday 07 April 2021 18:31 s it possible to know HOW my electrovalve has been activated?
Not natively but below script (using sqlite3 to access the domoticz database) will show you the last actor of the device.

Code: Select all

--[[
        triggerinfo.lua

        requires:   sqlite3
                    dzVents  >= 3.0.13
                    domoticz >= V2020.2 build 12693

]]

return
{
    on =
    {
        devices =
        {
            'myDevice', -- Change to device you need to monitor
            'eventTrigger',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when script is tested and OK
        marker = 'getActor',
    },

    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 ..  ' triggered me at ' ..  modTime,dz.LOG_FORCE)

            else
                dz.log( 'No data in LightingLog for device ' .. item.name,dz.LOG_DEBUG)
            end
        end
    end
}

Re: Which action triggered my device ?

Posted: Wednesday 07 April 2021 20:27
by jpr105
Thank you waaren

Fast and efficient. I will try asap ;)

Regards