one command to multiple devices..

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

Moderator: leecollings

Post Reply
OedzesG
Posts: 106
Joined: Monday 11 March 2019 0:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

one command to multiple devices..

Post 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.. :(
OedzesG
Posts: 106
Joined: Monday 11 March 2019 0:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: one command to multiple devices..

Post 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 
	} 
OedzesG
Posts: 106
Joined: Monday 11 March 2019 0:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: one command to multiple devices..

Post by OedzesG »

@ waaren ( I think I have the best chance with you :D )

in some cases i use the function openURL to update devices, you know how to handel with .foreach?
Last edited by OedzesG on Monday 10 February 2020 10:53, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: one command to multiple devices..

Post 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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
OedzesG
Posts: 106
Joined: Monday 11 March 2019 0:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: one command to multiple devices..

Post 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.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: one command to multiple devices..

Post 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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
OedzesG
Posts: 106
Joined: Monday 11 March 2019 0:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: one command to multiple devices..

Post 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&param=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&param=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&param=setcolbrightnessvalue&idx='..
        zolder_spot_3 ..
        '&color={"m":3,"r":' .. 
        red_level ..
	',"g":' ..
	green_level ..
	',"b":' ..
	blue_level ..
        '}&brightness=' .. 
        dim_level 
        )
		
	end

}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: one command to multiple devices..

Post 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&param=setcolbrightnessvalue&idx=' .. idx .. color )
        end
        
        for _, idx in ipairs(spots) do
            sendColor(idx)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
OedzesG
Posts: 106
Joined: Monday 11 March 2019 0:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: one command to multiple devices..

Post 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 :D )

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...
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest