Page 1 of 1
one command to multiple devices..
Posted: Sunday 09 February 2020 20:27
by OedzesG
hallo,
is there a way to send one command to multiple devices?
for example: one light-setting command to 3 diverent bulbs? instead of writing 3 times olmost the same code with diverent IDX numbers.
Code: Select all
return {
active = true,
on = { devices = {38}
},
logging = { level = domoticz.LOG_DEBUG
},
execute = function(dz, item)
if item.state == 'On' then
dz.devices(12).setColor(0,0,0, item.level, 0, 255, 2, 255).silent()
dz.devices(14).setColor(0,0,0, item.level, 0, 255, 2, 255).silent()
dz.devices(16).setColor(0,0,0, item.level, 0, 255, 2, 255).silent()
else
dz.devices(12).switchOff().silent()
dz.devices(14).switchOff().silent()
dz.devices(16).switchOff().silent()
end
end
}
i try to do something like this:
Code: Select all
dz.devices(12, 14, 16).setColor(0,0,0, item.level, 0, 255, 2, 255).silent()
but its not working..

Re: one command to multiple devices..
Posted: Sunday 09 February 2020 22:36
by OedzesG
Found solutuion....
Code: Select all
-- ************************************************** --
-- ** Group livingRoom Lights ** --
-- ************************************************** --
local group_dimmer = 38
local group_devices = {12, 14, 16}
return {
active = true,
on = { devices = {group_dimmer}
},
logging = { level = domoticz.LOG_ERROR
},
execute = function(dz, item)
local group = dz.devices().filter(group_devices)
if item.state == 'On' then
group.forEach(function(myGroup)
myGroup.setColor(0,0,0, item.level, 0, 255, 2, 255).silent() end)
else
group.forEach(function(myGroup)
myGroup.switchOff().silent() end)
end
end
}
Re: one command to multiple devices..
Posted: Monday 10 February 2020 10:16
by OedzesG
@ waaren ( I think I have the best chance with you

)
in some cases i use the function openURL to update devices, you know how to handel with .foreach?
Re: one command to multiple devices..
Posted: Monday 10 February 2020 10:50
by waaren
OedzesG wrote: Monday 10 February 2020 10:16
in some cases i use the function openURL to update devices, you know how to handle?
Can you please explain why you are not using native dzVents commands and show an example ?
Re: one command to multiple devices..
Posted: Monday 10 February 2020 10:56
by OedzesG
Can you please explain why you are not using native dzVents commands and show an example ?
some devices are on another domoticz installation inside the network.
Re: one command to multiple devices..
Posted: Monday 10 February 2020 11:05
by waaren
OedzesG wrote: Monday 10 February 2020 10:56
Can you please explain why you are not using native dzVents commands and show an example ?
some devices are on another domoticz installation inside the network.
Can you show the script you are using now as an example ?
Re: one command to multiple devices..
Posted: Monday 10 February 2020 11:27
by OedzesG
Can you show the script you are using now as an example ?
this is one of them...
Code: Select all
-- scéne zolder lampen
local zolder_scene_switch = 43 -- idx scéne pushOnn button
local zolder_spot_1 = 88 -- idx zolder lamp 1
local zolder_spot_2 = 89 -- idx zolder lamp 2
local zolder_spot_3 = 90 -- idx zolder lamp 3
return {
active = true,
on = { devices = {zolder_scene_switch} },
execute = function(dz, item)
red_level = '200'
green_level = '25'
blue_level = '68'
dim_level = '15'
dz.openURL (
'http://192.168.1.5:8085/json.htm?type=command¶m=setcolbrightnessvalue&idx='..
zolder_spot_1 ..
'&color={"m":3,"r":' ..
red_level ..
',"g":' ..
green_level ..
',"b":' ..
blue_level ..
'}&brightness=' ..
dim_level
)
dz.openURL (
'http://192.168.1.5:8085/json.htm?type=command¶m=setcolbrightnessvalue&idx='..
zolder_spot_2 ..
'&color={"m":3,"r":' ..
red_level ..
',"g":' ..
green_level ..
',"b":' ..
blue_level ..
'}&brightness=' ..
dim_level
)
dz.openURL (
'http://192.168.1.5:8085/json.htm?type=command¶m=setcolbrightnessvalue&idx='..
zolder_spot_3 ..
'&color={"m":3,"r":' ..
red_level ..
',"g":' ..
green_level ..
',"b":' ..
blue_level ..
'}&brightness=' ..
dim_level
)
end
}
Re: one command to multiple devices..
Posted: Monday 10 February 2020 12:33
by waaren
OedzesG wrote: Monday 10 February 2020 11:27
this is one of them...
I would use something like below (I have not checked the syntax of the API call)
Code: Select all
-- scéne zolder lampen
local zolder_scene_switch = 43 -- idx scéne pushOnn button
return {
active = true,
on = { devices = {zolder_scene_switch} },
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'send Color',
},
execute = function(dz, item)
local spots = {88, 89, 90}
local function sendColor(idx)
local red_level = '200'
local green_level = '25'
local blue_level = '68'
local dim_level = '15'
local color = '&color={"m":3' .. ',r":' .. red_level .. ',"g":' .. green_level ..',"b":' .. blue_level .. '}' .. '&brightness=' .. dim_level
dz.openURL('http://192.168.1.5:8085/json.htm?type=command¶m=setcolbrightnessvalue&idx=' .. idx .. color )
end
for _, idx in ipairs(spots) do
sendColor(idx)
end
end
}
Re: one command to multiple devices..
Posted: Tuesday 11 February 2020 15:46
by OedzesG
I would use something like below
Thnx again waaren!
works great.. now i simply can manage a group, i had some idea to make a pusch button with a diverent scene every time i hit the button..
for start i did some test with diverent brighness level... ( first time working with data

)
Code: Select all
----------------------------------------------------------------------------------
-- test puschOnn button with multi brightness level - color wamrWhite --
----------------------------------------------------------------------------------
local scene_switch = 48
local group_test = {30, 10, 32}
return {
active = true,
on = { devices = {scene_switch}
},
logging = { level = domoticz.LOG_DEBUG,
},
data = { brightness = { initial = 0 },
counter = { initial = 0 }
},
execute = function(dz, item)
if dz.data.counter == 5 then dz.data.counter = 0 else
dz.data.counter = dz.data.counter + 1
if dz.data.counter == 1 then dz.data.brightness = 1 else
dz.data.brightness = dz.data.counter * 20
local function updateGroup(idx)
dz.devices(idx).setColor(0,0,0, dz.data.brightness, 0, 255, 2, 255).silent() end
for _, idx in ipairs(group_test) do
updateGroup(idx) end
end
}
just to share, maybee the ideaa can fit to some of youre needs...