Page 1 of 1

On statement and global_data.lua [SOLVED]

Posted: Wednesday 13 January 2021 12:51
by Antori91
Hello,

Is there any way to use an entity declared in global_data.lua within the on statement of a dzVents script?

I mean:
This works -->

Code: Select all

    return {
        on = {
           timer   = {'every 1 minutes'},
           devices = {'Horaires/Start Chauffage','Horaires/Stop Chauffage', 17, 16}
        },
        
But, this doesn't work (Off course, IDX_HEATINGSELECTOR and IDX_THERMOSTAT_SETPOINT are defined in my global_data.lua file)
Runtime Error in the log: 2021-01-13 13:01:33.368 Status: dzVents: Error (2.4.19): /home/pi/domoticz/scripts/dzVents/scripts/Heating.lua:9: attempt to index global 'helpers' (a nil value)
-->

Code: Select all

    return {
        on = {
           timer   = {'every 1 minutes'},
           devices = {'Horaires/Start Chauffage','Horaires/Stop Chauffage', domoticz.helpers.IDX_HEATINGSELECTOR, domoticz.helpers.IDX_THERMOSTAT_SETPOINT}
        },
OR

Code: Select all

    return {
        on = {
           timer   = {'every 1 minutes'},
           devices = {'Horaires/Start Chauffage','Horaires/Stop Chauffage', helpers.IDX_HEATINGSELECTOR, helpers.IDX_THERMOSTAT_SETPOINT}
        },

Re: On statement and global_data.lua

Posted: Wednesday 13 January 2021 13:59
by waaren
Antori91 wrote: Wednesday 13 January 2021 12:51 Is there any way to use an entity declared in global_data.lua within the on statement of a dzVents script?
Yes; using Lua's require

Code: Select all

local dz = require ("global_data")

return
{
    on =
    {
        devices =
        {
            dz.helpers.IDX_HEATINGSELECTOR,
            dz.helpers.IDX_THERMOSTAT_SETPOINT,
            'Horaires/Start Chauffage',
            'Horaires/Stop Chauffage',
        },
    },

    logging =
    {
        level = domoticz.LOG_INFO,
        marker = 'globalData definitions',
    },

    execute = function(dz, item)
        dz.log('Triggered by ' ..item.name, dz.LOG_FORCE)
    end
}


Re: On statement and global_data.lua

Posted: Wednesday 13 January 2021 14:54
by Antori91
waaren wrote: Wednesday 13 January 2021 13:59
Antori91 wrote: Wednesday 13 January 2021 12:51 Is there any way to use an entity declared in global_data.lua within the on statement of a dzVents script?
Yes; using Lua's require
Thanks Waaren.