Hello waarenwaaren wrote: Thursday 10 December 2020 19:41I assume you changed the script because in the version I posted there is no variable "str" in line 36.Nefsolive wrote: Thursday 10 December 2020 18:19 But i still have this error:
Error: dzVents: Error: (3.0.2) astro dzVents: ...icz/scripts/dzVents/generated_scripts/Eventos do Dia.lua:36: attempt to index a number value (local 'str')
If so there is no way I can help without you sharing the script as it is now.
The only change was to add new "devKeys".
The variable "str" comes from your script "makeTime (str)"
It only gives me the error when I put "['D of the Day'] = 'day_length'," I assume it will be because it is text!
I Send the script
ty
Code: Select all
-- collect begin- and endtimes of some astro events. dzVents >= 2.4.19 (domoticz V4.10717)
local scriptVar = 'astro dzVents'
return {
on = {
timer = { 'at 17:24', 'at 06:03' }, -- twice a day to be sure and 3 min past the hour because at the hour already quite busy
httpResponses = { scriptVar }
},
logging = {
level = domoticz.LOG_ERROR,
marker = scriptVar
},
execute = function(dz, item)
-- domoticz text devices. Comment lines for devices you don't have / want
local devKeys = { -- Device names -- Key in data
['D do Dia'] = 'day_length',
['Sol do Meio-Dia'] = 'solar_noon',
['Início do Crepúsculo Civil'] = 'civil_twilight_begin',
['Fim do Crepúsculo Civil'] = 'civil_twilight_end',
['Início do Crepúsculo Náutico'] = 'nautical_twilight_begin',
['Fim do Crepúsculo Náutico'] = 'nautical_twilight_end',
['Início do Crepúsculo Astronômico'] = 'astronomical_twilight_begin',
['Fim do Crepúsculo Astronômico'] = 'astronomical_twilight_end',
}
local function TZOffset() -- in seconds
return os.difftime(os.time(), os.time(os.date('!*t'))) + (dz.time.isdst and 3600 or 0)
end
local function makeTime(str)
local pattern = '(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+)'
local runyear, runmonth, runday, runhour, runminute, runseconds = str:match(pattern)
local timestamp = os.time({year = runyear, month = runmonth, day = runday, hour = runhour, min = runminute, sec = runseconds})
return (os.date('%X',timestamp + TZOffset())):sub(1,5)
end
local function getAstroData()
url = 'https://api.sunrise-sunset.org/json' ..
'?lat=***' .. dz.settings.location.latitude ..
'&lng=***' .. dz.settings.location.longitude ..
'&formatted=0'
dz.openURL({ url = url, callback = scriptVar })
end
local function procesResults(t)
for dv, field in pairs(devKeys) do
if dz.devices(dv) and t[field] then
dz.devices(dv).updateText(makeTime(t[field]))
end
end
end
if item.isHTTPResponse then
if item.ok then
procesResults(item.json.results)
else
dz.log('problem retrieving information from sunrise-sunset.org \n' .. item.data, dz.LOG_ERROR)
end
else
getAstroData()
end
end
}