handling time in dzvents
Posted: Sunday 25 October 2020 15:52
Hi,
I have script based on timer (running every 3 minutes for instance) in which I'd like to use time elapsed since "something" happened, but I can't make it work. I have error messages or nothing returned.. I tried to follow wiki examples, but I didn't find exact similar context, so I' probably doing something wrong..
Here's the structure of my script (I removed most of the code for clarity):
In the log, it displays 'occurred 0 minutes ago' (even though the "if" block does not run every time the script is triggered).
I tried also to display the value of resetUPS with .getISO() like this:
but in such case, I have an error message.
If I use this instead:
I have no error message and it displays a date & time (but of course it's not the current time I want to display..)
So I probably misunderstood something on how to use dzvents objects in general or the Time in particular...
Could you help me ? Which code should I use to display a date & time variable ? and how to use the .minutesAgo ?
Thanks a lot,
Ricorico94
I have script based on timer (running every 3 minutes for instance) in which I'd like to use time elapsed since "something" happened, but I can't make it work. I have error messages or nothing returned.. I tried to follow wiki examples, but I didn't find exact similar context, so I' probably doing something wrong..
Here's the structure of my script (I removed most of the code for clarity):
Code: Select all
return
{
on =
{
timer =
{
'every 3 minutes', -- causes the script to be called every 3 minutes
},
},
data = {
lastmeasure = {initial=0},
resetUPS= {initial=0},
lastReset = {initial=""}
-- some other variables declared here (removed to ease reading..
},
execute = function(dz)
local UPSPlug = dz.devices(9999) -- device for UPS powercontrol
local unplugduration = 10 -- in minutes
local Time = require('Time')
-- some other variables declared here (removed to ease reading..
-- some more code here
if dz.data.resetUPS == 'Off' then
dz.data.resetUPS='On'
-- in following lines I want to store the time when I reset my UPS
local now= Time()
dz.data.lastReset = now
UPSplug.switchOff()
UPSplug.switchOn().afterMin(unplugduration)
end
dz.log('last reset occurred :'..dz.data.lastReset.minutesAgo ..' minutes ago' , dz.LOG_INFO)
end
}
I tried also to display the value of resetUPS with .getISO() like this:
Code: Select all
dz.log('last reset occurred at :'..dz.data.lastReset.getISO() ..' minutes ago' , dz.LOG_INFO)
If I use this instead:
Code: Select all
dz.log('last reset occurred at:'..now.getISO() ..' minutes ago' , dz.LOG_INFO)
So I probably misunderstood something on how to use dzvents objects in general or the Time in particular...
Could you help me ? Which code should I use to display a date & time variable ? and how to use the .minutesAgo ?
Thanks a lot,
Ricorico94