Yes you could do it but this option is depending on your received dataset, i checked yours but in this dataset you got back it's givving you timeframes of 6 hours, so you cant use that, i would search for a more detailed weather API ..
BR,
Erwin
OK, any idea of where I can get it?
Also, so I learn a little more, how do you see that it is a dataset for 6 hours? I just used the one posted earlier in this thread, so I am not really sure how it works.
Trond
There are 10 kinds of people in the world; those who can read binary and those who don't
01.10.2017, 17:11 (This post was last modified: 02.10.2017, 07:08 by Erwin van der Zwart.)
Hi,
Just paste the url from the request in your browser, there you see the original XML structure.
For better API you could try something like this as it has real time forecast and hourly data http://www.apixu.com (or any other of the 1000 available), another plus is that it also has JSON data so you don't need the XML parser to get a LUA table. You can use this free if you don’t need interval faster then 10 minutes (= max 5000 calls a month)
Here is a sample to get data from the apixu api:
Code:
12345678910111213141516171819202122232425
require'ssl.https'require'json'-- Set your API key hereapi_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'-- Set here your locationlocation = 'Amsterdam'-- Request data from APIr,c,h,s = ssl.https.request('https://api.apixu.com/v1/forecast.json?key=' .. api_key .. '=' .. location)
-- Decode JSON data to LUA tableifrthenresult = json.pdecode(r)
elsealert('Could not fetch data')
returnend-- Get next hour temperaturetemperature_in_one_hour = result['forecast']['forecastday'][1]['hour'][1]['temp_c']
-- Do something with the received temperaturelog(temperature_in_one_hour)
I'm not sure hour 1 is next hour or 1:00 so maybe you need to add small algorithm to compare with 'now' and selected day / hour from the table
Thank you Admin
If someone is interested in then there's yrno script below (warning: uses obsolete API)
Function minmax_temp_tomorrow returns lowest and highest temperature for tomorrow. The script is simple and ignores time shift.
(08.01.2019, 16:21)Thomas Wrote: Thank you Admin
If someone is interested in then there's yrno script below (warning: uses obsolete API)
Function minmax_temp_tomorrow returns lowest and highest temperature for tomorrow. The script is simple and ignores time shift.
Hi
1. I stored the script above in library ecl_yrno (don't forget to change URL according to your location)
2. I added script below into my scheduler. You have to change GAs to addresses you use in your project.
7/2/30 and 7/2/31 are 9.001 (temperature, float)
7/2/32 is 11.3 (date)
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).
require('json')
https = require('ssl.https')
escape = require('socket.url').escapekey = '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)
iftype(data) ~= 'table'thenalert('failed to load weather data')
returnendifdata.errorthenlog('error', data.error)
returnendcurrent = data.currenttoday = data.forecast.forecastday[ 1 ].daytomorrow = data.forecast.forecastday[ 2 ].day-- log(current, today, tomorrow)-- temperature in Cgrp.write('32/1/1', current.temp_c)
-- "feels like" temperature in Cgrp.write('32/1/2', current.feelslike_c)
-- humidity as percentagegrp.write('32/1/3', current.humidity)
-- wind speed in kilometers per hourgrp.write('32/1/4', current.wind_kph)
-- uv indexgrp.write('32/1/5', current.uv)
-- weather condition textgrp.write('32/1/6', current.condition.text)
-- pressure in millibarsgrp.write('32/1/7', current.pressure_mb)
-- precipitation amount in millimetersgrp.write('32/1/8', current.precip_mm)
-- minimum temperature in celsius for the daygrp.write('32/2/1', today.mintemp_c)
-- maximum temperature in celsius for the daygrp.write('32/2/2', today.maxtemp_c)
-- average temperature in celsius for the daygrp.write('32/2/3', today.avgtemp_c)
-- average humidity as percentagegrp.write('32/2/4', today.avghumidity)
-- maximum wind speed in kilometers per hourgrp.write('32/2/5', today.maxwind_kph)
-- uv indexgrp.write('32/2/6', today.uv)
-- weather condition textgrp.write('32/2/7', today.condition.text)
-- total precipitation in millimetersgrp.write('32/2/8', today.totalprecip_mm)
-- minimum temperature in celsius for the daygrp.write('32/3/1', tomorrow.mintemp_c)
-- maximum temperature in celsius for the daygrp.write('32/3/2', tomorrow.maxtemp_c)
-- average temperature in celsius for the daygrp.write('32/3/3', tomorrow.avgtemp_c)
-- average humidity as percentagegrp.write('32/3/4', tomorrow.avghumidity)
-- maximum wind speed in kilometers per hourgrp.write('32/3/5', tomorrow.maxwind_kph)
-- uv indexgrp.write('32/3/6', tomorrow.uv)
-- weather condition textgrp.write('32/3/7', tomorrow.condition.text)
-- total precipitation in millimetersgrp.write('32/3/8', tomorrow.totalprecip_mm)
(30.03.2016, 10:45)admin Wrote: Another option is to use forecast from http://yr.no
You have to replace URL with the one that corresponds to your location.
18.01.2019, 16:16 (This post was last modified: 18.01.2019, 16:23 by balatis.)
(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).
require('json')
https = require('ssl.https')
escape = require('socket.url').escapekey = '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)
iftype(data) ~= 'table'thenalert('failed to load weather data')
returnendifdata.errorthenlog('error', data.error)
returnendcurrent = data.currenttoday = data.forecast.forecastday[ 1 ].daytomorrow = data.forecast.forecastday[ 2 ].day-- log(current, today, tomorrow)-- temperature in Cgrp.write('32/1/1', current.temp_c)
-- "feels like" temperature in Cgrp.write('32/1/2', current.feelslike_c)
-- humidity as percentagegrp.write('32/1/3', current.humidity)
-- wind speed in kilometers per hourgrp.write('32/1/4', current.wind_kph)
-- uv indexgrp.write('32/1/5', current.uv)
-- weather condition textgrp.write('32/1/6', current.condition.text)
-- pressure in millibarsgrp.write('32/1/7', current.pressure_mb)
-- precipitation amount in millimetersgrp.write('32/1/8', current.precip_mm)
-- minimum temperature in celsius for the daygrp.write('32/2/1', today.mintemp_c)
-- maximum temperature in celsius for the daygrp.write('32/2/2', today.maxtemp_c)
-- average temperature in celsius for the daygrp.write('32/2/3', today.avgtemp_c)
-- average humidity as percentagegrp.write('32/2/4', today.avghumidity)
-- maximum wind speed in kilometers per hourgrp.write('32/2/5', today.maxwind_kph)
-- uv indexgrp.write('32/2/6', today.uv)
-- weather condition textgrp.write('32/2/7', today.condition.text)
-- total precipitation in millimetersgrp.write('32/2/8', today.totalprecip_mm)
-- minimum temperature in celsius for the daygrp.write('32/3/1', tomorrow.mintemp_c)
-- maximum temperature in celsius for the daygrp.write('32/3/2', tomorrow.maxtemp_c)
-- average temperature in celsius for the daygrp.write('32/3/3', tomorrow.avgtemp_c)
-- average humidity as percentagegrp.write('32/3/4', tomorrow.avghumidity)
-- maximum wind speed in kilometers per hourgrp.write('32/3/5', tomorrow.maxwind_kph)
-- uv indexgrp.write('32/3/6', tomorrow.uv)
-- weather condition textgrp.write('32/3/7', tomorrow.condition.text)
-- total precipitation in millimetersgrp.write('32/3/8', tomorrow.totalprecip_mm)
hi
for me do not work where is the fault?
thanks in advance.
////////////
require('json')
https = require('ssl.https')
escape = require('socket.url').escape
-- 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)
how is possible to put in visu a widget weather like this?