Script to display next F1 Race

Moderator: leecollings

User avatar
Brutus
Posts: 249
Joined: Friday 26 September 2014 9:33
Target OS: Windows
Domoticz version:
Location: Netherlands
Contact:

Re: Script to display next F1 Race

Post by Brutus »

elmortero wrote: Saturday 15 September 2018 17:30
Brutus wrote: Saturday 15 September 2018 17:03 I don't understand the logic when these script run:

The second checks the qualifying every 20 min every day while the qualifying only is at Saturday?

The third script checks the Driver standings, every 15 minutes on saterday, sunday or monday. At Saturday there can't be any new driver standings because the race is at Sunday.

Last thing when will the site https://ergast.com/api/f1/2018/15/qualifying update? The qualifying is already done for a couple of hours and still no data...

EDIT: Qualifying data is now online after about 2 hours. I think this is normal?
Hi,
You can of course change all the timers to your taste
About the third one: most likely I was doing tests on a Saturday while writing the script and did not want to wait until Sunday (so got the results from the previous results)

As for the update of the results (of qualify and race), that depends on the maintainer of Ergast. I believe I read somewhere that he tries to make sure to update within 4 hours.
If you want real-time results - and are willing to pay - you could subscribe to the F1.com API and adapt these scripts to get their data .
Dzvents is new for me so I looked at the following wiki page for timer options. Damm... planty of options there!

https://www.domoticz.com/wiki/DzVents:_ ... gger_rules
1x Intel NUC8i5BEK (Windows 10 x64) Domoticz on Virtualbox with DietPi.
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
28x Fibaro Modules
SMA Solar System
Daikin Airco / Heating
Denon DHT-S716H & DSW-1H
melgi
Posts: 23
Joined: Tuesday 15 August 2017 15:50
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Script to display next F1 Race

Post by melgi »

Brutus wrote:I have extended the qualifying results to a top 6 . Max doesn't always qualify in the top 3 like today ;)

Code: Select all

return {
	on = {
		timer = { 'every 20 minutes' },
		httpResponses = { 'nextF1', 'qualyF1' } -- 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 Race')
	local qboard =  domoticz.devices('F1 Kwalificatie')
	local prevQboard	= qboard.text
		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) and (triggerItem.callback == 'nextF1') then			--when a valid json is received do this
				 local name = response.json.MRData.RaceTable.Races[1].raceName
				 local country = response.json.MRData.RaceTable.Races[1].Circuit.Location.country
				 local season = response.json.MRData.RaceTable.season
				 local round = response.json.MRData.RaceTable.round
				 local qualURL = ('https://ergast.com/api/f1/'..season..'/'..round..'/qualifying.json')
				 print('Find qualify at '..qualURL)
				 local fechapura = (response.json.MRData.RaceTable.Races[1].date)   --get the date as provided(YYYY-MM-DD)
    				 _,_,y,m,d = string.find(fechapura, "(%d+)%-(%d+)%-(%d+)")
				 local fecha = (d..'/'..m..'/'..y)
				 local horapura = (response.json.MRData.RaceTable.Races[1].time) --get time as provided (GMT without offset for DST)
    				 _,_,h,mi = string.find(horapura, "(%d+):(%d+)")
				  local hora = ((h + offset)..':'..mi)
				 local race = (name..'\n'..fecha..'Starting 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
				 --now get qualify
				 print('** Fetching info from qualify')
				 --local qualURL = 'https://ergast.com/api/f1/2018/7/qualifying.json'
					domoticz.openURL({
					url = qualURL,
					method = 'GET',
					callback = 'qualyF1'
									})
			elseif  (response.ok and response.isJSON) and (triggerItem.callback == 'qualyF1') then
					local Races = #response.json.MRData.RaceTable.Races
					print('**Number of records for Qualify = '..Races)
				if Races > 0 then
				 print('** Qualify results are availabale')				
					--get data for P1
					 local P1driver = response.json.MRData.RaceTable.Races[1].QualifyingResults[1].Driver.familyName
					 local P1Const = response.json.MRData.RaceTable.Races[1].QualifyingResults[1].Constructor.name
					 local P1Q1 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[1].Q1
						 _,_,m,s = string.find(P1Q1, "(%d+):(%d+.+)")
						local P1Q1sec = ((tonumber(m) * 60) + tonumber(s))
						local P1Best = P1Q1
					 local P1Q2 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[1].Q2
						 _,_,m,s = string.find(P1Q2, "(%d+):(%d+.+)")					 
						local P1Q2sec = ((tonumber(m) * 60) + tonumber(s))
						if P1Q2sec < P1Q1sec then P1Best = P1Q2 end
					 local P1Q3 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[1].Q3
						 _,_,m,s = string.find(P1Q3, "(%d+):(%d+.+)")
						local P1Q3sec = ((tonumber(m) * 60) + tonumber(s))
						if P1Q3sec < P1Q1sec and P1Q3sec < P1Q2sec then P1Best = P1Q3 end
					print('P1Best = '..P1Best)
					--now get data for P2	
					 local P2driver = response.json.MRData.RaceTable.Races[1].QualifyingResults[2].Driver.familyName
					 local P2Const = response.json.MRData.RaceTable.Races[1].QualifyingResults[2].Constructor.name
					 local P2Q1 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[2].Q1
						 _,_,m,s = string.find(P2Q1, "(%d+):(%d+.+)")
						local P2Q1sec = ((tonumber(m) * 60) + tonumber(s))
						local P2Best = P2Q1
					 local P2Q2 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[2].Q2
						 _,_,m,s = string.find(P2Q2, "(%d+):(%d+.+)")
						local P2Q2sec = ((tonumber(m) * 60) + tonumber(s))
						if P2Q2sec < P2Q1sec then P2Best = P2Q2 end
					 local P2Q3 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[2].Q3
						 _,_,m,s = string.find(P2Q3, "(%d+):(%d+.+)")
						local P2Q3sec = ((tonumber(m) * 60) + tonumber(s))
						if P2Q3sec < P2Q1sec and P2Q3sec < P2Q2sec then P2Best = P2Q3 end
					print('P2Best = '..P2Best)					
					-- get data for P3
					 local P3driver = response.json.MRData.RaceTable.Races[1].QualifyingResults[3].Driver.familyName
					 local P3Const = response.json.MRData.RaceTable.Races[1].QualifyingResults[3].Constructor.name
					 local P3Q1 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[3].Q1
						 _,_,m,s = string.find(P3Q1, "(%d+):(%d+.+)")
						local P3Q1sec = ((tonumber(m) * 60) + tonumber(s))
						local P3Best = P3Q1
					 local P3Q2 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[3].Q2
						 _,_,m,s = string.find(P3Q2, "(%d+):(%d+.+)")
						local P3Q2sec = ((tonumber(m) * 60) + tonumber(s))
						if P3Q2sec < P3Q1sec then P3Best = P3Q2 end
					 local P3Q3 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[3].Q3
						 _,_,m,s = string.find(P3Q3, "(%d+):(%d+.+)")
						local P3Q3sec = ((tonumber(m) * 60) + tonumber(s))
						if P3Q3sec < P3Q1sec and P3Q3sec < P3Q2sec then P3Best = P3Q3 end		
					print('P3Best = '..P3Best)
					--now get data for P4	
					 local P4driver = response.json.MRData.RaceTable.Races[1].QualifyingResults[4].Driver.familyName
					 local P4Const = response.json.MRData.RaceTable.Races[1].QualifyingResults[4].Constructor.name
					 local P4Q1 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[4].Q1
						 _,_,m,s = string.find(P4Q1, "(%d+):(%d+.+)")
						local P4Q1sec = ((tonumber(m) * 60) + tonumber(s))
						local P4Best = P4Q1
					 local P4Q2 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[4].Q2
						 _,_,m,s = string.find(P4Q2, "(%d+):(%d+.+)")
						local P4Q2sec = ((tonumber(m) * 60) + tonumber(s))
						if P4Q2sec < P4Q1sec then P4Best = P4Q2 end
					 local P4Q3 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[4].Q3
						 _,_,m,s = string.find(P4Q3, "(%d+):(%d+.+)")
						local P4Q3sec = ((tonumber(m) * 60) + tonumber(s))
						if P4Q3sec < P4Q1sec and P4Q3sec < P4Q2sec then P4Best = P4Q3 end
					print('P4Best = '..P4Best)
					--now get data for P5	
					 local P5driver = response.json.MRData.RaceTable.Races[1].QualifyingResults[5].Driver.familyName
					 local P5Const = response.json.MRData.RaceTable.Races[1].QualifyingResults[5].Constructor.name
					 local P5Q1 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[5].Q1
						 _,_,m,s = string.find(P5Q1, "(%d+):(%d+.+)")
						local P5Q1sec = ((tonumber(m) * 60) + tonumber(s))
						local P5Best = P5Q1
					 local P5Q2 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[5].Q2
						 _,_,m,s = string.find(P5Q2, "(%d+):(%d+.+)")
						local P5Q2sec = ((tonumber(m) * 60) + tonumber(s))
						if P5Q2sec < P4Q1sec then P5Best = P4Q2 end
					 local P5Q3 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[5].Q3
						 _,_,m,s = string.find(P5Q3, "(%d+):(%d+.+)")
						local P5Q3sec = ((tonumber(m) * 60) + tonumber(s))
						if P5Q3sec < P5Q1sec and P5Q3sec < P5Q2sec then P5Best = P5Q3 end
					print('P5Best = '..P5Best)	
					--now get data for P6	
					 local P6driver = response.json.MRData.RaceTable.Races[1].QualifyingResults[6].Driver.familyName
					 local P6Const = response.json.MRData.RaceTable.Races[1].QualifyingResults[6].Constructor.name
					 local P6Q1 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[6].Q1
						 _,_,m,s = string.find(P6Q1, "(%d+):(%d+.+)")
						local P6Q1sec = ((tonumber(m) * 60) + tonumber(s))
						local P6Best = P4Q1
					 local P6Q2 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[6].Q2
						 _,_,m,s = string.find(P6Q2, "(%d+):(%d+.+)")
						local P6Q2sec = ((tonumber(m) * 60) + tonumber(s))
						if P6Q2sec < P6Q1sec then P6Best = P6Q2 end
					 local P6Q3 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[6].Q3
						 _,_,m,s = string.find(P6Q3, "(%d+):(%d+.+)")
						local P6Q3sec = ((tonumber(m) * 60) + tonumber(s))
						if P6Q3sec < P6Q1sec and P6Q3sec < P6Q2sec then P6Best = P6Q3 end
					print('P6Best = '..P6Best)	
					local Qresults = ('1. '..P1driver..'('..P1Const..') - '..P1Best..'\n2. '..P2driver..'('..P2Const..') - '..P2Best..'\n3. '..P3driver..'('..P3Const..') - '..P3Best..'\n4. '..P4driver..'('..P4Const..') - '..P4Best..'\n5. '..P5driver..'('..P5Const..') - '..P5Best..'\n6. '..P6driver..'('..P6Const..') - '..P6Best)
					local QresultsPrint = ('\n'..Qresults)
					print(Qresults)		

    				if Qresults ~= prevQboard then
    				 qboard.updateText(Qresults)
    				 end
				--end
				end
Brutus, I'd like to use your script. I have a virtual sensor called "F1" and two text switches called "F1 Race" and "F1 Quali". What do I need to change in your script to have it work for me too?

Verstuurd vanaf mijn SM-G955F met Tapatalk

User avatar
Brutus
Posts: 249
Joined: Friday 26 September 2014 9:33
Target OS: Windows
Domoticz version:
Location: Netherlands
Contact:

Re: Script to display next F1 Race

Post by Brutus »

@melgi

I don't know why u need a Virtual Sensor called "F1"?

But for now you need the change this:

Code: Select all

	local sensor =  domoticz.devices('F1 Race')
	local qboard =  domoticz.devices('F1 Kwalificatie')
To this:

Code: Select all

	local sensor =  domoticz.devices('F1 Race')
	local qboard =  domoticz.devices('F1 Quali')
1x Intel NUC8i5BEK (Windows 10 x64) Domoticz on Virtualbox with DietPi.
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
28x Fibaro Modules
SMA Solar System
Daikin Airco / Heating
Denon DHT-S716H & DSW-1H
melgi
Posts: 23
Joined: Tuesday 15 August 2017 15:50
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Script to display next F1 Race

Post by melgi »

Brutus, thanx for your reply. Will try that. In my post I made a mistake. The "F1" is actually the Dummy I created in the Hardware section. On this hardware I created the said virtual text sensors.

Verstuurd vanaf mijn SM-G955F met Tapatalk

Furiousz23
Posts: 27
Joined: Saturday 30 December 2017 20:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10199
Location: Nederland
Contact:

Re: Script to display next F1 Race

Post by Furiousz23 »

Great script! Now i don`t have to open the Ziggo app anymore to check when the race is starting :mrgreen: . Now i have to figure out how to get a Telegram notification through Domoticz one hour before the start of the race.
User avatar
Brutus
Posts: 249
Joined: Friday 26 September 2014 9:33
Target OS: Windows
Domoticz version:
Location: Netherlands
Contact:

Re: Script to display next F1 Race

Post by Brutus »

Furiousz23 wrote: Saturday 15 September 2018 20:05 Great script! Now i don`t have to open the Ziggo app anymore to check when the race is starting :mrgreen: . Now i have to figure out how to get a Telegram notification through Domoticz one hour before the start of the race.
That would be cool indeed.
1x Intel NUC8i5BEK (Windows 10 x64) Domoticz on Virtualbox with DietPi.
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
28x Fibaro Modules
SMA Solar System
Daikin Airco / Heating
Denon DHT-S716H & DSW-1H
melgi
Posts: 23
Joined: Tuesday 15 August 2017 15:50
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Script to display next F1 Race

Post by melgi »

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.
Mdieli
Posts: 12
Joined: Saturday 14 February 2015 11:18
Target OS: Linux
Domoticz version: BETA
Location: The Netherlands
Contact:

Re: Script to display next F1 Race

Post by Mdieli »

For some reason, since a couple of months the time is not shown correct anymore.
instead of
Example Grand Prix at 15:10
it shows
Example Grand Prix at 15.0:10


When i remove the addition of the offset, the time is shown correctly.

Original code:
local HH = (string.sub(horapura, 1,2) + offset); local MM = string.sub(horapura, 4,5); local hora = (HH..':'..MM)
Removed the offset:
local HH = (string.sub(horapura, 1,2)); local MM = string.sub(horapura, 4,5); local hora = (HH..':'..MM)
So my best educated guess is that the mistake is happening with rounding of the "offset" value.
However, i'm no programmer and have absolutely no clue how to solve this.
Do you have any ideas I can try?
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: Script to display next F1 Race

Post by elmortero »

Hi, I hadn't noticed actually since there are no GPs in the near future :-P

I think - but no time to check now - that it has to do with the upgrade to LUA 5.3

It is strange that by removing the offset you get the correct time as it is in UTC.
Quick (and dirty) fix for now:
Change this line:
local hora = ((h + offset)..':'..mi)
into : local hora = (math.floor(h + offset)..':'..mi)
That will get rid of the .0 decimal
Snowtiger
Posts: 120
Joined: Tuesday 18 October 2016 13:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10915
Contact:

Re: Script to display next F1 Race

Post by Snowtiger »

elmortero wrote:Hi, I hadn't noticed actually since there are no GPs in the near future :-P

I think - but no time to check now - that it has to do with the upgrade to LUA 5.3

It is strange that by removing the offset you get the correct time as it is in UTC.
Quick (and dirty) fix for now:
Change this line:
local hora = ((h + offset)..':'..mi)
into : local hora = (math.floor(h + offset)..':'..mi)
That will get rid of the .0 decimal
Correct, since 5.3 - Introduction of an integer subtype for numbers with as side effect that a conversion of a float to a string now adds a .0 suffix to
the result if it looks like an integer. (For instance, the float 2.0 will be printed as 2.0, not as 2 )
Mdieli
Posts: 12
Joined: Saturday 14 February 2015 11:18
Target OS: Linux
Domoticz version: BETA
Location: The Netherlands
Contact:

Re: Script to display next F1 Race

Post by Mdieli »

elmortero wrote: Wednesday 29 April 2020 12:14 Hi, I hadn't noticed actually since there are no GPs in the near future :-P

I think - but no time to check now - that it has to do with the upgrade to LUA 5.3

It is strange that by removing the offset you get the correct time as it is in UTC.
Quick (and dirty) fix for now:
Change this line:
local hora = ((h + offset)..':'..mi)
into : local hora = (math.floor(h + offset)..':'..mi)
That will get rid of the .0 decimal
Thank you for your quick response, the solution works like a charm!
Drees
Posts: 8
Joined: Monday 06 June 2022 16:00
Target OS: Windows
Domoticz version:
Contact:

Re: Script to display next F1 Race

Post by Drees »

Brutus wrote: Saturday 15 September 2018 17:42 I have extended the qualifying results to a top 6 . Max doesn't always qualify in the top 3 like today ;)

Code: Select all

return {
	on = {
		timer = { 'every 20 minutes' },
		httpResponses = { 'nextF1', 'qualyF1' } -- 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 Race')
	local qboard =  domoticz.devices('F1 Kwalificatie')
	local prevQboard	= qboard.text
		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) and (triggerItem.callback == 'nextF1') then			--when a valid json is received do this
				 local name = response.json.MRData.RaceTable.Races[1].raceName
				 local country = response.json.MRData.RaceTable.Races[1].Circuit.Location.country
				 local season = response.json.MRData.RaceTable.season
				 local round = response.json.MRData.RaceTable.round
				 local qualURL = ('https://ergast.com/api/f1/'..season..'/'..round..'/qualifying.json')
				 print('Find qualify at '..qualURL)
				 local fechapura = (response.json.MRData.RaceTable.Races[1].date)   --get the date as provided(YYYY-MM-DD)
    				 _,_,y,m,d = string.find(fechapura, "(%d+)%-(%d+)%-(%d+)")
				 local fecha = (d..'/'..m..'/'..y)
				 local horapura = (response.json.MRData.RaceTable.Races[1].time) --get time as provided (GMT without offset for DST)
    				 _,_,h,mi = string.find(horapura, "(%d+):(%d+)")
				  local hora = ((h + offset)..':'..mi)
				 local race = (name..'\n'..fecha..'Starting 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
				 --now get qualify
				 print('** Fetching info from qualify')
				 --local qualURL = 'https://ergast.com/api/f1/2018/7/qualifying.json'
					domoticz.openURL({
					url = qualURL,
					method = 'GET',
					callback = 'qualyF1'
									})
			elseif  (response.ok and response.isJSON) and (triggerItem.callback == 'qualyF1') then
					local Races = #response.json.MRData.RaceTable.Races
					print('**Number of records for Qualify = '..Races)
				if Races > 0 then
				 print('** Qualify results are availabale')				
					--get data for P1
					 local P1driver = response.json.MRData.RaceTable.Races[1].QualifyingResults[1].Driver.familyName
					 local P1Const = response.json.MRData.RaceTable.Races[1].QualifyingResults[1].Constructor.name
					 local P1Q1 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[1].Q1
						 _,_,m,s = string.find(P1Q1, "(%d+):(%d+.+)")
						local P1Q1sec = ((tonumber(m) * 60) + tonumber(s))
						local P1Best = P1Q1
					 local P1Q2 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[1].Q2
						 _,_,m,s = string.find(P1Q2, "(%d+):(%d+.+)")					 
						local P1Q2sec = ((tonumber(m) * 60) + tonumber(s))
						if P1Q2sec < P1Q1sec then P1Best = P1Q2 end
					 local P1Q3 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[1].Q3
						 _,_,m,s = string.find(P1Q3, "(%d+):(%d+.+)")
						local P1Q3sec = ((tonumber(m) * 60) + tonumber(s))
						if P1Q3sec < P1Q1sec and P1Q3sec < P1Q2sec then P1Best = P1Q3 end
					print('P1Best = '..P1Best)
					--now get data for P2	
					 local P2driver = response.json.MRData.RaceTable.Races[1].QualifyingResults[2].Driver.familyName
					 local P2Const = response.json.MRData.RaceTable.Races[1].QualifyingResults[2].Constructor.name
					 local P2Q1 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[2].Q1
						 _,_,m,s = string.find(P2Q1, "(%d+):(%d+.+)")
						local P2Q1sec = ((tonumber(m) * 60) + tonumber(s))
						local P2Best = P2Q1
					 local P2Q2 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[2].Q2
						 _,_,m,s = string.find(P2Q2, "(%d+):(%d+.+)")
						local P2Q2sec = ((tonumber(m) * 60) + tonumber(s))
						if P2Q2sec < P2Q1sec then P2Best = P2Q2 end
					 local P2Q3 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[2].Q3
						 _,_,m,s = string.find(P2Q3, "(%d+):(%d+.+)")
						local P2Q3sec = ((tonumber(m) * 60) + tonumber(s))
						if P2Q3sec < P2Q1sec and P2Q3sec < P2Q2sec then P2Best = P2Q3 end
					print('P2Best = '..P2Best)					
					-- get data for P3
					 local P3driver = response.json.MRData.RaceTable.Races[1].QualifyingResults[3].Driver.familyName
					 local P3Const = response.json.MRData.RaceTable.Races[1].QualifyingResults[3].Constructor.name
					 local P3Q1 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[3].Q1
						 _,_,m,s = string.find(P3Q1, "(%d+):(%d+.+)")
						local P3Q1sec = ((tonumber(m) * 60) + tonumber(s))
						local P3Best = P3Q1
					 local P3Q2 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[3].Q2
						 _,_,m,s = string.find(P3Q2, "(%d+):(%d+.+)")
						local P3Q2sec = ((tonumber(m) * 60) + tonumber(s))
						if P3Q2sec < P3Q1sec then P3Best = P3Q2 end
					 local P3Q3 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[3].Q3
						 _,_,m,s = string.find(P3Q3, "(%d+):(%d+.+)")
						local P3Q3sec = ((tonumber(m) * 60) + tonumber(s))
						if P3Q3sec < P3Q1sec and P3Q3sec < P3Q2sec then P3Best = P3Q3 end		
					print('P3Best = '..P3Best)
					--now get data for P4	
					 local P4driver = response.json.MRData.RaceTable.Races[1].QualifyingResults[4].Driver.familyName
					 local P4Const = response.json.MRData.RaceTable.Races[1].QualifyingResults[4].Constructor.name
					 local P4Q1 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[4].Q1
						 _,_,m,s = string.find(P4Q1, "(%d+):(%d+.+)")
						local P4Q1sec = ((tonumber(m) * 60) + tonumber(s))
						local P4Best = P4Q1
					 local P4Q2 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[4].Q2
						 _,_,m,s = string.find(P4Q2, "(%d+):(%d+.+)")
						local P4Q2sec = ((tonumber(m) * 60) + tonumber(s))
						if P4Q2sec < P4Q1sec then P4Best = P4Q2 end
					 local P4Q3 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[4].Q3
						 _,_,m,s = string.find(P4Q3, "(%d+):(%d+.+)")
						local P4Q3sec = ((tonumber(m) * 60) + tonumber(s))
						if P4Q3sec < P4Q1sec and P4Q3sec < P4Q2sec then P4Best = P4Q3 end
					print('P4Best = '..P4Best)
					--now get data for P5	
					 local P5driver = response.json.MRData.RaceTable.Races[1].QualifyingResults[5].Driver.familyName
					 local P5Const = response.json.MRData.RaceTable.Races[1].QualifyingResults[5].Constructor.name
					 local P5Q1 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[5].Q1
						 _,_,m,s = string.find(P5Q1, "(%d+):(%d+.+)")
						local P5Q1sec = ((tonumber(m) * 60) + tonumber(s))
						local P5Best = P5Q1
					 local P5Q2 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[5].Q2
						 _,_,m,s = string.find(P5Q2, "(%d+):(%d+.+)")
						local P5Q2sec = ((tonumber(m) * 60) + tonumber(s))
						if P5Q2sec < P4Q1sec then P5Best = P4Q2 end
					 local P5Q3 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[5].Q3
						 _,_,m,s = string.find(P5Q3, "(%d+):(%d+.+)")
						local P5Q3sec = ((tonumber(m) * 60) + tonumber(s))
						if P5Q3sec < P5Q1sec and P5Q3sec < P5Q2sec then P5Best = P5Q3 end
					print('P5Best = '..P5Best)	
					--now get data for P6	
					 local P6driver = response.json.MRData.RaceTable.Races[1].QualifyingResults[6].Driver.familyName
					 local P6Const = response.json.MRData.RaceTable.Races[1].QualifyingResults[6].Constructor.name
					 local P6Q1 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[6].Q1
						 _,_,m,s = string.find(P6Q1, "(%d+):(%d+.+)")
						local P6Q1sec = ((tonumber(m) * 60) + tonumber(s))
						local P6Best = P4Q1
					 local P6Q2 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[6].Q2
						 _,_,m,s = string.find(P6Q2, "(%d+):(%d+.+)")
						local P6Q2sec = ((tonumber(m) * 60) + tonumber(s))
						if P6Q2sec < P6Q1sec then P6Best = P6Q2 end
					 local P6Q3 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[6].Q3
						 _,_,m,s = string.find(P6Q3, "(%d+):(%d+.+)")
						local P6Q3sec = ((tonumber(m) * 60) + tonumber(s))
						if P6Q3sec < P6Q1sec and P6Q3sec < P6Q2sec then P6Best = P6Q3 end
					print('P6Best = '..P6Best)	
					local Qresults = ('1. '..P1driver..'('..P1Const..') - '..P1Best..'\n2. '..P2driver..'('..P2Const..') - '..P2Best..'\n3. '..P3driver..'('..P3Const..') - '..P3Best..'\n4. '..P4driver..'('..P4Const..') - '..P4Best..'\n5. '..P5driver..'('..P5Const..') - '..P5Best..'\n6. '..P6driver..'('..P6Const..') - '..P6Best)
					local QresultsPrint = ('\n'..Qresults)
					print(Qresults)		

    				if Qresults ~= prevQboard then
    				 qboard.updateText(Qresults)
    				 end
				--end
				end
I was trying to use this script.
i copy paste the script, but when i look at the error log i got the message

Code: Select all

 2022-10-16 14:14:39.011 Error: dzVents: Error: (3.1.8) error loading module 'F1_Quali3' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/F1_Quali3.lua':
2022-10-16 14:14:39.011 ...domoticz/scripts/dzVents/generated_scripts/F1_Quali3.lua:165: 'end' expected (to close 'function' at line 10) near <eof> 
It looks like there is missing a [END] but i don't see where i have to put the [END].
But I'm not sure about it, because i cant be the fist one in 2 your who notice this.

i hope someone with code skills can help me.
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: Script to display next F1 Race

Post by elmortero »

Hi

Looks like you missed some end to close the if loops (@lines 54, 164 and 165) and a closing } at the end of the script.
I haven't tried but this should fix it (moved the script to Python now)

Code: Select all

return {
	on = {
		timer = { 'every 20 minutes' },
		httpResponses = { 'nextF1', 'qualyF1' } -- 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 Race')
	local qboard =  domoticz.devices('F1 Kwalificatie')
	local prevQboard	= qboard.text
		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) and (triggerItem.callback == 'nextF1') then			--when a valid json is received do this
				 local name = response.json.MRData.RaceTable.Races[1].raceName
				 local country = response.json.MRData.RaceTable.Races[1].Circuit.Location.country
				 local season = response.json.MRData.RaceTable.season
				 local round = response.json.MRData.RaceTable.round
				 local qualURL = ('https://ergast.com/api/f1/'..season..'/'..round..'/qualifying.json')
				 print('Find qualify at '..qualURL)
				 local fechapura = (response.json.MRData.RaceTable.Races[1].date)   --get the date as provided(YYYY-MM-DD)
    				 _,_,y,m,d = string.find(fechapura, "(%d+)%-(%d+)%-(%d+)")
				 local fecha = (d..'/'..m..'/'..y)
				 local horapura = (response.json.MRData.RaceTable.Races[1].time) --get time as provided (GMT without offset for DST)
    				 _,_,h,mi = string.find(horapura, "(%d+):(%d+)")
				  local hora = ((h + offset)..':'..mi)
				 local race = (name..'\n'..fecha..'Starting 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
				 --now get qualify
				 print('** Fetching info from qualify')
				 --local qualURL = 'https://ergast.com/api/f1/2018/7/qualifying.json'
					domoticz.openURL({
					url = qualURL,
					method = 'GET',
					callback = 'qualyF1'
									})
				end
			elseif  (response.ok and response.isJSON) and (triggerItem.callback == 'qualyF1') then
					local Races = #response.json.MRData.RaceTable.Races
					print('**Number of records for Qualify = '..Races)
				if Races > 0 then
				 print('** Qualify results are availabale')				
					--get data for P1
					 local P1driver = response.json.MRData.RaceTable.Races[1].QualifyingResults[1].Driver.familyName
					 local P1Const = response.json.MRData.RaceTable.Races[1].QualifyingResults[1].Constructor.name
					 local P1Q1 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[1].Q1
						 _,_,m,s = string.find(P1Q1, "(%d+):(%d+.+)")
						local P1Q1sec = ((tonumber(m) * 60) + tonumber(s))
						local P1Best = P1Q1
					 local P1Q2 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[1].Q2
						 _,_,m,s = string.find(P1Q2, "(%d+):(%d+.+)")					 
						local P1Q2sec = ((tonumber(m) * 60) + tonumber(s))
						if P1Q2sec < P1Q1sec then P1Best = P1Q2 end
					 local P1Q3 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[1].Q3
						 _,_,m,s = string.find(P1Q3, "(%d+):(%d+.+)")
						local P1Q3sec = ((tonumber(m) * 60) + tonumber(s))
						if P1Q3sec < P1Q1sec and P1Q3sec < P1Q2sec then P1Best = P1Q3 end
					print('P1Best = '..P1Best)
					--now get data for P2	
					 local P2driver = response.json.MRData.RaceTable.Races[1].QualifyingResults[2].Driver.familyName
					 local P2Const = response.json.MRData.RaceTable.Races[1].QualifyingResults[2].Constructor.name
					 local P2Q1 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[2].Q1
						 _,_,m,s = string.find(P2Q1, "(%d+):(%d+.+)")
						local P2Q1sec = ((tonumber(m) * 60) + tonumber(s))
						local P2Best = P2Q1
					 local P2Q2 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[2].Q2
						 _,_,m,s = string.find(P2Q2, "(%d+):(%d+.+)")
						local P2Q2sec = ((tonumber(m) * 60) + tonumber(s))
						if P2Q2sec < P2Q1sec then P2Best = P2Q2 end
					 local P2Q3 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[2].Q3
						 _,_,m,s = string.find(P2Q3, "(%d+):(%d+.+)")
						local P2Q3sec = ((tonumber(m) * 60) + tonumber(s))
						if P2Q3sec < P2Q1sec and P2Q3sec < P2Q2sec then P2Best = P2Q3 end
					print('P2Best = '..P2Best)					
					-- get data for P3
					 local P3driver = response.json.MRData.RaceTable.Races[1].QualifyingResults[3].Driver.familyName
					 local P3Const = response.json.MRData.RaceTable.Races[1].QualifyingResults[3].Constructor.name
					 local P3Q1 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[3].Q1
						 _,_,m,s = string.find(P3Q1, "(%d+):(%d+.+)")
						local P3Q1sec = ((tonumber(m) * 60) + tonumber(s))
						local P3Best = P3Q1
					 local P3Q2 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[3].Q2
						 _,_,m,s = string.find(P3Q2, "(%d+):(%d+.+)")
						local P3Q2sec = ((tonumber(m) * 60) + tonumber(s))
						if P3Q2sec < P3Q1sec then P3Best = P3Q2 end
					 local P3Q3 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[3].Q3
						 _,_,m,s = string.find(P3Q3, "(%d+):(%d+.+)")
						local P3Q3sec = ((tonumber(m) * 60) + tonumber(s))
						if P3Q3sec < P3Q1sec and P3Q3sec < P3Q2sec then P3Best = P3Q3 end		
					print('P3Best = '..P3Best)
					--now get data for P4	
					 local P4driver = response.json.MRData.RaceTable.Races[1].QualifyingResults[4].Driver.familyName
					 local P4Const = response.json.MRData.RaceTable.Races[1].QualifyingResults[4].Constructor.name
					 local P4Q1 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[4].Q1
						 _,_,m,s = string.find(P4Q1, "(%d+):(%d+.+)")
						local P4Q1sec = ((tonumber(m) * 60) + tonumber(s))
						local P4Best = P4Q1
					 local P4Q2 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[4].Q2
						 _,_,m,s = string.find(P4Q2, "(%d+):(%d+.+)")
						local P4Q2sec = ((tonumber(m) * 60) + tonumber(s))
						if P4Q2sec < P4Q1sec then P4Best = P4Q2 end
					 local P4Q3 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[4].Q3
						 _,_,m,s = string.find(P4Q3, "(%d+):(%d+.+)")
						local P4Q3sec = ((tonumber(m) * 60) + tonumber(s))
						if P4Q3sec < P4Q1sec and P4Q3sec < P4Q2sec then P4Best = P4Q3 end
					print('P4Best = '..P4Best)
					--now get data for P5	
					 local P5driver = response.json.MRData.RaceTable.Races[1].QualifyingResults[5].Driver.familyName
					 local P5Const = response.json.MRData.RaceTable.Races[1].QualifyingResults[5].Constructor.name
					 local P5Q1 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[5].Q1
						 _,_,m,s = string.find(P5Q1, "(%d+):(%d+.+)")
						local P5Q1sec = ((tonumber(m) * 60) + tonumber(s))
						local P5Best = P5Q1
					 local P5Q2 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[5].Q2
						 _,_,m,s = string.find(P5Q2, "(%d+):(%d+.+)")
						local P5Q2sec = ((tonumber(m) * 60) + tonumber(s))
						if P5Q2sec < P4Q1sec then P5Best = P4Q2 end
					 local P5Q3 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[5].Q3
						 _,_,m,s = string.find(P5Q3, "(%d+):(%d+.+)")
						local P5Q3sec = ((tonumber(m) * 60) + tonumber(s))
						if P5Q3sec < P5Q1sec and P5Q3sec < P5Q2sec then P5Best = P5Q3 end
					print('P5Best = '..P5Best)	
					--now get data for P6	
					 local P6driver = response.json.MRData.RaceTable.Races[1].QualifyingResults[6].Driver.familyName
					 local P6Const = response.json.MRData.RaceTable.Races[1].QualifyingResults[6].Constructor.name
					 local P6Q1 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[6].Q1
						 _,_,m,s = string.find(P6Q1, "(%d+):(%d+.+)")
						local P6Q1sec = ((tonumber(m) * 60) + tonumber(s))
						local P6Best = P4Q1
					 local P6Q2 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[6].Q2
						 _,_,m,s = string.find(P6Q2, "(%d+):(%d+.+)")
						local P6Q2sec = ((tonumber(m) * 60) + tonumber(s))
						if P6Q2sec < P6Q1sec then P6Best = P6Q2 end
					 local P6Q3 =  response.json.MRData.RaceTable.Races[1].QualifyingResults[6].Q3
						 _,_,m,s = string.find(P6Q3, "(%d+):(%d+.+)")
						local P6Q3sec = ((tonumber(m) * 60) + tonumber(s))
						if P6Q3sec < P6Q1sec and P6Q3sec < P6Q2sec then P6Best = P6Q3 end
					print('P6Best = '..P6Best)	
					local Qresults = ('1. '..P1driver..'('..P1Const..') - '..P1Best..'\n2. '..P2driver..'('..P2Const..') - '..P2Best..'\n3. '..P3driver..'('..P3Const..') - '..P3Best..'\n4. '..P4driver..'('..P4Const..') - '..P4Best..'\n5. '..P5driver..'('..P5Const..') - '..P5Best..'\n6. '..P6driver..'('..P6Const..') - '..P6Best)
					local QresultsPrint = ('\n'..Qresults)
					print(Qresults)		

    				if Qresults ~= prevQboard then
    				 qboard.updateText(Qresults)
    				 end
			end
		end
end
}

User avatar
HansieNL
Posts: 957
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Script to display next F1 Race

Post by HansieNL »

Because there's no new F1 Race information yet I get the following errors every day now:

Code: Select all

2022-11-27 10:00:04.459 Error: dzVents: Error: (3.1.8) An error occurred when calling event handler f1
2022-11-27 10:00:04.459 Error: dzVents: Error: (3.1.8) /home/pi/domoticz/scripts/dzVents/scripts/f1.lua:29: attempt to index a nil value (field '?') 
I'm using the 1st script from the 1st page. Line 29 contains:

Code: Select all

local name = response.json.MRData.RaceTable.Races[1].raceName
Can someone tell me how to get rid of the errors?
Thanks in advance.
Blah blah blah
User avatar
waltervl
Posts: 5149
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Script to display next F1 Race

Post by waltervl »

When I check if https://ergast.com/api/f1/current/next.json I get answer "Unable to select database" which is no json.

So line

Code: Select all

if (response.ok and response.isJSON) and (triggerItem.callback == 'nextF1') then
should fail as response.isJSON is false.

Do you have response.isJSON in your script?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
HansieNL
Posts: 957
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Script to display next F1 Race

Post by HansieNL »

waltervl wrote: Monday 28 November 2022 16:43 When I check if https://ergast.com/api/f1/current/next.json I get answer "Unable to select database" which is no json.
I get the following info now when I check https://ergast.com/api/f1/current/next.json

Code: Select all

{"MRData":{"xmlns":"http:\/\/ergast.com\/mrd\/1.5","series":"f1","url":"http://ergast.com/api/f1/current/next.json","limit":"30","offset":"0","total":"0","RaceTable":{"season":"2023","round":"1","Races":[]}}}
I have the following code in the script:

Code: Select all

if (response.ok and response.isJSON) then
There's no next race data available right now. Can that be the reason for the error message?
Blah blah blah
User avatar
JustDude
Posts: 16
Joined: Thursday 23 February 2023 18:15
Target OS: Linux
Domoticz version: Latest
Location: NL
Contact:

Re: Script to display next F1 Race

Post by JustDude »

I extended the script yesterday evening with the Qualifying date/time information, the text is overwritten after Qualification with the results.
However I could not test that last bit ;) Any tips for improving or correction are welcome.

And it looks like this:
Selection_002.png
Selection_002.png (11.67 KiB) Viewed 1617 times
I added the code below after the F1 text update

Code: Select all

			
	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
followed by

Code: Select all

			-- get Quali date / time (is re-used for Q results after the Qualification)
			local qdateraw = (response.json.MRData.RaceTable.Races[1].Qualifying.date) 
				_,_,y,m,d = string.find(qdateraw, "(%d+)%-(%d+)%-(%d+)")
			local qdate = (d..'/'..m..'/'..y)
			local qtimeraw = (response.json.MRData.RaceTable.Races[1].Qualifying.time) 
				_,_,h,mi = string.find(qtimeraw, "(%d+):(%d+)")
			local qtime = (math.floor(h + offset)..':'..mi)
			local quali = (name..'\n'..qdate..' Starting at '..qtime)
			if qboard ~= quali then              --Only update text sensor if current info is different from the stored info
				qboard.updateText(quali)           
				domoticz.data.nextQF1 = qboard       --write the new info to global variable
				qboard.updateText(quali)
			end
Declare domoticz.data.nextQF1 at the top
---
Measuring is knowing
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests