Dzvents - setting RGB to slaves from dummy master is sending previous selected color to the real lamp
Posted: Tuesday 08 September 2020 13:13
Dear all,
The past weeks I am struggling to set up the DZvents script for managing slave RGB tradfri lamps.
I have set up one dummy RGBWW device from which the dzvents will get triggered on changes.
I have used some parts from the following topic: https://www.domoticz.com/forum/viewtopic.php?t=26056
The script will retrieve the properties (first color and dimlevel) from the master dummy object and must push this to the slave object.
First it is tested as 'setColor' and next it is tested with a direct openURL call.
But the color of the lamp itself is running one selection behind compared to what is selected.
So the following steps are done:
1. Change the color on dummy master to 'red' (255,0,0);
1.a DZvents debug log shows the newly selected color and the corresponding call to localhost it performed for the slave device is processed;
1.b the color of the slave device in Domoticz is changed to the selected master color, the lamp itself is not changing its color;
2. A new color is selected at the dummy-master, green (0,255,0);
2.a DZvents debug log shows the newly selected color and the corresponding call to localhost it performed for the slave device is processed;
2.b the color of the slave device in Domoticz is changed to the selected master color, the lamp itself is now changing to the selected color at step 1.a;
3. A new color is selected at the dummy-master, blue (0,0,255);
3.a DZvents debug log shows the newly selected color and the corresponding call to localhost it performed for the slave device is processed;
3.b the color of the slave device in Domoticz is changed to the selected master color, the lamp itself is now changing to the selected color at step 2.a;
The steps above are tested with the localhost address and the real IP of the domoticz host.
When I open a browser and submit the identical webcall, the corresponding IDX object gets updated with the new color and the lamp is changing its color accordingly and instantly.
Next when i change the color of the slave object through the Domoticz GUI, it is also changing the lamp color instant.
The following is the dzvents code:
Can someone help me out with this, because I am debugging it over a week and got stuck on it.
The domoticz Build date is : 2020-04-26 13:45:55 -> Domoticz 2020.2 and it is running on a RPI 4 (2 months old).
The past weeks I am struggling to set up the DZvents script for managing slave RGB tradfri lamps.
I have set up one dummy RGBWW device from which the dzvents will get triggered on changes.
I have used some parts from the following topic: https://www.domoticz.com/forum/viewtopic.php?t=26056
The script will retrieve the properties (first color and dimlevel) from the master dummy object and must push this to the slave object.
First it is tested as 'setColor' and next it is tested with a direct openURL call.
But the color of the lamp itself is running one selection behind compared to what is selected.
So the following steps are done:
1. Change the color on dummy master to 'red' (255,0,0);
1.a DZvents debug log shows the newly selected color and the corresponding call to localhost it performed for the slave device is processed;
1.b the color of the slave device in Domoticz is changed to the selected master color, the lamp itself is not changing its color;
2. A new color is selected at the dummy-master, green (0,255,0);
2.a DZvents debug log shows the newly selected color and the corresponding call to localhost it performed for the slave device is processed;
2.b the color of the slave device in Domoticz is changed to the selected master color, the lamp itself is now changing to the selected color at step 1.a;
3. A new color is selected at the dummy-master, blue (0,0,255);
3.a DZvents debug log shows the newly selected color and the corresponding call to localhost it performed for the slave device is processed;
3.b the color of the slave device in Domoticz is changed to the selected master color, the lamp itself is now changing to the selected color at step 2.a;
The steps above are tested with the localhost address and the real IP of the domoticz host.
When I open a browser and submit the identical webcall, the corresponding IDX object gets updated with the new color and the lamp is changing its color accordingly and instantly.
Next when i change the color of the slave object through the Domoticz GUI, it is also changing the lamp color instant.
The following is the dzvents code:
Code: Select all
return {
on = {
devices = {"tradfri-woonkamer-RGBWWZ" },
},
logging = { level = domoticz.LOG_DEBUG, -- switch to LOG_INFO when results are OK
marker = "dzTestRGB" },
data = { userTriggered = { initial = false },
setColor = { initial = true },
dimLevel = {initial = 50},
color = {initial = {}},
},
execute = function(dz, triggeredItem)
local slaveDevices = { 'ZiGate_lamp_woonkamer_color_01', 'ZiGate_lamp_woonkamer_color_02', 'ZiGate_lamp_woonkamer_color_03' }
local rgb01 = dz.devices("ZiGate_lamp_woonkamer_color_02")
if ( dz.data.color == nil or dz.data.setColor) then
dz.log( 'Found NIL data or setColor == true, setting new color.', dz.LOG_DEBUG)
dz.data.color = dz.utils.fromJSON(triggeredItem.color)
dz.data.setColor = false
else
dz.log("color, R="..dz.data.color.r..", G="..dz.data.color.g..", B="..dz.data.color.b..".", dz.LOG_DEBUG)
end
local RGBcolor = triggeredItem.color
local dimLevel = triggeredItem.level
colorNew = dz.utils.fromJSON(triggeredItem.color)
dz.log("selector color, R="..colorNew.r..", G="..colorNew.g..", B="..colorNew.b..".", dz.LOG_DEBUG)
dz.log("old = dz.data.color, R="..dz.data.color.r..", G="..dz.data.color.g..", B="..dz.data.color.b..".", dz.LOG_DEBUG)
local colorURL = dz.settings['Domoticz url'] .. "/json.htm?type=command¶m=setcolbrightnessvalue&idx="..rgb01.idx.."&brightness="..dimLevel.."&color="..RGBcolor
dz.openURL(colorURL)
-- local switchOnURL = dz.settings['Domoticz url'] .. '/json.htm?type=command¶m=switchlight&idx='..rgb01.idx..'&switchcmd=On'
-- dz.openURL(switchOnURL).afterSec(0.2)
-- dz.data.color = colorNew
-- dz.log("new = dz.data.color, R="..dz.data.color.r..", G="..dz.data.color.g..", B="..dz.data.color.b..".", dz.LOG_DEBUG)
end
}
The domoticz Build date is : 2020-04-26 13:45:55 -> Domoticz 2020.2 and it is running on a RPI 4 (2 months old).