controlling multiple devices at once

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

Moderator: leecollings

Post Reply
markjgabb
Posts: 142
Joined: Tuesday 24 January 2017 23:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: Australia
Contact:

controlling multiple devices at once

Post by markjgabb »

hey all im interested in controlling multiple devices at once... i tried the below code, but only the first device is controlled
any tips on why one is working but the other is not?
i know its something wrong with the local HallLight.... but im not sure why it doesnt apply correctly

Code: Select all


return {
	on = {
		devices = {['Loungeroom motion sensor'] =  {'at nighttime'}}
		
	},
	execute = function(dz, item, device)
	    local moodLight = dz.devices('Mood Light')
	    local HallLight = dz.devices(10,11)
        local delay = 120
	--	dz.log('Device ' .. device.name .. ' was changed', dz.LOG_INFO)
		if item.state == 'On' then
		    if item.active then
            if dz.time.matchesRule('between 23:00 and sunrise') then
                moodLight.cancelQueuedCommands()
                moodLight.dimTo(15)
                moodLight.switchOff().afterSec(delay)
                HallLight.cancelQueuedCommands()
                HallLight.dimTo(15)
                HallLight.switchOff().afterSec(delay)
            else
                moodLight.dimTo(100)
                moodLight.switchOff().afterSec(delay)
                HallLight.dimTo(100)
                HallLight.switchOff().afterSec(delay)
            end
    end
end
end
    
}
V 2020.2 RPI 3
RFlink 334 mhz
mysensors
broadlink
Mirabella Genio Globes
hestia
Posts: 357
Joined: Monday 25 December 2017 23:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Paris
Contact:

Re: controlling multiple devices at once

Post by hestia »

local HallLight = dz.devices(10,11)
10,11 ?!?
maybe 10 or 11, not both...
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: controlling multiple devices at once

Post by waaren »

markjgabb wrote: Sunday 26 July 2020 13:25 I know its something wrong with the local HallLight.... but im not sure why it doesnt apply correctly

Code: Select all

	    local HallLight = dz.devices(10,11)
You cannot assign two devices to one variable using above syntax.

Can you try this ?

Code: Select all

return
{
    on =
    {
        devices =
        {
            ['Loungeroom motion sensor'] =
            {
                'at nighttime',
            },
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when al OK
        marker = 'Loungeroom motion',
    },

    execute = function(dz, item)

        if item.active then
             local allLights =   {
                                dz.devices('Mood Light'),
                                dz.devices(10),
                                dz.devices(11),
                            }
            local delay = 120

            dimLevel = dz.time.matchesRule('between 23:00 and sunrise') and 15 or 100
            for _, dv in ipairs(allLights) do
                dv.cancelQueuedCommands()
                dv.dimTo(dimLevel)
                dv.dimTo(0).afterSec(delay)
            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
markjgabb
Posts: 142
Joined: Tuesday 24 January 2017 23:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: Australia
Contact:

Re: controlling multiple devices at once

Post by markjgabb »

hey that works... makes script alot smaller too thank you
V 2020.2 RPI 3
RFlink 334 mhz
mysensors
broadlink
Mirabella Genio Globes
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest