waaren wrote: ↑Saturday 01 May 2021 21:44
There is no native Lua / dzVents method to get this. From the OS you can get nanoseconds so you can use something like below.
I must say waaren; it always amazes me how you are able to always answer the questions from the community. Thank you very much!
I had to make a small adjustment to the script because there was a
"\n" at the end of the command.
Solved it by replacing the command itself but perhaps this can also be done in dzVents. However I lack the skill to know how.
Code: Select all
local timestamp = osCommand('date +%s%3N| tr -d "\n"')
Full script below for anyone wanting to do the same:
Code: Select all
return {
active = true,
on = {
devices = {
'Doorsensor - Hall',
'Windowsensor - Bedroom',
'Dimmer - Mechanical Home Ventilation',
}
},
logging = {
level = domoticz.LOG_DEBUG,
marker = 'testl'
},
execute = function(domoticz, item)
local function osCommand(cmd)
domoticz.log('Executing Command: ' .. cmd,domoticz.LOG_DEBUG)
local fileHandle = assert(io.popen(cmd))
local commandOutput = assert(fileHandle:read('*a'))
local returnTable = {fileHandle:close()}
domoticz.log('ReturnCode: ' .. returnTable[3] .. '\ncommandOutput:\n' .. commandOutput, domoticz.LOG_DEBUG)
return commandOutput,returnTable[3] -- rc[3] contains returnCode
end
local timestamp = osCommand('date +%s%3N | tr -d "\n"')
local annotation = 'Status of sensor or device ' .. item.name .. ' changed. New status/level: ' .. item.state .. '/' .. item.level
domoticz.openURL({
url = 'http://XXX.XXX.XXX.XXX:3000/api/annotations',
headers = { ['Authorization'] = 'Bearer XXXXX', ['Content-Type'] = 'application/json' },
method = 'POST',
postData = '{"dashboardId":XX,"panelId":X,"time":' .. timestamp .. ',"timeEnd":' .. timestamp .. ',"tags":["domoticz"],"text":"' .. annotation .. '"}',
callback = 'info'
})
end
}