Page 1 of 1

Cannot get all buienradar data from json call

Posted: Sunday 17 December 2023 23:54
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')
)

Re: Cannot get all buienradar data from json call

Posted: Monday 18 December 2023 7:36
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 ...

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

Posted: Monday 18 December 2023 8:11
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

Re: Cannot get all buienradar data from json call

Posted: Monday 18 December 2023 10:14
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.

Re: Cannot get all buienradar data from json call

Posted: Monday 18 December 2023 10:38
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?

Re: Cannot get all buienradar data from json call

Posted: Monday 18 December 2023 10:45
by habahabahaba
May be this can help you?

Re: Cannot get all buienradar data from json call

Posted: Monday 18 December 2023 11:04
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

Re: Cannot get all buienradar data from json call

Posted: Monday 18 December 2023 11:41
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.

Re: Cannot get all buienradar data from json call

Posted: Monday 18 December 2023 12:15
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

Re: Cannot get all buienradar data from json call

Posted: Monday 18 December 2023 12:23
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.

Re: Cannot get all buienradar data from json call

Posted: Monday 18 December 2023 12:26
by habahabahaba
Yes, sorry.
Im from the phone and little tired