Which action triggered my device ?

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

Moderator: leecollings

Post Reply
jpr105
Posts: 6
Joined: Friday 07 June 2019 10:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Which action triggered my device ?

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

Re: Which action triggered my device ?

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
jpr105
Posts: 6
Joined: Friday 07 June 2019 10:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Which action triggered my device ?

Post by jpr105 »

Thank you waaren

Fast and efficient. I will try asap ;)

Regards
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest