DZventz access to (global) persistant data [Solved]
Moderator: leecollings
-
- Posts: 13
- Joined: Thursday 09 May 2019 18:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: NL
DZventz access to (global) persistant data
I have tried to use (global) persistant data
But I am not able to access the data in a Dzvents script function. What I want to achieve is to set the ambiance for a set of hue spots based on a choice from 1-5 triggered by an event (scene selection). In order to do that I need an array of presets for red, green,blue and the corresponding dimlevel.
From the array I select the appropriate set (say index 4) and push that to a command to set the hue light. That works with hard code.
Now I have tried almost everything I know. A predefined array as in the example, but also with a single number, a history of 5 values, in the global data, also in local data. But noting I try seems to work. I need some guidance.
But I am not able to access the data in a Dzvents script function. What I want to achieve is to set the ambiance for a set of hue spots based on a choice from 1-5 triggered by an event (scene selection). In order to do that I need an array of presets for red, green,blue and the corresponding dimlevel.
From the array I select the appropriate set (say index 4) and push that to a command to set the hue light. That works with hard code.
Now I have tried almost everything I know. A predefined array as in the example, but also with a single number, a history of 5 values, in the global data, also in local data. But noting I try seems to work. I need some guidance.
Raspberry PI 3 &4; Hue Bridge * 2; Zwave devices: FGD212 * 22, FGS222 * 4, FGSD002 * 3, FGMS002 * 5, Qubino ZMNHXD 3 Phase meter * 3 ; P1 smart meter; Foscam camera *2; Solaredge inverter and solarpanels * 2, NIBE 1255-06 PC heat pump
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: DZventz access to (global) persistant data
If you try to acces data from the globaldata you should use domoticz.globalData.name
even when you access the data from within global_data.lua
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: 13
- Joined: Thursday 09 May 2019 18:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: NL
Re: DZventz access to (global) persistant data
I know. I have read all that multiple times. But it seems I am blind to the solution. And I do have programming skills.
Raspberry PI 3 &4; Hue Bridge * 2; Zwave devices: FGD212 * 22, FGS222 * 4, FGSD002 * 3, FGMS002 * 5, Qubino ZMNHXD 3 Phase meter * 3 ; P1 smart meter; Foscam camera *2; Solaredge inverter and solarpanels * 2, NIBE 1255-06 PC heat pump
-
- Posts: 13
- Joined: Thursday 09 May 2019 18:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: NL
Re: DZventz access to (global) persistant data
I had tried and have tried again the use of domoticz.globalData.name. I have also set a fixed index to be sure. Same result.
r = domoticz.globalData.ambiance_R[4]
g = domoticz.globalData.ambiance_G[4]
b = domoticz.globalData.ambiance_B[4]
d = domoticz.globalData.ambiance_dimlevel[4]
r = domoticz.globalData.ambiance_R[4]
g = domoticz.globalData.ambiance_G[4]
b = domoticz.globalData.ambiance_B[4]
d = domoticz.globalData.ambiance_dimlevel[4]
Raspberry PI 3 &4; Hue Bridge * 2; Zwave devices: FGD212 * 22, FGS222 * 4, FGSD002 * 3, FGMS002 * 5, Qubino ZMNHXD 3 Phase meter * 3 ; P1 smart meter; Foscam camera *2; Solaredge inverter and solarpanels * 2, NIBE 1255-06 PC heat pump
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: DZventz access to (global) persistant data
Try this set of global_data.lua and test script.
Code: Select all
-- global_data.lua
return
{
data = -- Because these tables are nowhere else set, they need to be initialized
{
ambiance_R = { initial = { 255, 255, 224, 255, 255 }}, -- RED
ambiance_G = { initial = { 189, 255, 224, 182, 84 }}, -- GREEN
ambiance_B = { initial = { 127, 74, 255, 114, 49 }}, -- BLUE
ambiance_dimlevel = { initial = { 100, 57, 100, 31, 31}}, -- with respective dimlevel
},
helpers =
{
test_global_hue = function(dz, selected_ambiance)
local r = dz.globalData.ambiance_R[selected_ambiance]
local g = dz.globalData.ambiance_G[selected_ambiance]
local b = dz.globalData.ambiance_G[selected_ambiance]
local d = dz.globalData.ambiance_dimlevel[selected_ambiance]
dz.log('\nred: ' .. r ..
'\ngreen: ' .. g ..
'\nblue: ' .. b ..
'\ndimlevel: ' .. d ,dz.LOG_FORCE)
-- domoticz.devices("L_H1_Hue_color").setHex(r,g,b)
end,
}
}
Code: Select all
return
{
on = { timer = { 'every minute' }},
logging = { level = domoticz.LOG_DEBUG, marker = 'hue Test' },
execute = function(dz)
dz.helpers.test_global_hue(dz,1)
dz.helpers.test_global_hue(dz,2)
dz.helpers.test_global_hue(dz,3)
dz.helpers.test_global_hue(dz,4)
dz.helpers.test_global_hue(dz,5)
end
}
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: 13
- Joined: Thursday 09 May 2019 18:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: NL
Re: DZventz access to (global) persistant data
Thanks Waaren. That was very helpful. This works! I can now start building the rest of my system in an efficient way.
Raspberry PI 3 &4; Hue Bridge * 2; Zwave devices: FGD212 * 22, FGS222 * 4, FGSD002 * 3, FGMS002 * 5, Qubino ZMNHXD 3 Phase meter * 3 ; P1 smart meter; Foscam camera *2; Solaredge inverter and solarpanels * 2, NIBE 1255-06 PC heat pump
-
- Posts: 13
- Joined: Thursday 09 May 2019 18:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: NL
Re: DZventz access to (global) persistant data
Apparently I think it means that the domoticz object referring to global_data can only be accessed via "dz" and not via "domoticz"...
dz.globalData.ambiance_R[selected_ambiance] works
domoticz.globalData.ambiance_R[selected_ambiance] fails
dz.globalData.ambiance_R[selected_ambiance] works
domoticz.globalData.ambiance_R[selected_ambiance] fails
Raspberry PI 3 &4; Hue Bridge * 2; Zwave devices: FGD212 * 22, FGS222 * 4, FGSD002 * 3, FGMS002 * 5, Qubino ZMNHXD 3 Phase meter * 3 ; P1 smart meter; Foscam camera *2; Solaredge inverter and solarpanels * 2, NIBE 1255-06 PC heat pump
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: DZventz access to (global) persistant data
No it' s just a name. As long as it refers to the domoticz object it's ok. As example you could change dz to Domo in the script and dz to domoticz in global_data if you do this throughout the files.ceesgeert wrote:Apparently I think it means that the domoticz object referring to global_data can only be accessed via "dz" and not via "domoticz"...
dz.globalData.ambiance_R[selected_ambiance] works
domoticz.globalData.ambiance_R[selected_ambiance] fails
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
- boum
- Posts: 135
- Joined: Friday 18 January 2019 11:31
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Location: France
- Contact:
Re: DZventz access to (global) persistant data
Hello Ceesgeert, I won't get into the why it was not working. But I had just a remark about the style. So that personal and you can totally dismiss it, it's your call.
Why are you spliting the components in different tables? Was it because it didn't work when you did it differently or no reason?
I'd do something like that, easier to change later:
Why are you spliting the components in different tables? Was it because it didn't work when you did it differently or no reason?
I'd do something like that, easier to change later:
Code: Select all
-- global_data.lua
return
{
data = -- Because these tables are nowhere else set, they need to be initialized
{
ambiance = { initial = {
{ r=255, g=189, b=127, dim=100, },
{ r=255, g=255, b=74, dim=57, },
{ r=224, g=224, b=255, dim=100, },
{ r=255, g=182, b=114, dim=31, },
{ r=255, g=84, b=49, dim=31, },
} },
},
helpers =
{
test_global_hue = function(dz, selected_ambiance)
local ambiance = dz.globalData.ambiance[selected_ambiance]
local r = ambiance.r
local g = ambiance.g
local b = ambiance.b
local d = ambiance.dim
dz.log('\nred: ' .. r ..
'\ngreen: ' .. g ..
'\nblue: ' .. b ..
'\ndimlevel: ' .. d ,dz.LOG_FORCE)
-- domoticz.devices("L_H1_Hue_color").setHex(r,g,b)
end,
}
}
-
- Posts: 13
- Joined: Thursday 09 May 2019 18:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: NL
Re: DZventz access to (global) persistant data [Solved]
Thank you for your tip Boum. Indeed I started with one 2-dimensional table but changed it many times even up to single values. However the problems remained.
Fortunately my problem not getting access to the global data was resolved by Waaren. (Great this forum and thank you for the fast reponses!)
As far as I am concerned this item can be marked as " solved"
Fortunately my problem not getting access to the global data was resolved by Waaren. (Great this forum and thank you for the fast reponses!)
As far as I am concerned this item can be marked as " solved"
Raspberry PI 3 &4; Hue Bridge * 2; Zwave devices: FGD212 * 22, FGS222 * 4, FGSD002 * 3, FGMS002 * 5, Qubino ZMNHXD 3 Phase meter * 3 ; P1 smart meter; Foscam camera *2; Solaredge inverter and solarpanels * 2, NIBE 1255-06 PC heat pump
Who is online
Users browsing this forum: No registered users and 1 guest