Which device triggers the scrip?  [Solved]

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

Moderator: leecollings

Post Reply
iganin
Posts: 47
Joined: Tuesday 28 October 2014 17:55
Target OS: NAS (Synology & others)
Domoticz version: 2020.2
Location: Aalter, Belgium
Contact:

Which device triggers the scrip?

Post 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?
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Which device triggers the scrip?

Post by EddyG »

Use dzVents and you can find the trigger devices by name.
The first 2 post explain more.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Which device triggers the scrip?  [Solved]

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest