[SOLVED] Set variable for setRGB()

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

Moderator: leecollings

Post Reply
stewdyne
Posts: 20
Joined: Friday 20 July 2018 7:55
Target OS: Windows
Domoticz version:
Contact:

[SOLVED] Set variable for setRGB()

Post 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)
Last edited by stewdyne on Monday 24 September 2018 8:02, edited 1 time in total.
Inso80
Posts: 12
Joined: Thursday 17 May 2018 13:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Set variable for setRGB()

Post 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)
stewdyne
Posts: 20
Joined: Friday 20 July 2018 7:55
Target OS: Windows
Domoticz version:
Contact:

Re: Set variable for setRGB()

Post 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)
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Set variable for setRGB()

Post 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
Last edited by poudenes on Tuesday 18 September 2018 14:52, edited 1 time in total.
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
Inso80
Posts: 12
Joined: Thursday 17 May 2018 13:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Set variable for setRGB()

Post 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 :)
stewdyne
Posts: 20
Joined: Friday 20 July 2018 7:55
Target OS: Windows
Domoticz version:
Contact:

Re: Set variable for setRGB()

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

Re: Set variable for setRGB()

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
stewdyne
Posts: 20
Joined: Friday 20 July 2018 7:55
Target OS: Windows
Domoticz version:
Contact:

Re: Set variable for setRGB()

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

Re: Set variable for setRGB()

Post 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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
stewdyne
Posts: 20
Joined: Friday 20 July 2018 7:55
Target OS: Windows
Domoticz version:
Contact:

Re: Set variable for setRGB()

Post 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?
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Set variable for setRGB()

Post 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
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Set variable for setRGB()

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
stewdyne
Posts: 20
Joined: Friday 20 July 2018 7:55
Target OS: Windows
Domoticz version:
Contact:

Re: Set variable for setRGB()

Post by stewdyne »

Thank you for your help! This topic can be set on solved.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Set variable for setRGB()

Post 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)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Inso80
Posts: 12
Joined: Thursday 17 May 2018 13:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Set variable for setRGB()

Post 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..
stewdyne
Posts: 20
Joined: Friday 20 July 2018 7:55
Target OS: Windows
Domoticz version:
Contact:

Re: [SOLVED] Set variable for setRGB()

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

Who is online

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