Page 1 of 1

[SOLVED] Set variable for setRGB()

Posted: Tuesday 18 September 2018 13:17
by stewdyne
Is it possible to set a variable in setRGB () with Dzvents? I mean something like that:

setRGB (variableRed, variableGreen, variableBlue) or something like: setRGB (variableRGBhere)

Re: Set variable for setRGB()

Posted: Tuesday 18 September 2018 13:22
by Inso80
Maybe take a look at:
https://www.domoticz.com/wiki/DzVents:_ ... object_API
and scroll down to specific devices, rgb(w)

For the call in DzVents:
https://www.domoticz.com/wiki/DzVents:_ ... terface.29

should be something like

Code: Select all

domoticz.devices('deviceName').setRGB(red, green, blue)

Re: Set variable for setRGB()

Posted: Tuesday 18 September 2018 14:32
by stewdyne
Thank you for your reply.

I know how setRGB works, but that is not what I mean. I want to store a variable (like: 0,250,0) and set that in setRGB().

setRGB('Variable_here'')

output:

setRGB(0,250,0)

Re: Set variable for setRGB()

Posted: Tuesday 18 September 2018 14:51
by poudenes
What i did for colors is this:

Create a "global_data" dzVents file. The Even name is global_data

Code: Select all

-- RGB          (domoticz,idx,dim,color,sec)    (domoticz,idx,100,'white',0)

local COLORS = {
                ['White']       = {255,225,255},
                ['Red']         = {255,0,1},
                ['Blue']        = {12,0,179},
                ['Green']       = {150,255,142},
                ['Romantic']    = {128,0,0}
            }
            
return {
    helpers = {
        
        RGB = function(domoticz,idx,dim,color,sec)
            if (dim == nil)     then dim = 100 end
        	if (color == nil)   then rgb = COLORS['White']  else rgb = COLORS[color] end
            if (sec == nil)     then sec = 0 end
            domoticz.devices(idx).setRGB(rgb[1], rgb[2], rgb[3]).afterSec(sec)
            domoticz.devices(idx).dimTo(dim).afterSec(sec)
            status = 'aangezet'
        end
          }
}
Then in your dzVents scripts you can do this:

Code: Select all

domoticz.helpers.RGB(domoticz,BulbLivingroomAll,nil,'Green',nil)
domoticz.helpers.RGB(domoticz,BulbLivingroomAll,nil,'Blue',nil)
domoticz.helpers.RGB(domoticz,BulbLivingroomAll,nil,'Romantic',nil)
I add some things extra like dim option, and seconds. So you can have 1 line and add dim, RGB, aftersec

Re: Set variable for setRGB()

Posted: Tuesday 18 September 2018 14:52
by Inso80
stewdyne wrote: Tuesday 18 September 2018 14:32 Thank you for your reply.

I know how setRGB works, but that is not what I mean. I want to store a variable (like: 0,250,0) and set that in setRGB().

setRGB('Variable_here'')

output:

setRGB(0,250,0)
Ah, sorry^^

you mean:

Code: Select all

a = 50;
b = 50;
c = 50;
domoticz.devices('testrgb').setRGB(a, b, c)
?

Just tested within
execute = function(domoticz, device)
, works.

Should also work if you use persistent / global variables

https://www.domoticz.com/wiki/DzVents:_ ... stent_data

@poudenes: that is indeed a nice way to handle it :)

Re: Set variable for setRGB()

Posted: Wednesday 19 September 2018 7:59
by stewdyne
Inso80 wrote: Tuesday 18 September 2018 14:52
stewdyne wrote: Tuesday 18 September 2018 14:32 Thank you for your reply.

I know how setRGB works, but that is not what I mean. I want to store a variable (like: 0,250,0) and set that in setRGB().

setRGB('Variable_here'')

output:

setRGB(0,250,0)
Ah, sorry^^

you mean:

Code: Select all

a = 50;
b = 50;
c = 50;
domoticz.devices('testrgb').setRGB(a, b, c)
?

Just tested within
execute = function(domoticz, device)
, works.

Should also work if you use persistent / global variables

https://www.domoticz.com/wiki/DzVents:_ ... stent_data

@poudenes: that is indeed a nice way to handle it :)
Indeed, that is what I want. This is what I tried:

Code: Select all

living.setRGB(dz.globalData.rgbRed, dz.globalData.rgbGreen, dz.globalData.rgbBlue)
No luck there. The lights just turn white.

In global data I have:

Code: Select all

    return {
       helpers = {},
       data = {
            rgbRed = { initial = 0 },
            rgbGreen = { initial = 250 },
            rgbBlue = { initial = 0 }
       }
    }

@poudenes: Looks interesting! I'll look in your code this weekend. I'm not (yet) familair with Helpers.

Re: Set variable for setRGB()

Posted: Wednesday 19 September 2018 8:20
by waaren
stewdyne wrote: Wednesday 19 September 2018 7:59 ..This is what I tried:

Code: Select all

living.setRGB(dz.globalData.rgbRed, dz.globalData.rgbGreen, dz.globalData.rgbBlue)
No luck there. The lights just turn white.

In global data I have:

Code: Select all

    return {
       helpers = {},
       data = {
            rgbRed = { initial = 0 },
            rgbGreen = { initial = 250 },
            rgbBlue = { initial = 0 }
       }
    }
can you display the values by putting something like ?

Code: Select all

dz.log(dz.globalData.rgbGreen)
in your code ? And it might help us to help you if you could show the complete script.

Re: Set variable for setRGB()

Posted: Thursday 20 September 2018 19:31
by stewdyne
Ok, I've found the problem.

Had this in my global_data:

Code: Select all

    return {
       helpers = {},
       data = {
            brightnessLiving = { initial = 100 },
            brightnessHallwayOne = { initial = 100 },
            brightnessHallwayTwo = { initial = 100 },
            brightnessToilet = { initial = 100 },
            brightnessKitchen = { initial = 100 },
            brightnessBedroom = { initial = 100 },
            colorTemperature = { initial = 100 },
            rgbRed = { initial = 50 },
            rgbGreen = { initial = 250 },
            rgbBlue = { initial = 80 }
       }
    }
Executed this script:

Code: Select all

return {
	on = {
		devices = {
			'Test_switch'
		}
	},
	execute = function(dz, switch)
        if (dz.devices('Test_switch').state == 'On') then
            dz.devices('Lampen_Woon_1').setRGB(dz.globalData.rgbRed, dz.globalData.rgbGreen, dz.globalData.rgbBlue)
            dz.log(dz.globalData.rgbGreen)
        end
	end
}
The code above set the light to full white and printed 255 in log. But I have initial 250 in global data. So I tried this:

Code: Select all

return {
	on = {
		devices = {
			'Test_switch'
		}
	},
	execute = function(dz, switch)
        if (dz.devices('Test_switch').state == 'On') then
            dz.globalData.rgbRed = 20
            dz.globalData.rgbGreen = 20
            dz.globalData.rgbBlue = 250
            dz.devices('Lampen_Woon_1').setRGB(dz.globalData.rgbRed, dz.globalData.rgbGreen, dz.globalData.rgbBlue)
            dz.log(dz.globalData.rgbGreen)
        end
	end
}
And that gave me the right color. Conclusion: my global data initial value aint working :) What is wrong with it?

Re: Set variable for setRGB()

Posted: Thursday 20 September 2018 20:22
by waaren
stewdyne wrote: Thursday 20 September 2018 19:31 Ok, I've found the problem.
The code above set the light to full white and printed 255 in log. But I have initial 250 in global data. So I tried this:
....
And that gave me the right color. Conclusion: my global data initial value aint working :) What is wrong with it?
Can you confirm that nothing else can modify global data ? No internal or external dzVents script ?
I copied your script and global data and add

Code: Select all

dz.log("Green: ".. dz.globalData.rgbGreen .. " - Red: " .. dz.globalData.rgbRed .. " - Blue: " .. dz.globalData.rgbBlue,dz.LOG_FORCE)
Before and after the setRGB line.
My result is that the RGB device changed to the requested color and the log showed:

Code: Select all

2018-09-20 20:10:38.499  Status: dzVents: !Info: Green: 250 - Red: 50 - Blue: 80
2018-09-20 20:10:38.501  Status: dzVents: !Info: Green: 250 - Red: 50 - Blue: 80
Can you also look what the content of the file <domoticz_dir>/scripts/dzVents/data/__data_global_data.lua is ?

Re: Set variable for setRGB()

Posted: Saturday 22 September 2018 0:03
by stewdyne
Hi Waaren,

I checked my scripts and indeed the values were changed at start. Everything is working fine now, thank you!

1 more question. By setting the rgb you also automaticly change the brightness of the lights. Is it possible to only change the color without changing the brightness? And how?

Re: Set variable for setRGB()

Posted: Saturday 22 September 2018 9:25
by poudenes
stewdyne wrote:Hi Waaren,

I checked my scripts and indeed the values were changed at start. Everything is working fine now, thank you!

1 more question. By setting the rgb you also automaticly change the brightness of the lights. Is it possible to only change the color without changing the brightness? And how?
What I always do is goto Google search for "color picker" then you get a tool to select color and left you see rgb value.


Verzonden vanaf mijn iPhone met Tapatalk Pro

Re: Set variable for setRGB()

Posted: Saturday 22 September 2018 9:54
by waaren
stewdyne wrote: Saturday 22 September 2018 0:03 ...By setting the rgb you also automaticly change the brightness of the lights. Is it possible to only change the color without changing the brightness? And how?
hi @stewdyne,
If my understanding of dzVents current device-adapter for RGBW devices is correct, it is not yet possible to do this with native dzVents commands. @dannybloe can give you a definitive answer on that.

If you look at https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's and scroll to "Specify Domoticz JSON color object and brightness" you will see the json example:

Code: Select all

/json.htm?type=command&param=setcolbrightnessvalue&idx=130&color={"m":3,"t":0,"r":0,"g":0,"b":50,"cw":0,"ww":0}&brightness=100
and with that information you can use the openURL command like:

Code: Select all

domoticz.openURL({
                	url = domoticz.settings['Domoticz url'] .. "/json.htm?type=command&param=setcolbrightnessvalue&idx=130&color={"m":3,"t":0,"r":0,"g":0,"b":50,"cw":0,"ww":0}&brightness=100",
                	method = "GET",
                  })
To get to the result you want.

Re: Set variable for setRGB()

Posted: Monday 24 September 2018 6:59
by stewdyne
Thank you for your help! This topic can be set on solved.

Re: Set variable for setRGB()

Posted: Monday 24 September 2018 7:39
by waaren
stewdyne wrote: Monday 24 September 2018 6:59 Thank you for your help! This topic can be set on solved.
Good to hear ! You must set this topic to solved yourself (as you are the topic starter)

Re: Set variable for setRGB()

Posted: Tuesday 25 September 2018 14:36
by Inso80
stewdyne wrote: Saturday 22 September 2018 0:03 Hi Waaren,

I checked my scripts and indeed the values were changed at start. Everything is working fine now, thank you!

1 more question. By setting the rgb you also automaticly change the brightness of the lights. Is it possible to only change the color without changing the brightness? And how?
On some lights you can set HSV instead of RGB when sending the command directly. Has some pros and cons, one pro is changing the color does not affect the brightnes. Con to change back to RGB for me was HSV is not as precisious for color set of the single colors as RGB is.
HSV is f.e. available for Yeelights, WS2812b, Hue..

Re: [SOLVED] Set variable for setRGB()

Posted: Tuesday 25 September 2018 14:39
by stewdyne
Ow wow! Thank you. Should have known this earlier. Now I've created a workaround that puts some load on my rpi. Will check this out tonight.