Page 1 of 1

Which device triggers the scrip?

Posted: Friday 05 June 2020 15:39
by iganin
I planning to write a script with multiple devices (i.e switches) in the selection field.
A question. How to detect, using if logic, which one triggers the script?

Re: Which device triggers the scrip?

Posted: Friday 05 June 2020 16:07
by EddyG
Use dzVents and you can find the trigger devices by name.
The first 2 post explain more.

Re: Which device triggers the scrip?  [Solved]

Posted: Friday 05 June 2020 16:59
by waaren
iganin wrote: Friday 05 June 2020 15:39 I planning to write a script with multiple devices (i.e switches) in the selection field.
A question. How to detect, using if logic, which one triggers the script?
If you insist on using if logic (if logic is not needed to identify which device triggered the script) you can use something like below.

Code: Select all

return
{
    on =
    {
        devices =
        {
            'deviceA',
            'deviceB',
        },
    },

    logging =
    {
        level = domoticz.LOG_INFO,
        marker = 'trigger identifyer',
    },

    execute = function(dz, item)

        local deviceA = dz.devices('deviceA')
        local deviceB = dz.devices('deviceB')

        if item == deviceA then
            dz.log('script was triggered by deviceA',dz.LOG_INFO)
        elseif item == deviceB then
            dz.log('script was triggered by deviceB',dz.LOG_INFO)
        end
    end
}