Cannot get all buienradar data from json call  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
Tukker
Posts: 673
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Cannot get all buienradar data from json call

Post by Tukker »

My home is inbetween Groenlo and Twente.
To get a more or less accurate local temperature I'm polling buienradar.
Stations with a number 29 or less can get retrieved with a json call.
Twente however is numer 30 and buienradar refuses to send data ( the json call is not successfull)
Here is my script.

Code: Select all

-- Buienradar gegevens
-- Buienradar json: https://data.buienradar.nl/2.0/feed/json
-- Groenlo-Hupsel = item.json.actual.stationmeasurements[9]
-- Groningen = item.json.actual.stationmeasurements[10]
-- Twente = item.json.actual.stationmeasurements[30]

return {
	active = true,
	on = {
		timer = { 'every minute' },           -- every minute for testing, 10 minutes when active
		httpResponses = { 'BuienradarRetrieved' }     -- matches callback string below
	},
		logging = {level = domoticz.LOG_INFO, 
	           marker = 'Buienradar meetstations'
	},
	
	execute = function(domoticz, item)
		if (item.isTimer) then
			domoticz.openURL({
				url = 'https://data.buienradar.nl/2.0/feed/json',
				--method = 'GET',
				callback = 'BuienradarRetrieved'
			})
        end
		if (item.isHTTPResponse) then
			if (item.ok and item.isJSON) then 
				-- domoticz.utils.dumpTable(item.json) 
				-- domoticz.log(item.json.actual.stationmeasurements[9].temperature,domoticz.LOG_INFO)
				local Groenlo_temp = item.json.actual.stationmeasurements[9].temperature
				local Groningen_temp = item.json.actual.stationmeasurements[10].temperature
				local Home_temp = (Groenlo_temp + Groningen_temp)/2
			    domoticz.devices('Temp_Home').updateTemperature(Home_temp)
			    domoticz.log('Groenlo temperature = ' .. Groenlo_temp, domoticz.LOG_INFO)
				domoticz.log('Groningen temperature = ' .. Groningen_temp, domoticz.LOG_INFO)
			else
				-- oops
				domoticz.log('Error fetching Buienradar data', domoticz.LOG_ERROR)
			end
		end
	end
}
At station 30 the log reports:

Code: Select all

2023-12-18 00:24:00.557 Error: dzVents: Error: (3.1.8) Buienradar meetstations: An error occurred when calling event handler Buienradar
2023-12-18 00:24:00.557 Error: dzVents: Error: (3.1.8) Buienradar meetstations: ...omoticz/scripts/dzVents/generated_scripts/Buienradar.lua:37: attempt to concatenate a nil value (local 'Twente_temp')
)
Bugs bug me.
roblom
Posts: 408
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

Re: Cannot get all buienradar data from json call

Post by roblom »

Are you sure the error is coming from this script? The value of Twente_temp is empty but as far as I can see there is no Twente_temp in the whole script, so it's impossible it's giving this error.
There is Groningen_temp ...
User avatar
waltervl
Posts: 7005
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: Cannot get all buienradar data from json call  [Solved]

Post by waltervl »

There is a built in buienradar integration that connects to the closest weather station, based on your location you have filled in in menu Setup settings. You can also override to a specific station. https://www.domoticz.com/wiki/Buienradar
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Tukker
Posts: 673
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Cannot get all buienradar data from json call

Post by Tukker »

@roblom
You're right and you're wrong.
When you try the script and fill in the value of 30 despite the names Groenlo of Groningen you'll see the error appearing in the log.

@waltervl
By mentioning the buienradar plugin and making the question as being solved you go a little bit too short through the corner.
I have buienradar installed and I am asking for help in a dzvents or a json problem in a domoticz script.
The question about how to overcome the error has not been resolved yet.

Help is appreciated.
Bugs bug me.
User avatar
habahabahaba
Posts: 283
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: Cannot get all buienradar data from json call

Post by habahabahaba »

So... May be im not understanding you...
If i use https://jsonparser.org/ and fill in with your link i can see different station data, including number 30 - regio: Twente and other weather conditions.

So, what is the problem to make dzvents script and get those data?
User avatar
habahabahaba
Posts: 283
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: Cannot get all buienradar data from json call

Post by habahabahaba »

May be this can help you?
User avatar
jvdz
Posts: 2476
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Cannot get all buienradar data from json call

Post by jvdz »

It really seems to be a variable Twente_temp in the file: domoticz/scripts/dzVents/generated_scripts/Buienradar.lua that is nill!
Guess you are using the WebEditor, but could you doublecheck the actual file for that variable?

EDIT: Tested you actual posted code in a test environment and got this: (Only commented the TEMP device update line)

Code: Select all

2023-12-18 11:10:00.124 Status: dzVents: Info: Buienradar meetstations: ------ Start internal script: testbuienradar:, trigger: "every minute"
2023-12-18 11:10:00.124 Status: dzVents: Info: Buienradar meetstations: ------ Finished testbuienradar
2023-12-18 11:10:00.272 Status: dzVents: Info: Buienradar meetstations: ------ Start internal script: testbuienradar: HTTPResponse: "BuienradarRetrieved"
2023-12-18 11:10:00.280 Status: dzVents: Info: Buienradar meetstations: Groenlo temperature = 6.9
2023-12-18 11:10:00.280 Status: dzVents: Info: Buienradar meetstations: Groningen temperature = 6.1
2023-12-18 11:10:00.280 Status: dzVents: Info: Buienradar meetstations: ------ Finished testbuienradar
User avatar
waltervl
Posts: 7005
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: Cannot get all buienradar data from json call

Post by waltervl »

HvdW wrote: Monday 18 December 2023 10:14 @waltervl
By mentioning the buienradar plugin and making the question as being solved you go a little bit too short through the corner.
I have buienradar installed and I am asking for help in a dzvents or a json problem in a domoticz script.
The question about how to overcome the error has not been resolved yet.

Help is appreciated.
I did nothing to put it on solved, I cannot do that, you did that yourself.
I tried to help your issue by advising you not using dzvents but use the existing buienradar integration. Sometimes the solution to a problem can be somewhere else. Perhaps you were not aware there was a Buienradar integration.
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
habahabahaba
Posts: 283
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: Cannot get all buienradar data from json call

Post by habahabahaba »

jvdz wrote: Monday 18 December 2023 11:04but could you doublecheck the actual file for that variable?
I dont have such script im my Dz
User avatar
jvdz
Posts: 2476
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Cannot get all buienradar data from json call

Post by jvdz »

Not sure why you are responding to my comments to @HvdW, but the Web interface does generate an actual file in the indicated directory when you hit save, as you should also see in the Domoticz log at save time.
User avatar
habahabahaba
Posts: 283
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: Cannot get all buienradar data from json call

Post by habahabahaba »

Yes, sorry.
Im from the phone and little tired
Post Reply