Page 1 of 1

Get attribute from device

Posted: Tuesday 17 April 2018 23:25
by krzych
Hello guys,

How can i retrive color only attribute from my virtual rgb switch ?

So far i see it under dump function

domoticz.devices('Yeelight vswitch').dump() =>

...
dzVents: > color: {"b":255,"cw":0,"g":243,"m":3,"r":171,"t":0,"ww":0}
...

Final result i would like to have rgb as different variables, i believe it may be trivial but i'm not soo good at LUA yet :(

Re: Get attribute from device

Posted: Wednesday 18 April 2018 7:06
by waaren
@krzych

probably the easiest way here is to use the builtin function of dzVents utils.

Code: Select all

return {
	on = { devices = { 'your RGB device'} },
	
	execute = function(dz, device)
		if device.color ~= nil then
		    	rt  = dz.utils.fromJSON(device.color)                                           -- rt = result table
	        	dz.log('Device ' .. device.name .. ': red   ==>> ' .. rt.r, dz.LOG_INFO)
	        	dz.log('Device ' .. device.name .. ': green ==>> ' .. rt.g, dz.LOG_INFO)
	        	dz.log('Device ' .. device.name .. ': blue  ==>> ' .. rt.b, dz.LOG_INFO)
		else
			dz.log('Device ' .. device.name .. ': No color available (device might be off or wrong type) ' , dz.LOG_INFO)
		end
	end
}

Re: Get attribute from device

Posted: Wednesday 18 April 2018 8:04
by dannybloe
Once the whole rgbw shizzle becomes stable I will adjust the rgb device adapter to make this work out of the box.

Re: Get attribute from device

Posted: Thursday 19 April 2018 20:13
by krzych
Thank you guys, working as expected.