[SOLVED] Set variable for setRGB()
Moderator: leecollings
[SOLVED] Set variable for setRGB()
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)
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.
-
- Posts: 12
- Joined: Thursday 17 May 2018 13:28
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Set variable for setRGB()
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
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()
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)
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)
-
- Posts: 667
- Joined: Wednesday 08 March 2017 9:42
- Target OS: Linux
- Domoticz version: 3.8993
- Location: Amsterdam
- Contact:
Re: Set variable for setRGB()
What i did for colors is this:
Create a "global_data" dzVents file. The Even name is global_data
Then in your dzVents scripts you can do this:
I add some things extra like dim option, and seconds. So you can have 1 line and add dim, RGB, aftersec
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
}
}
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)
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
-
- Posts: 12
- Joined: Thursday 17 May 2018 13:28
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Set variable for setRGB()
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()
Indeed, that is what I want. This is what I tried:Inso80 wrote: ↑Tuesday 18 September 2018 14:52Ah, 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
Code: Select all
living.setRGB(dz.globalData.rgbRed, dz.globalData.rgbGreen, dz.globalData.rgbBlue)
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.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Set variable for setRGB()
can you display the values by putting something like ?stewdyne wrote: ↑Wednesday 19 September 2018 7:59 ..This is what I tried:No luck there. The lights just turn white.Code: Select all
living.setRGB(dz.globalData.rgbRed, dz.globalData.rgbGreen, dz.globalData.rgbBlue)
In global data I have:Code: Select all
return { helpers = {}, data = { rgbRed = { initial = 0 }, rgbGreen = { initial = 250 }, rgbBlue = { initial = 0 } } }
Code: Select all
dz.log(dz.globalData.rgbGreen)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Re: Set variable for setRGB()
Ok, I've found the problem.
Had this in my global_data:
Executed this script:
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?
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 }
}
}
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
}
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
}
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Set variable for setRGB()
Can you confirm that nothing else can modify global data ? No internal or external dzVents script ?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?
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)
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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Re: Set variable for setRGB()
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?
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?
-
- Posts: 667
- Joined: Wednesday 08 March 2017 9:42
- Target OS: Linux
- Domoticz version: 3.8993
- Location: Amsterdam
- Contact:
Re: Set variable for setRGB()
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.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?
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
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Set variable for setRGB()
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¶m=setcolbrightnessvalue&idx=130&color={"m":3,"t":0,"r":0,"g":0,"b":50,"cw":0,"ww":0}&brightness=100
Code: Select all
domoticz.openURL({
url = domoticz.settings['Domoticz url'] .. "/json.htm?type=command¶m=setcolbrightnessvalue&idx=130&color={"m":3,"t":0,"r":0,"g":0,"b":50,"cw":0,"ww":0}&brightness=100",
method = "GET",
})
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Re: Set variable for setRGB()
Thank you for your help! This topic can be set on solved.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Set variable for setRGB()
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
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 12
- Joined: Thursday 17 May 2018 13:28
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Set variable for setRGB()
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.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?
HSV is f.e. available for Yeelights, WS2812b, Hue..
Re: [SOLVED] Set variable for setRGB()
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.
Who is online
Users browsing this forum: No registered users and 1 guest