Get color of RGBW device in dzVents  [Solved]

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

Moderator: leecollings

Sateetje
Posts: 24
Joined: Monday 07 December 2015 15:22
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Get color of RGBW device in dzVents

Post by Sateetje »

I've the same problem with a RGBW switch. The print shows the old values, I don't know why it shows the old values. Doesn't make sense.

It sends to a MySensors node, using S_INFO

Is there a bug submitted?

Quick fix, not a nice one...

Code: Select all

return {
	on = {
		devices = {
			'Klokje - Verlichting'
		}
	},
        data = {
            state = { initial = 0 }
    },
	execute = function(domoticz, device)
	    local klokVerlichting = domoticz.devices('Klokje - Verlichting')

        if (domoticz.data.state == 0) then
            klokVerlichting.switchOn().afterSec(0.3)
            
            domoticz.data.state = 1
        elseif (domoticz.data.state == 1) then
            colorTable = domoticz.utils.fromJSON(klokVerlichting.color)

        	local dataToSend = ''
        	
        	--if (colorTable.ww > 0) then
        	--    dataToSend = '#000000' .. string.format("%x", colorTable.ww)
        	--else
        	--    dataToSend = string.format("%x", colorTable.r) .. string.format("%x", colorTable.g) .. string.format("%x", colorTable.b)     
        	--end

            dataToSend = colorTable.r .. '.' .. colorTable.g .. '.' .. colorTable.b .. '.' .. colorTable.ww .. '.' .. klokVerlichting.level
            
            print(dataToSend)
            
        	domoticz.devices('Klokje - Text').updateText(dataToSend)
        	
            domoticz.data.state = 0
        else
            domoticz.data.state = 0
        end
    
    end
}
Sateetje
Posts: 24
Joined: Monday 07 December 2015 15:22
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Get color of RGBW device in dzVents

Post by Sateetje »

Using an API call will "solve" the problem.

Code: Select all

return {
	on = {
		devices = {
			'Klok'
		},
		httpResponses   = { 
		    "getColorFromDevice"    
		}
	}
    },
	execute = function(domoticz, item)
	    local function getDeviceStatus(idx)
            local url = domoticz.settings['Domoticz url'] .. "/json.htm?type=devices&rid=" .. idx 
            domoticz.openURL  ({ url = url, method = "GET", callback = callBack })
        end

        if item.isDevice then
            getDeviceStatus(item.id) 
        else  
            dataReceived = item.json
            
            local colorTable = domoticz.utils.fromJSON(dataReceived.result[1].Color)
            
            local name = dataReceived.result[1].Name
            
            local level = dataReceived.result[1].Level
            
            level = math.floor((level / 100) * 255) -- map 0-100 to 0-255

            local dataToSend = string.format("%02x", colorTable.r) .. string.format("%02x", colorTable.g) .. string.format("%02x", colorTable.b) .. string.format("%02x", colorTable.ww) .. string.format("%02x", level)
                
            print('Data to clock as r,g,b,ww,brightness: ' ..  dataToSend)
            
            domoticz.devices('Klok - Data').updateText(dataToSend)    
        end
    end
}
darrepac
Posts: 133
Joined: Tuesday 04 February 2014 21:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Isère, France
Contact:

Re: Get color of RGBW device in dzVents

Post by darrepac »

Hello

Seems I need to do the same thing than you tried: drive my 3 RGBWZ lights from 1 master (a dummy light switch).
I took the script from waaren but I go the following error in the log: Error: User: Admin, switch not found (idx=target.id)! 3 times
I checked the name of my slave lights and they are ok.
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: Get color of RGBW device in dzVents

Post by Nautilus »

waaren wrote: Monday 18 November 2019 22:51
eserero wrote: Monday 18 November 2019 22:33 I have the same problem as @Haubke,
the color temperature seems to be updating only the second time.

anyone know how to resolve that?
You could try to add an extra switchOn.afterSec(0.3)
Sorry, I don't get it. An extra switchOn where? I tried adding it to the function but cannot see any change. Slaves' colors are still followig one step behind the master. Can you @waaren or someone post the complete example, please? :)
User avatar
waltervl
Posts: 5846
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Get color of RGBW device in dzVents

Post by waltervl »

@waaren unfortunately passed away already more then a year ago so this will not be followed up.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: Get color of RGBW device in dzVents

Post by Nautilus »

waltervl wrote: Friday 24 February 2023 22:43 @waaren unfortunately passed away already more then a year ago so this will not be followed up.
Oh, sorry to hear :(

It seems @eserero found the same solution. Maybe s/he can elaborate. I understand one would need to trigger the setColor twice hence the additional switchOn(). But then if I set it in in the main script I get an endless loop as expected.

edit. This - while not pretty - works:

Code: Select all

return
{
    on = { devices = { 'master' }}, data = {state = { initial = 0 }},-- change to name of your 'master' colorswitch
     
    logging = { level = domoticz.LOG_ERROR },

    execute = function(dz, item)
        local slaves =
        { 
            'slave1', -- change to the names of your 'slave' colorswitches
            'slave2',
        }
        
        -- No changes required below this line

    	_G.logMarker =  _G.moduleLabel
        local function setColor(target, source, delay)
            local delay = delay or 0
            local source = source or item
            local switchOnURL = dz.settings['Domoticz url'] .. '/json.htm?type=command&param=switchlight&idx=' .. target.id   .. '&switchcmd=On'
            local colorURL = dz.settings['Domoticz url'] ..
                        '/json.htm?type=command&param=setcolbrightnessvalue' ..
                        '&idx=' .. target.id   .. '&brightness=' .. source.level .. '&color=' .. source.color
            dz.openURL(colorURL)
            dz.openURL(switchOnURL).afterSec(0.2)
            --dz.log('Color set to ' .. source.color .. '( brightness: ' .. source.level ..')',dz.LOG_DEBUG )
        end

        if item.state ~= 'Off' and dz.data.state == 0 then
            item.switchOn().afterSec(0.3)
            dz.data.state = 1 
        elseif item.state ~= 'Off' and dz.data.state == 1 then
            for index, value in pairs(slaves) do
                setColor(dz.devices(value))
            end
            dz.data.state = 0
        elseif item.state == 'Off' then
            for index, value in pairs(slaves) do
                dz.devices(value).switchOff()
            end
            dz.data.state = 0
        else
            dz.data.state = 0
        end

    end
}
Post Reply

Who is online

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