Page 1 of 1

Choose between two devices

Posted: Friday 22 November 2024 19:44
by HvdW
From the wiki.

Code: Select all

return {
    on = {
            timer = { 'every 5 minutes' },
            devices = { 'myDetector' }
    },
    execute = function(domoticz, item)
        if (item.isTimer) then
            -- the timer was triggered
            domoticz.devices('myLamp').switchOff()
        elseif (item.isDevice and item.active) then
            -- it must be the detector
            domoticz.devices('myLamp').switchOn()
        end
    end
}
In my case there are two devices

Code: Select all

[code]return {
    on = {
            timer = { 'every 5 minutes' },
            devices = { 'myDetector_1', 'myDetector_2' }
    },
    execute = function(domoticz, item)
        if (item.isTimer) then
            -- the timer was triggered
            domoticz.devices('myLamp').switchOff()
        elseif (item.isDevice and device is myDetector_1) then  -- here I want to know which device it is
            -- it must be the detector
            domoticz.devices('myLamp_1').switchOn()
        elseif (item.isDevice and device is myDetector_2) then  -- here I want to know which device it is
            -- it must be the detector
            domoticz.devices('myLamp_2').switchOn()
        end
    end
}
[/code]
How can I know which device activated the script?

Re: Choose between two devices

Posted: Friday 22 November 2024 20:58
by waltervl
I think something like

elseif (item.isDevice and item.name == 'myDetector_1')

Re: Choose between two devices

Posted: Friday 22 November 2024 21:22
by HvdW
waltervl wrote: Friday 22 November 2024 20:58 I think something like

elseif (item.isDevice and item.name == 'myDetector_1')
How simple.
Thanks @Walter