On statement and global_data.lua [SOLVED]

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

Moderator: leecollings

Post Reply
User avatar
Antori91
Posts: 136
Joined: Sunday 12 February 2017 17:12
Target OS: NAS (Synology & others)
Domoticz version: 4.10717
Location: France
Contact:

On statement and global_data.lua [SOLVED]

Post 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}
        },
Last edited by Antori91 on Wednesday 13 January 2021 14:55, edited 2 times in total.
Domoticz High Availability Cluster: Synology Dz V4.10693 (Main) - Raspberry Dz V4.10717 (Backup) - Scripts Node.js
Alarm server: Raspberry - motionEye - iot_ALARM-SVR Node.js
Sensors/Actuators: ESP8266-Arduino
https://github.com/Antori91/Home_Automation
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: On statement and global_data.lua

Post 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
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
Antori91
Posts: 136
Joined: Sunday 12 February 2017 17:12
Target OS: NAS (Synology & others)
Domoticz version: 4.10717
Location: France
Contact:

Re: On statement and global_data.lua

Post 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.
Domoticz High Availability Cluster: Synology Dz V4.10693 (Main) - Raspberry Dz V4.10717 (Backup) - Scripts Node.js
Alarm server: Raspberry - motionEye - iot_ALARM-SVR Node.js
Sensors/Actuators: ESP8266-Arduino
https://github.com/Antori91/Home_Automation
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest