Script for Airplanes.live api

In this subforum you can show projects you have made, or you are busy with. Please create your own topic.

Moderator: leecollings

janpep
Posts: 212
Joined: Thursday 14 March 2024 10:11
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Script for Airplanes.live api

Post by janpep »

PieterS wrote: Tuesday 25 June 2024 18:50 Only next goal is export to a csv-file so that I can filter.
Nice.
For appending to csv file, you just have to enter a path and set the variable 'ap_useCSVfile' to 1
Domoticz in Ubuntu virtual machine on Synology DS718+ behind FRITZ!Box.
Using: EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
janpep
Posts: 212
Joined: Thursday 14 March 2024 10:11
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Script for Airplanes.live api

Post by janpep »

Finishing touch is in the icon :-). (See first post)
Domoticz in Ubuntu virtual machine on Synology DS718+ behind FRITZ!Box.
Using: EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
PieterS
Posts: 195
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: NL
Contact:

Re: Script for Airplanes.live api

Post by PieterS »

For appending to csv file, you just have to enter a path and set the variable 'ap_useCSVfile' to 1
Found it allready. No airplanes up till now.
Finishing touch is in the icon :-). (See first post)
Yes, first things first.

Image

Thnx Jan!
Synology with Domoticz build (V2024.7) in Docker
PieterS
Posts: 195
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: NL
Contact:

Re: Script for Airplanes.live api

Post by PieterS »

This morning the airport decided to change to start the planes in another direction.. :?
The application does a good job. But it does not create a csv-file. Wondering about how to write a correct notation of the location of that file.

Some trial and errors in the settings that did not work out:

Code: Select all

--- Your settings ----------------------------------------------------------------
-- First set the used device index numbers and variables you might want to change.
---#################################################################
local ap_text_idx = 2559       --idx of the custom Text device
local ap_counter_idx = 2560    --idx of the optional incremental counter device. (or 99999 if not confugured)

local ap_maxRadiusKm = 3    -- Query max radius in KM around your coordinates.
local ap_maxAltitudeM = 2500    -- Save only < max ap_maxAltitude in Meters.
local ap_useCSVfile = 1          -- 0 = NO csv file, or 1 = Save airplanes also in csv file.
-- local ap_csvFile = '../scripts/dzVents/scripts/SavedAirplanes.csv'
-- local ap_csvFile = '/scripts/dzVents/scripts/SavedAirplanes.csv'
local ap_csvFile = '/<pathtoyourfile>/SavedAirplanes.csv'
local ap_pollFreq = 15  --Poll frequency in seconds. Default 15. Normally > 1 and < 60.

----------------------------------------------------------------------------------
This a look into the filesystem. The file airplanes.lua is in the map ..\scripts\dzVents\scripts.
Domoticz is running in Docker on a Synolygy DS718+ with DSM 7.1

Image

I found an exemple of a path in this thread from Waaren: https://www.domoticz.com/forum/viewtopic.php?t=30993

He wrote for a Raspberry:

Code: Select all

local csvFile = '/home/pi/Desktop/GPV_data/Humidity' .. dz.time.rawDate .. '.csv' -- location/name of your csv text file
But that seems to be an absolute path..

Does somebody has a suggestion? Thnx in advance.
Synology with Domoticz build (V2024.7) in Docker
janpep
Posts: 212
Joined: Thursday 14 March 2024 10:11
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Script for Airplanes.live api

Post by janpep »

Use the full path in your synology.
Something like /volume1/docker/domoticz/scripts/yourfile.csv
Domoticz in Ubuntu virtual machine on Synology DS718+ behind FRITZ!Box.
Using: EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
PieterS
Posts: 195
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: NL
Contact:

Re: Script for Airplanes.live api

Post by PieterS »

Use the full path in your synology.
Something like /volume1/docker/domoticz/scripts/yourfile.csv
Thnx Jan! Waiting for the next plane..
Synology with Domoticz build (V2024.7) in Docker
PieterS
Posts: 195
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: NL
Contact:

Re: Script for Airplanes.live api

Post by PieterS »

A plane passed by. So I searched with *.csv in the Windows Explorer. But no success.
In the log of Domoticz is an error:

Code: Select all

 2024-06-27 16:21:15.835 Status: EventSystem: Script event triggered: /opt/domoticz/dzVents/runtime/dzVents.lua
2024-06-27 16:21:15.835 Error: dzVents: Error: (3.1.8) Airplanes-: An error occurred when calling event handler airplanes
2024-06-27 16:21:15.835 Error: dzVents: Error: (3.1.8) Airplanes-: ...erdata/scripts/dzVents/generated_scripts/global_data.lua:59: attempt to index a nil value (local 'file') 
I did a reboot of the container after saving the new settings.

Code: Select all

2024-06-27 15:54:14.314 Status: Domoticz V2024.4 (build 16089) (c)2012-2024 GizMoCuz
2024-06-27 15:54:14.314 Status: Build Hash: 7ee2474fb, Date: 2024-06-20 07:16:22
2024-06-27 15:54:14.314 Status: Startup Path: /opt/domoticz/ 
No idea what to do about it..
Synology with Domoticz build (V2024.7) in Docker
janpep
Posts: 212
Joined: Thursday 14 March 2024 10:11
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Script for Airplanes.live api

Post by janpep »

Can you show line 59 from global_data?
And the current definition of 'ap_csvFile'?
Domoticz in Ubuntu virtual machine on Synology DS718+ behind FRITZ!Box.
Using: EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
User avatar
RonkA
Posts: 95
Joined: Tuesday 14 June 2022 12:57
Target OS: NAS (Synology & others)
Domoticz version: 2023.2
Location: Harlingen
Contact:

Re: Script for Airplanes.live api

Post by RonkA »

The error occurs when your filepath is not correct.
I have struggled with this also, and succeded in the end 8-)
I wanted to make a textfile named 'net_verbruik.txt' using some values in a script and store this on the nas. For me this did the trick:
I have a map on my nas: \\NAS-1\docker\domoticz\Made, this map is writable from Domoticz running within Docker by using this path:

Code: Select all

local file_path = '/opt/domoticz/userdata/Made/net_verbruik.txt'
This works for my own script, not for this script..

So you have to figure out the correct part of the path on your nas to use in the airplanes script..
Last edited by RonkA on Thursday 27 June 2024 18:52, edited 3 times in total.
SolarEdge ModbusTCP - Open Weather Map - Kaku - Synology NAS - Watermeter - ESPEasy - DS18b20
Work in progress = Life in general..
janpep
Posts: 212
Joined: Thursday 14 March 2024 10:11
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Script for Airplanes.live api

Post by janpep »

No need to create a directory. He can just point to an existing directory that can be accessed localy on the nas. Using the right full path to it. (Not the share you showed from explorer.)
Domoticz in Ubuntu virtual machine on Synology DS718+ behind FRITZ!Box.
Using: EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
janpep
Posts: 212
Joined: Thursday 14 March 2024 10:11
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Script for Airplanes.live api

Post by janpep »

I an not very familiar with docker. Maybe it sees '/domoticz' as the root?
Domoticz in Ubuntu virtual machine on Synology DS718+ behind FRITZ!Box.
Using: EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
PieterS
Posts: 195
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: NL
Contact:

Re: Script for Airplanes.live api

Post by PieterS »

Thnx gentlemen for all input.
This is the config of the container:

Image

So userdata is the root of that virtual machine.

@janpep: Yes, I had the idea to fill that csv-file which is created by dzVents in the root. But what is than the correct path to fill in the application?

I should think: /SavedAirplanes.csv

But reading in the forum the post of Waaren, he mentioned the fulll path from the root of the OS. local csvFile = '/home/pi/Desktop/GPV_data/Humidity' (My Source: https://www.domoticz.com/forum/viewtopic.php?t=30993 )

But to make it more complicated: there is no file airplanes.lua in generated_scripts... :roll: Only the global_data.lua...
I saved airplanes.lua in the path domoticz\scripts\dzVents\scripts

I entered the virtual machine to the console with Portainer and discoverd that the OS has a map userdata to store its data. The root is domoticz..

Image

So I will figure out with trial and error what will be the right path.. :?
Synology with Domoticz build (V2024.7) in Docker
PieterS
Posts: 195
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: NL
Contact:

Re: Script for Airplanes.live api

Post by PieterS »

YESSS! There is a csv-file in the root!

And this seems the right syntax for my case:

Code: Select all

local ap_csvFile = '/volume1/docker/domoticz/SavedAirplanes.csv'

Code: Select all

"ap_time	ap_hex	ap_flight	ap_r	ap_t	ap_desc	ap_gs	ap_track	ap_direction	ap_lat	ap_long	ap_distance	ap_geom_rateString	ap_altitude"
"19:44:15	4d2271	RYR88UD 	9H-QEC	B738	BOEING 737-800	489	92.39	O	51.370488	5.460434	2.2	 Stijgt 829 m/min.	2438"
"19:52:01	4d2348	RYR5UK  	9H-VUI	B38M	BOEING 737 MAX 8	540	121.67	OZO	51.362527	5.472565	1.6	 Stijgt 858 m/min.	2172"
"20:27:45	4d2460	WZZ4H   	9H-WBV	A320	AIRBUS A-320	508	80.78	O	51.366484	5.456314	1.8	 Stijgt 849 m/min.	2294"
Thnx a lot gentlemen! 8-)

@janpep: Maybe a suggestion to build in a dellimiter to filter the records? ;)
Synology with Domoticz build (V2024.7) in Docker
janpep
Posts: 212
Joined: Thursday 14 March 2024 10:11
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Script for Airplanes.live api

Post by janpep »

PieterS wrote: Thursday 27 June 2024 21:01 YESSS! There is a csv-file in the root!
Great. You should now also be able to address the subdirectories under it when you prefer.
@janpep: Maybe a suggestion to build in a dellimiter to filter the records? ;)
There is a delimiter!
It is the TAB. They call it a TAB delimited CSV file. Easy when you want to paste it in Excel.
Someone might like a comma and another prefers semicolon to separate the fields. Someone else like to have double quotes around the fields. You can adjust the code as you like. I stay with just the TAB.
Domoticz in Ubuntu virtual machine on Synology DS718+ behind FRITZ!Box.
Using: EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
PieterS
Posts: 195
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: NL
Contact:

Re: Script for Airplanes.live api

Post by PieterS »

I was too early. :twisted:
the file was made with other syntax. I missed the file in the list when checking.. (without refresh screen I guess) After that creation I changed the path and since that time there are no updates.

I have to figure out again. But that is for tonight. I let you know the correct syntax.
Synology with Domoticz build (V2024.7) in Docker
PieterS
Posts: 195
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: NL
Contact:

Re: Script for Airplanes.live api

Post by PieterS »

Found the right path again, so problem solved. :D

Code: Select all

local ap_csvFile = '/opt/domoticz/userdata/SavedAirplanes.csv'
Thanks @RonkA for your hint.

Import through tab Gegevens of a textfile is a long time ago. MS changed that..:ugeek: But good to see a nice layout now. Only data that is missing in my opinion is the date. Will add that to make selections.

Image

Thanks for support!
Synology with Domoticz build (V2024.7) in Docker
janpep
Posts: 212
Joined: Thursday 14 March 2024 10:11
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Script for Airplanes.live api

Post by janpep »

I shall add the date in update.
Domoticz in Ubuntu virtual machine on Synology DS718+ behind FRITZ!Box.
Using: EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
DiaDomo
Posts: 37
Joined: Saturday 28 March 2020 13:55
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Script for Airplanes.live api

Post by DiaDomo »

Hi, nice script!
I'm trying to run it, but no airplanes are logged.
I changed the settings to:

Code: Select all

local ap_maxRadiusKm = 50    -- Query max radius in KM around your coordinates.
local ap_maxAltitudeM = 6500    --  was 2500 save only < max ap_maxAltitude in Meters.
Still no airplanes,but flightradar24 is showing airplanes.
This is part of the domoticz log (no errors):

Code: Select all

2024-06-28 19:45:00.385 Status: dzVents: Debug: Airplanes: OpenURL: method = GET
2024-06-28 19:45:00.385 Status: dzVents: Debug: Airplanes: OpenURL: post data = nil
2024-06-28 19:45:00.385 Status: dzVents: Debug: Airplanes: OpenURL: headers = nil
2024-06-28 19:45:00.385 Status: dzVents: Debug: Airplanes: OpenURL: callback = airplanes
2024-06-28 19:45:00.385 Status: dzVents: Debug: Airplanes: OpenURL: url = https://api.airplanes.live/v2/point/0/0/31.0685595
2024-06-28 19:45:00.385 Status: dzVents: Debug: Airplanes: OpenURL: method = GET
2024-06-28 19:45:00.385 Status: dzVents: Debug: Airplanes: OpenURL: post data = nil
2024-06-28 19:45:00.385 Status: dzVents: Debug: Airplanes: OpenURL: headers = nil
2024-06-28 19:45:00.385 Status: dzVents: Debug: Airplanes: OpenURL: callback = airplanes
2024-06-28 19:45:00.386 Status: dzVents: Debug: Airplanes: OpenURL: url = https://api.airplanes.live/v2/point/0/0/31.0685595
2024-06-28 19:45:00.386 Status: dzVents: Debug: Airplanes: OpenURL: method = GET
2024-06-28 19:45:00.386 Status: dzVents: Debug: Airplanes: OpenURL: post data = nil
2024-06-28 19:45:00.386 Status: dzVents: Debug: Airplanes: OpenURL: headers = nil
2024-06-28 19:45:00.386 Status: dzVents: Debug: Airplanes: OpenURL: callback = airplanes
2024-06-28 19:45:00.386 Status: dzVents: Debug: Airplanes: OpenURL: url = https://api.airplanes.live/v2/point/0/0/31.0685595
2024-06-28 19:45:00.386 Status: dzVents: Debug: Airplanes: OpenURL: method = GET
2024-06-28 19:45:00.386 Status: dzVents: Debug: Airplanes: OpenURL: post data = nil
2024-06-28 19:45:00.386 Status: dzVents: Debug: Airplanes: OpenURL: headers = nil
2024-06-28 19:45:00.387 Status: dzVents: Debug: Airplanes: OpenURL: callback = airplanes
2024-06-28 19:45:00.387 Status: dzVents: Debug: Airplanes: OpenURL: url = https://api.airplanes.live/v2/point/0/0/31.0685595
2024-06-28 19:45:00.387 Status: dzVents: Debug: Airplanes: OpenURL: method = GET
2024-06-28 19:45:00.387 Status: dzVents: Debug: Airplanes: OpenURL: post data = nil
2024-06-28 19:45:00.387 Status: dzVents: Debug: Airplanes: OpenURL: headers = nil
2024-06-28 19:45:00.387 Status: dzVents: Debug: Airplanes: OpenURL: callback = airplanes
2024-06-28 19:45:00.387 Status: dzVents: Debug: Airplanes: OpenURL: url = https://api.airplanes.live/v2/point/0/0/31.0685595
2024-06-28 19:45:00.387 Status: dzVents: Debug: Airplanes: OpenURL: method = GET
2024-06-28 19:45:00.388 Status: dzVents: Debug: Airplanes: OpenURL: post data = nil
2024-06-28 19:45:00.388 Status: dzVents: Debug: Airplanes: OpenURL: headers = nil
2024-06-28 19:45:00.388 Status: dzVents: Debug: Airplanes: OpenURL: callback = airplanes
2024-06-28 19:45:00.388 Status: dzVents: Debug: Airplanes: OpenURL: url = https://api.airplanes.live/v2/point/0/0/31.0685595
2024-06-28 19:45:00.388 Status: dzVents: Debug: Airplanes: OpenURL: method = GET
2024-06-28 19:45:00.388 Status: dzVents: Debug: Airplanes: OpenURL: post data = nil
2024-06-28 19:45:00.388 Status: dzVents: Debug: Airplanes: OpenURL: headers = nil
2024-06-28 19:45:00.388 Status: dzVents: Debug: Airplanes: OpenURL: callback = airplanes
2024-06-28 19:45:00.389 Status: dzVents: Info: Airplanes: ------ Finished airplanes.lua
2024-06-28 19:45:00.832 Status: dzVents: Info: Handling httpResponse-events for: "airplanes"
2024-06-28 19:45:00.833 Status: dzVents: Info: Airplanes: ------ Start external script: airplanes.lua: HTTPResponse: "airplanes"
and this part:

Code: Select all

2024-06-28 19:50:45.885 Status: dzVents: Debug: Airplanes: Item and JSON - OK
2024-06-28 19:50:45.885 Status: dzVents: Debug: Airplanes: result_table: type = table
2024-06-28 19:50:45.885 Status: dzVents: Debug: Airplanes: Total flights found in response = 0.
2024-06-28 19:50:45.885 Status: dzVents: Debug: Airplanes: Nothing left in global _d.ap_table to write to device.
2024-06-28 19:50:45.886 Status: dzVents: Info: Airplanes: ------ Finished airplanes.lua
2024-06-28 19:51:01.163 Status: dzVents: Info: Handling httpResponse-events for: "airplanes"
2024-06-28 19:51:01.163 Status: dzVents: Info: Airplanes: ------ Start external script: airplanes.lua: HTTPResponse: "airplanes"
2024-06-28 19:51:01.164 Status: dzVents: Debug: Airplanes: Item and JSON - OK
2024-06-28 19:51:01.164 Status: dzVents: Debug: Airplanes: result_table: type = table
2024-06-28 19:51:01.164 Status: dzVents: Debug: Airplanes: Total flights found in response = 0.
2024-06-28 19:51:01.164 Status: dzVents: Debug: Airplanes: Nothing left in global _d.ap_table to write to device.
2024-06-28 19:51:01.171 Status: dzVents: Info: Airplanes: ------ Finished airplanes.lua
2024-06-28 19:51:15.927 Status: dzVents: Info: Handling httpResponse-events for: "airplanes"
2024-06-28 19:51:15.928 Status: dzVents: Info: Airplanes: ------ Start external script: airplanes.lua: HTTPResponse: "airplanes"
2024-06-28 19:51:15.929 Status: dzVents: Debug: Airplanes: Item and JSON - OK
2024-06-28 19:51:15.929 Status: dzVents: Debug: Airplanes: result_table: type = table
2024-06-28 19:51:15.929 Status: dzVents: Debug: Airplanes: Total flights found in response = 0.
2024-06-28 19:51:15.929 Status: dzVents: Debug: Airplanes: Nothing left in global _d.ap_table to write to device.
2024-06-28 19:51:15.930 Status: dzVents: Info: Airplanes: ------ Finished airplanes.lua
Is the URL correct?
Raspberry PI 2 & 3 & 4 | RFlink | MySensors | ESP32 | Homebridge | Tasmota Sonoff | Zigbee2Mqtt | ADS-B
janpep
Posts: 212
Joined: Thursday 14 March 2024 10:11
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Script for Airplanes.live api

Post by janpep »

DiaDomo wrote: Friday 28 June 2024 19:50 Is the URL correct?
In the url the coordinates seem to be missing.
It is taken from the Domoticz settings. Check if it is filled in there.
Domoticz in Ubuntu virtual machine on Synology DS718+ behind FRITZ!Box.
Using: EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
DiaDomo
Posts: 37
Joined: Saturday 28 March 2020 13:55
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Script for Airplanes.live api

Post by DiaDomo »

Yes, coordinates are filled in
Last edited by DiaDomo on Friday 28 June 2024 21:47, edited 1 time in total.
Raspberry PI 2 & 3 & 4 | RFlink | MySensors | ESP32 | Homebridge | Tasmota Sonoff | Zigbee2Mqtt | ADS-B
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest