Error: EventSystem: Lua script did not return a commandArray Topic is solved

Moderator: leecollings

Post Reply
foscolino
Posts: 20
Joined: Monday 02 November 2020 18:38
Target OS: Windows
Domoticz version: 2.20
Location: Italy
Contact:

Error: EventSystem: Lua script did not return a commandArray

Post by foscolino »

Hi, i use this code to tun-off lamp if this in on for more times, the script work correctly! ;)
But i see always error " Error: EventSystem: Lua script did not return a commandArray" in log...

Can you help me to find error, please?

Code: Select all

local atMinute = '02'

if os.date('%M') ~= atMinute then
    print ('Nessuna azione richiesta, esco dallo script')
    return commandArray
end

print ('Procedo con il controllo LUCI Antibagno')

-- script controllo Luci di Casa - Antibagno
t1 = os.time()
s = otherdevices_lastupdate['S1 - Antibagno - 192.168.20.73']
-- returns a date time like 2013-07-11 17:23:12

year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)

commandArray = {}

t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = (os.difftime (t1, t2))

if (otherdevices['S1 - Antibagno - 192.168.20.73'] == 'On' and difference >= 1800 and difference <= 3600) then
   commandArray['SendNotification']='Luce Antibagno#Attenzione, Luce accesa da più di 30 minuti!'
   print('Luce Antibagno accesa da più di 30 minuti')
elseif (otherdevices['S1 - Antibagno - 192.168.20.73'] == 'On' and difference >= 3600 and difference <= 7200) then
   commandArray['SendNotification']='Luce Antibagno#Attenzione, Luce accesa da più di 1 ora!'
   print('Luce Antibagno accesa da più di 1 ora')
end

return commandArray
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Error: EventSystem: Lua script did not return a commandArray

Post by waaren »

foscolino wrote: Wednesday 16 December 2020 11:17 Can you help me to find error, please?
The declaration of commandArray should be earlier in your script. Use below modified script

Code: Select all

commandArray = {}
local atMinute = '02'
local myDevice = 'S1 - Antibagno - 192.168.20.73'

local function timestamp(dateString, pattern)
    local pattern = pattern or  "(%d+)%-(%d+)%-(%d+)%s+(%d+):(%d+):(%d+)"
    local year, month, day, hour, minute, seconds = dateString:match(pattern)
    return os.time( { year = year, month = month, day = day, hour = hour, min = minute, sec = seconds } )
end

if os.date('%M') ~= atMinute then
    print ('Nessuna azione richiesta, esco dallo script')
    return commandArray
end

print ('Procedo con il controllo LUCI Antibagno')

-- script controllo Luci di Casa - Antibagno
local deltaSeconds = timestamp( otherdevices_lastupdate[myDevice] ) - os.time()

if (otherdevices[myDevice] == 'On' and deltaSeconds >= 1800 and deltaSeconds <= 3600) then
   commandArray['SendNotification']='Luce Antibagno#Attenzione, Luce accesa da più di 30 minuti!'
   print('Luce Antibagno accesa da più di 30 minuti')
elseif (otherdevices[myDevice] == 'On' and deltaSeconds >= 3600 and deltaSeconds <= 7200) then
   commandArray['SendNotification']='Luce Antibagno#Attenzione, Luce accesa da più di 1 ora!'
   print('Luce Antibagno accesa da più di 1 ora')
end

return commandArray
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
foscolino
Posts: 20
Joined: Monday 02 November 2020 18:38
Target OS: Windows
Domoticz version: 2.20
Location: Italy
Contact:

Re: Error: EventSystem: Lua script did not return a commandArray

Post by foscolino »

Hi waaren, thank you very much.
error is disappeared ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests