Get attribute from device

Easy to use, 100% Lua-based event scripting framework.
Post Reply
krzych
Posts: 7
Joined: Monday 11 December 2017 23:26
Target OS: -
Domoticz version:
Contact:

Get attribute from device

Post by krzych » Tuesday 17 April 2018 23:25

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 :(

User avatar
waaren
Posts: 613
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Get attribute from device

Post by waaren » Wednesday 18 April 2018 7:06

@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
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave , dzVents 2.4.n, Amazon echo

dannybloe
Posts: 1436
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: Get attribute from device

Post by dannybloe » Wednesday 18 April 2018 8:04

Once the whole rgbw shizzle becomes stable I will adjust the rgb device adapter to make this work out of the box.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

krzych
Posts: 7
Joined: Monday 11 December 2017 23:26
Target OS: -
Domoticz version:
Contact:

Re: Get attribute from device

Post by krzych » Thursday 19 April 2018 20:13

Thank you guys, working as expected.

Post Reply

Who is online

Users browsing this forum: papoo and 2 guests