Choose between two devices

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

Moderator: leecollings

Post Reply
HvdW
Posts: 535
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Choose between two devices

Post 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?
Bugs bug me.
User avatar
waltervl
Posts: 5391
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Choose between two devices

Post by waltervl »

I think something like

elseif (item.isDevice and item.name == 'myDetector_1')
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
HvdW
Posts: 535
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Choose between two devices

Post 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
Bugs bug me.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest