Time and getISO problem
Posted: Monday 17 April 2023 14:04
Hi,
There must be something that I don't understand about Time variables and data. I had a script running properly for a long time, but not wokring anymore since I had to reinstall and upgrade to newer domtoicz/dzvents version. I was probably not coding properly and benefitting from some trick, but now, I can't understand why it doesn't work..
I'm now using Domoticz 2023.1, on Buster, with DZvents 3.1.8.
I can't succeed making work properly the getISO command. In below script (simplified version of my script to manage a small OPS for the raspberry), I want to keep memory of last "reset date/time" and display that date/time in clear text in the log as well as showing how many minutes since last reset.
But despite getISO works on another script I tested, using local variable, here it doesn't work.
(Note: there are many "if" statements in script above, but the target of these is only to try understanding when variable is NIL and why getISO() returns this error message..
In fact, when the script reaches dz.log instructions with .getISO(), I receive error message like :
2023-04-17 13:53:00.476 Error: dzVents: Error: (3.1.8) An error occurred when calling event handler Test2 script
2023-04-17 13:53:00.476 Error: dzVents: Error: (3.1.8) ...oticz/scripts/dzVents/generated_scripts/Test2 script.lua:36: attempt to call a nil value (field 'getISO')
What I don't understand, is that in my test above, I test is the value of dz.data.lastReset is NIL and if yes, I initialize it at Time() and it seems working because next I see message :
2023-04-17 13:55:00.491 Status: dzVents: Info: ------ Start internal script: Test2 script:, trigger: "every 1 minutes"
2023-04-17 13:55:00.492 Status: dzVents: Info: testscript lastReset is not anymore NIL !!
2023-04-17 13:55:00.492 Status: dzVents: Info: ------ Finished Test2 script
but then I get the error message shown above. And with all the "IF" I put, I see that the value should not be NIL since scripts runs through the ELSE displaying "not anymore NIL"
I tried also to go through a local variable (cf code above with temptime), but it fails also.
If I do a script with simply
this does work..
So can you help me understanding what I do wrong ?
Also, maybe an extra question : to initialize the global variable lastReset upon first run, i use the " lastReset = {initial= ''} "statement. Is there a way to initialize it as a predefined date/time or even the current date/time ? When I try something like {initial=Time()} I have error message, bprobably because I don't have yet the "local Time=require ('Time') before the initialization.
Thanks a lot for your help !
There must be something that I don't understand about Time variables and data. I had a script running properly for a long time, but not wokring anymore since I had to reinstall and upgrade to newer domtoicz/dzvents version. I was probably not coding properly and benefitting from some trick, but now, I can't understand why it doesn't work..
I'm now using Domoticz 2023.1, on Buster, with DZvents 3.1.8.
I can't succeed making work properly the getISO command. In below script (simplified version of my script to manage a small OPS for the raspberry), I want to keep memory of last "reset date/time" and display that date/time in clear text in the log as well as showing how many minutes since last reset.
But despite getISO works on another script I tested, using local variable, here it doesn't work.
Code: Select all
return
{
on =
{
timer =
{
'every 1 minutes', -- causes the script to be called every 3 minutes
},
},
data = {
lastReset = {initial= ''}
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = getVoltage,
},
execute = function(dz)
local Time = require('Time')
if dz.data.lastReset == nil then
dz.log('testscript lastReset is NIL ', dz.LOG_INFO)
dz.data.lastReset=Time()
dz.log('testscript lastReset is now set at '..dz.data.lastReset.getISO(), dz.LOG_INFO)
end
if dz.data.lastReset == nil then
dz.log('testscript lastReset is still NIL !!', dz.LOG_INFO)
else
dz.log('testscript lastReset is not anymore NIL !! ', dz.LOG_INFO)
local temptime=dz.data.lastReset
if temptime == nil then
dz.log('testscript temptime is NIL ', dz.LOG_INFO)
else
dz.log('testscript valeur de temptime'..temptime.getISO(), dz.LOG_INFO)
end
end
if dz.data.lastReset ~= nil then
dz.log('testscript lastReset is not NIL and can be displayed !!'..dz.data.lastReset.getISO(), dz.LOG_INFO)
end
if (true ) then
dz.log('testscript critical warning domoticz UPS under too low voltage, starting reset', dz.LOG_INFO)
local now= Time()
dz.data.lastReset = now
end
dz.log('testscript last reset at time :'..dz.data.lastReset.getISO(), dz.LOG_INFO)
dz.log(' testscriptlast reset at '..dz.data.lastReset.getISO()..' which means in minutes :'..dz.data.lastReset.minutesAgo, dz.LOG_INFO)
end
}
In fact, when the script reaches dz.log instructions with .getISO(), I receive error message like :
2023-04-17 13:53:00.476 Error: dzVents: Error: (3.1.8) An error occurred when calling event handler Test2 script
2023-04-17 13:53:00.476 Error: dzVents: Error: (3.1.8) ...oticz/scripts/dzVents/generated_scripts/Test2 script.lua:36: attempt to call a nil value (field 'getISO')
What I don't understand, is that in my test above, I test is the value of dz.data.lastReset is NIL and if yes, I initialize it at Time() and it seems working because next I see message :
2023-04-17 13:55:00.491 Status: dzVents: Info: ------ Start internal script: Test2 script:, trigger: "every 1 minutes"
2023-04-17 13:55:00.492 Status: dzVents: Info: testscript lastReset is not anymore NIL !!
2023-04-17 13:55:00.492 Status: dzVents: Info: ------ Finished Test2 script
but then I get the error message shown above. And with all the "IF" I put, I see that the value should not be NIL since scripts runs through the ELSE displaying "not anymore NIL"
I tried also to go through a local variable (cf code above with temptime), but it fails also.
If I do a script with simply
Code: Select all
local Time = require('Time')
local tonight = Time()
dz.log('test script tonight value:'..tonight.getISO(), dz.LOG_INFO)
dz.data.lastReset = tonight
So can you help me understanding what I do wrong ?
Also, maybe an extra question : to initialize the global variable lastReset upon first run, i use the " lastReset = {initial= ''} "statement. Is there a way to initialize it as a predefined date/time or even the current date/time ? When I try something like {initial=Time()} I have error message, bprobably because I don't have yet the "local Time=require ('Time') before the initialization.
Thanks a lot for your help !