RE: Weather service not working anymore? - admin - 02.05.2019
See this post: https://forum.logicmachine.net/showthread.php?tid=2044&pid=12735#pid12735
RE: Weather service not working anymore? - MichelDeLigne - 02.05.2019
(02.05.2019, 12:51)jetsetter Wrote: Hi to all,
I tried Michell's code (with either his or my city code) and I am always getting an alert:
Fetch failed: error:1409442E:lib(20):func(148):reason(1070)
and the script stops. I tried to find any error description in yr.no but no luck.
Any ideas?
Thank you in advance.
Did you put https in the url?
The script works only with http.
Regards.
Michel.
RE: Weather service not working anymore? - Keitz - 28.08.2019
(18.01.2019, 07:50)admin Wrote: Since there's no response from Yahoo we suggest using https://apixu.com instead. You will have to create a free account and make sure that your script does not fetch data too quickly (not less than once in 5 minutes).
Here's a short example, change key variable to your API key, location variable to required location in textual form. This example fetches current weather condition and forecast for today and tomorrow. Fields can be found in apixu documentation: https://www.apixu.com/doc/forecast.aspx (day Element).
Code: require('json')
https = require('ssl.https')
escape = require('socket.url').escape
key = 'my_api_key'
location = 'my location name'
url = 'https://api.apixu.com/v1/forecast.json?key=%s&q=%s&days=2'
url = string.format(url, key, escape(location))
res = https.request(url)
data = json.pdecode(res)
if type(data) ~= 'table' then
alert('failed to load weather data')
return
end
if data.error then
log('error', data.error)
return
end
current = data.current
today = data.forecast.forecastday[ 1 ].day
tomorrow = data.forecast.forecastday[ 2 ].day
-- log(current, today, tomorrow)
-- temperature in C
grp.write('32/1/1', current.temp_c)
-- "feels like" temperature in C
grp.write('32/1/2', current.feelslike_c)
-- humidity as percentage
grp.write('32/1/3', current.humidity)
-- wind speed in kilometers per hour
grp.write('32/1/4', current.wind_kph)
-- uv index
grp.write('32/1/5', current.uv)
-- weather condition text
grp.write('32/1/6', current.condition.text)
-- pressure in millibars
grp.write('32/1/7', current.pressure_mb)
-- precipitation amount in millimeters
grp.write('32/1/8', current.precip_mm)
-- minimum temperature in celsius for the day
grp.write('32/2/1', today.mintemp_c)
-- maximum temperature in celsius for the day
grp.write('32/2/2', today.maxtemp_c)
-- average temperature in celsius for the day
grp.write('32/2/3', today.avgtemp_c)
-- average humidity as percentage
grp.write('32/2/4', today.avghumidity)
-- maximum wind speed in kilometers per hour
grp.write('32/2/5', today.maxwind_kph)
-- uv index
grp.write('32/2/6', today.uv)
-- weather condition text
grp.write('32/2/7', today.condition.text)
-- total precipitation in millimeters
grp.write('32/2/8', today.totalprecip_mm)
-- minimum temperature in celsius for the day
grp.write('32/3/1', tomorrow.mintemp_c)
-- maximum temperature in celsius for the day
grp.write('32/3/2', tomorrow.maxtemp_c)
-- average temperature in celsius for the day
grp.write('32/3/3', tomorrow.avgtemp_c)
-- average humidity as percentage
grp.write('32/3/4', tomorrow.avghumidity)
-- maximum wind speed in kilometers per hour
grp.write('32/3/5', tomorrow.maxwind_kph)
-- uv index
grp.write('32/3/6', tomorrow.uv)
-- weather condition text
grp.write('32/3/7', tomorrow.condition.text)
-- total precipitation in millimeters
grp.write('32/3/8', tomorrow.totalprecip_mm)
Now i get always the alert failed to load weather data.
What im doing wrong ?
The same script has worked before.
Is there something changed in the apixu ?
RE: Weather service not working anymore? - admin - 29.08.2019
Works for me, try logging server response.
Replace:
Code: res = https.request(url)
With:
Code: res, code, hdrs, stat = https.request(url)
log(res, code, hdrs, stat)
And post what you get in Logs tab.
RE: Weather service not working anymore? - Keitz - 29.08.2019
(29.08.2019, 06:43)admin Wrote: Works for me, try logging server response.
Replace:
Code: res = https.request(url)
With:
Code: res, code, hdrs, stat = https.request(url)
log(res, code, hdrs, stat)
And post what you get in Logs tab. Thanks
This is what i get :
weater_data_apixu 29.08.2019 20:49:37
* arg: 1
* nil
* arg: 2
* nil
* arg: 3
* nil
* arg: 4
* nil
RE: Weather service not working anymore? - admin - 29.08.2019
Which firmware version are you running? Can you send your Apixu key via PM?
RE: Weather service not working anymore? - Keitz - 29.08.2019
(29.08.2019, 19:24)admin Wrote: Which firmware version are you running? Can you send your Apixu key via PM? Version: 20170620
RE: Weather service not working anymore? - admin - 30.08.2019
This is probably due to older FW, as a work-around you can use HTTP request instead:
Code: require('json')
http = require('socket.http')
escape = require('socket.url').escape
key = 'my_api_key'
location = 'my location name'
url = 'http://api.apixu.com/v1/forecast.json?key=%s&q=%s&days=2'
url = string.format(url, key, escape(location))
res = http.request(url)
data = json.pdecode(res)
...
RE: Weather service not working anymore? - dreamcatcher - 06.12.2019
I am all new to the LM and are on a steep learning path. I've been struggling to get the yr.no xml API script to work for my Yr location. However, after further inspections and testing I found out that the xml from norwegian locations have a subtle difference compared to other location. I could get all others to work, but not for any norwegian places.
For norwegian places you get an additional text section as below:
<forecast>
<text>
<location name="Oslo">
<time from="2019-12-06" to="2019-12-06">
<title>Obs! Note!</title>
<body>Tekstvarsel-tjenesten er nedlagt. The text forecast service is suspended</body>
</time>
</location>
</text>
Because of this the first index to values must be 2 instead of 1. That eventually made things work for me. I don't know why nobody has mentioned this before. Maybe this is a recent change? Or is it me missing something here...?
RE: Weather service not working anymore? - AlexLV - 05.04.2020
Hi,
how correctly attach weather icons to visualization?
As example I have group with icon number or name - 250 byte string - 03n, and I have icon 03n.png. How better show it at visualization?
Thank you in advance,
Alex
RE: Weather service not working anymore? - admin - 06.04.2020
See this example: https://forum.logicmachine.net/showthread.php?tid=2253
RE: Weather service not working anymore? - AlexLV - 06.04.2020
admin,
thank you, now will check and add to my icon's control
RE: Weather service not working anymore? - alexgleyzer - 08.05.2020
(30.08.2019, 06:16)admin Wrote: This is probably due to older FW, as a work-around you can use HTTP request instead:
Code: require('json')
http = require('socket.http')
escape = require('socket.url').escape
key = 'my_api_key'
location = 'my location name'
url = 'http://api.apixu.com/v1/forecast.json?key=%s&q=%s&days=2'
url = string.format(url, key, escape(location))
res = http.request(url)
data = json.pdecode(res)
...
Weather service is working, but from different url
url = 'http://api.weatherstack.com/current?access_key=%s&query=%s'
will return table data.current like this
* table:
["cloudcover"]
* number: 59
["visibility"]
* number: 10
["observation_time"]
* string: 12:24 PM
["uv_index"]
* number: 5
["wind_dir"]
* string: NNW
["humidity"]
* number: 60
["weather_descriptions"]
* table:
[1]
* string: Cloudy
["wind_speed"]
* number: 21
["weather_code"]
* number: 119
["is_day"]
* string: yes
["pressure"]
* number: 1017
["precip"]
* number: 0.1
["weather_icons"]
* table:
[1]
* string: https://assets.weatherstack.com/images/wsymbols01_png_64/wsymbol_0003_white_cloud.png
["feelslike"]
* number: 10
["temperature"]
* number: 12
["wind_degree"]
* number: 327
Best regards
Alex
RE: Weather service not working anymore? - davidchispas - 30.07.2020
Is there any kind of change in the weather script?
I see that the application loads it well without errors and even updates the data ... but it does not send the correct values for the season of the year in which we are ...
RE: Weather service not working anymore? - admin - 30.07.2020
Which one are you using?
RE: Weather service not working anymore? - davidchispas - 30.07.2020
(30.07.2020, 15:03)admin Wrote: Which one are you using? Hello admin, this is my script.
Code: require('json')
http = require('socket.http')
escape = require('socket.url').escape
key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
location = 'xxxx'
url = 'http://api.weatherstack.com/current?access_key=%s&query=%s'
url = string.format(url, key, escape(location))
res = http.request(url)
data = json.pdecode(res)
if type(data) ~= 'table' then
alert('no se pudieron cargar los datos del clima')
return
end
if data.error then
log('error', data.error)
return
end
current = data.current
-- temperature
grp.write('32/1/1', current.temperature)
-- "feels like" temperature
grp.write('32/1/2', current.feelslike)
-- humidity as percentage
grp.write('32/1/3', current.humidity)
-- wind speed in kilometers per hour
grp.write('32/1/4', current.wind_speed)
-- uv index
grp.write('32/1/5', current.uv_index)
-- weather condition text
grp.write('32/1/6', current.weather_descriptions[1])
-- pressure
grp.write('32/1/7', current.pressure)
-- precipitation amount
grp.write('32/1/8', current.precip)
RE: Weather service not working anymore? - admin - 30.07.2020
Maybe the location is incorrect? You can use latitude, longitude format to get a more precise results. Try logging JSON data, maybe it will provide some useful information.
RE: Weather service not working anymore? - mkaymak - 23.03.2022
Hi Admin , Didn't understand how to use your script ? Could you please give me some instructions about it .
RE: Weather service not working anymore? - admin - 23.03.2022
Which script exactly? There are many examples that use data from different services.
RE: Weather service not working anymore? - mkaymak - 23.03.2022
Code: require('json')
https = require('ssl.https')
escape = require('socket.url').escape
key = 'my_api_key'
location = 'my location name'
url = 'https://api.apixu.com/v1/forecast.json?key=%s&q=%s&days=2'
url = string.format(url, key, escape(location))
res = https.request(url)
data = json.pdecode(res)
if type(data) ~= 'table' then
alert('failed to load weather data')
return
end
if data.error then
log('error', data.error)
return
end
current = data.current
today = data.forecast.forecastday[ 1 ].day
tomorrow = data.forecast.forecastday[ 2 ].day
-- log(current, today, tomorrow)
-- temperature in C
grp.write('32/1/1', current.temp_c)
-- "feels like" temperature in C
grp.write('32/1/2', current.feelslike_c)
-- humidity as percentage
grp.write('32/1/3', current.humidity)
-- wind speed in kilometers per hour
grp.write('32/1/4', current.wind_kph)
-- uv index
grp.write('32/1/5', current.uv)
-- weather condition text
grp.write('32/1/6', current.condition.text)
-- pressure in millibars
grp.write('32/1/7', current.pressure_mb)
-- precipitation amount in millimeters
grp.write('32/1/8', current.precip_mm)
-- minimum temperature in celsius for the day
grp.write('32/2/1', today.mintemp_c)
-- maximum temperature in celsius for the day
grp.write('32/2/2', today.maxtemp_c)
-- average temperature in celsius for the day
grp.write('32/2/3', today.avgtemp_c)
-- average humidity as percentage
grp.write('32/2/4', today.avghumidity)
-- maximum wind speed in kilometers per hour
grp.write('32/2/5', today.maxwind_kph)
-- uv index
grp.write('32/2/6', today.uv)
-- weather condition text
grp.write('32/2/7', today.condition.text)
-- total precipitation in millimeters
grp.write('32/2/8', today.totalprecip_mm)
-- minimum temperature in celsius for the day
grp.write('32/3/1', tomorrow.mintemp_c)
-- maximum temperature in celsius for the day
grp.write('32/3/2', tomorrow.maxtemp_c)
-- average temperature in celsius for the day
grp.write('32/3/3', tomorrow.avgtemp_c)
-- average humidity as percentage
grp.write('32/3/4', tomorrow.avghumidity)
-- maximum wind speed in kilometers per hour
grp.write('32/3/5', tomorrow.maxwind_kph)
-- uv index
grp.write('32/3/6', tomorrow.uv)
-- weather condition text
grp.write('32/3/7', tomorrow.condition.text)
-- total precipitation in millimeters
grp.write('32/3/8', tomorrow.totalprecip_mm)
This one
|