DZventz access to (global) persistant data  [Solved]

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

Moderator: leecollings

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

Post by ceesgeert »

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.
code example hue.txt
(1.13 KiB) Downloaded 81 times
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
User avatar
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

Post by waaren »

ceesgeert wrote: Thursday 10 October 2019 21:43 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.
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
ceesgeert
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

Post by ceesgeert »

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
ceesgeert
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

Post by ceesgeert »

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]
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
User avatar
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

Post by waaren »

ceesgeert wrote: Thursday 10 October 2019 22:40 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.
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,
    }
}
test script

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
ceesgeert
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

Post by ceesgeert »

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
ceesgeert
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

Post by ceesgeert »

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
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
User avatar
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

Post by waaren »

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
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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
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

Post by boum »

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:

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,
    }
}
ceesgeert
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]

Post by ceesgeert »

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

Who is online

Users browsing this forum: No registered users and 1 guest