I still can't get this to work
.
THIS SCRIPT DOESN'T WORK FOR ME:
return {
on = {
timer = { 'every 2 minutes on sat, sun, mon, tu, wed, thu, fri' }
--timer = { 'at 10:00' },
httpResponses = { 'nextF1' } -- matches callback string below
},
data = {
nextF1 = { initial = nil }
},
execute = function(domoticz, triggerItem)
if situation == 'CET' then -- check for DST
offset = 1 -- offset for timezone Madrid Winter time
else offset = 2 -- offset for timezone Madrid Summer time, change these values to match your timezone
end
local board = domoticz.data.nextF1
local sensor = domoticz.devices('F1_next_race') -- name of my virtual text sensor
if (triggerItem.isTimer) then
domoticz.openURL({
url = '
https://ergast.com/api/f1/current/next.json',
method = 'GET',
callback = 'nextF1'
})
elseif (triggerItem.isHTTPResponse) then
local response = triggerItem
if (response.ok and response.isJSON) then --when a valid json is received do this
local name = response.json.MRData.RaceTable.Races[1].raceName
local fechapura = (response.json.MRData.RaceTable.Races[1].date) --get the date as provided(YYYY-MM-DD)
--Next line converts it to DD-MM-YYYY, you can delete it if you are OK with provided date format
local YY = string.sub(fechapura, 1,4); local MM = string.sub(fechapura, 6,7); local DD = string.sub(fechapura, 9,10); local fecha = (DD..'-'..MM..'-'..YY)
local horapura = (response.json.MRData.RaceTable.Races[1].time) --get time as provided (GMT without offset for DST)
--convert provided time to time in your timezone
local HH = (string.sub(horapura, 1,2) + offset); local MM = string.sub(horapura, 4,5); local hora = (HH..':'..MM)
local race = (name..'\n'..fecha..' at '..hora)
if board ~= race then --Only update text sensor if current info is different from the stored info
sensor.updateText(race)
domoticz.data.nextF1 = race --write the new info to global variable
end
else
print('**nextF1 failed to fetch info')
end --end of actions after valid json received
end
end
}
THIS SCRIPT WORKS FOR ME:
return {
on = {
timer = { 'every 2 minutes on sat, sun, mon, tu, wed, thu, fri' }, --{ 'at *:22', 'every 15 minutes on sat, sun, mon, tu, wed, thu, fri' },
httpResponses = { 'F1-Top3' },
devices = {'F1'}
},
execute = function(domoticz, triggerItem)
local board = domoticz.devices('F1 race') --a virtual text sensor
local prevboard = tostring(board.text) --get current value of text sensor
if (triggerItem.isTimer) then
domoticz.openURL({
url = '
https://ergast.com/api/f1/current/driverStandings.json',
method = 'GET',
callback = 'F1-Top3'
})
elseif (triggerItem.isHTTPResponse) then
local response = triggerItem
if (response.ok and response.isJSON) then
local pInfo = ''
local bInfo = ''
tl = 5
tc = 1
repeat
local code = tostring(response.json.MRData.StandingsTable.StandingsLists[1].DriverStandings[tc].Driver.code)
local points = tostring(response.json.MRData.StandingsTable.StandingsLists[1].DriverStandings[tc].points)
local const = tostring(response.json.MRData.StandingsTable.StandingsLists[1].DriverStandings[tc].Constructors[1].name)
local pos = tostring(response.json.MRData.StandingsTable.StandingsLists[1].DriverStandings[tc].position)
if string.len(points) < 3 then points = (' '..points) end
local Full = (pos..'. '..code..' '..points..' '..const..'\n')
tc = tc + 1
pInfo = (pInfo..Full)
until tc == tl + 1
if pInfo ~= prevboard then
board.updateText(pInfo)
end
else
print('** F1-Top3 failed to fetch info')
end
end
end
}
What am I doing wrong? I'm just starting to use dzVents and trying really hard to understand this. Sadly I can't see any log from running this script. Maybe it contains the errors that show up while running this script. If only I could read/see them, I could try to figure out what is going wrong here.