Hi,
You cannot pass your token (apikey) to Openiv.io as a query string like with darksky for example.
As an alternative you can use io.popen
(sorry Dannybloe, I tried to pass the -H x-access-token with your asynchronous http requests but gave up on it

)
Here is the script I came up with(dzvents):
Code: Select all
return {
on = {
timer = { 'every 30 minutes' }
},
execute = function(domoticz, triggerItem)
--check offset for DST/non-DST
--these are for timezone Brussels. change to match your timezone
local situation = os.date("%Z")
if situation == 'CET' then
offset = 1 --non-DST
else offset = 2 --DST
end
json = (loadfile "/home/root/domoticz/scripts/lua/JSON.lua")() -- For Linux
local token = 'xxxxxxxx' -- fill in your key here
local lat = 'xxxxx' --latitude
local lng = 'xxxxxx' --longitude
local config=assert(io.popen("curl -X GET 'https://api.openuv.io/api/v1/uv?lat="..lat.."&lng="..lng.."' -H 'x-access-token: '"..token))
local location = config:read('*all')
config:close()
local response = json:decode(location)
uv = tonumber(response.result.uv)
uv_max = domoticz.utils.round((response.result.uv_max),0)
uv_max_time = response.result.uv_max_time
--get hour and minutes only from time string
local hora = tonumber(string.sub(uv_max_time, 12,13)) + offset --add offset for timezone and DST to hours
local mins = string.sub(uv_max_time, 15,16)
maxtime = tostring(hora..':'..mins) --combine to HH:MM
ozone = domoticz.utils.round((response.result.ozone),0)
print('\nCurrent UV value : '..uv)
print('Highest UV value today: '..uv_max)
print('Highest UV value at: '..maxtime)
print('Current ozone value: '..ozone)
-- update your sensors with aquired values here
end
}