Logic Machine Forum
Weather service not working anymore? - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Weather service not working anymore? (/showthread.php?tid=253)

Pages: 1 2 3 4 5


RE: Weather service not working anymore? - Trond Hoyem - 01.10.2017

(01.10.2017, 14:57)Erwin van der Zwart Wrote: Hi,


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


RE: Weather service not working anymore? - Erwin van der Zwart - 01.10.2017

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:
require 'ssl.https'
require 'json'

-- Set your API key here
api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

-- Set here your location
location = 'Amsterdam'

-- Request data from API
r,c,h,s = ssl.https.request('https://api.apixu.com/v1/forecast.json?key=' .. api_key .. '=' .. location)

-- Decode JSON data to LUA table
if r then
 result = json.pdecode(r)
else
 alert('Could not fetch data')
 return
end

-- Get next hour temperature
temperature_in_one_hour = result['forecast']['forecastday'][1]['hour'][1]['temp_c']

-- Do something with the received temperature
log(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 

BR,

Erwin


RE: Weather service not working anymore? - jetsetter - 07.01.2019

Happy new year to all.

I think that the Weather service has stoped working since some days ago. Can you please check this?
Thank you in advance.


RE: Weather service not working anymore? - Thomas - 07.01.2019

Hi
Yes. I can confirm it stopped working 4.1.2019.
http://openrb.com/weather/?w=796597
returns
{"error":true,"cause":"response error"}


RE: Weather service not working anymore? - suporte.arqtech - 07.01.2019

Hi.

There´s some changes in the Yahoo API.
They changed the link and created a user key system (like OpenWeatherMap) that is needed for get the data.

BR


RE: Weather service not working anymore? - balatis - 07.01.2019

same problem


RE: Weather service not working anymore? - Thomas - 08.01.2019

Is there somebodybody who has a ready solution for yr.no?
https://api.met.no/
https://api.met.no/weatherapi/documentation

It looks easy, doesn't require autentication token etc. SoI'm asking before I'm going to implement it.


RE: Weather service not working anymore? - admin - 08.01.2019

See this example for yr.no: https://forum.logicmachine.net/showthread.php?tid=253&pid=1164#pid1164

As for Yahoo, we are still waiting for them to accept our access request since their API changed again.


RE: Weather service not working anymore? - Thomas - 08.01.2019

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.
Code:
require('socket.http')

forecast = {}

function parsetag(parser, tag, attributes)
 if tag == 'time' then
   table.insert(forecast, {})
   forecast[ #forecast ].from=attributes.from
   forecast[ #forecast ].to=attributes.to
   forecast[ #forecast ].period=attributes.period
 elseif tag == 'symbol' then
   forecast[ #forecast ].symbol = attributes.name
 elseif tag == 'precipitation' then
   forecast[ #forecast ].precipitation = attributes.value
 elseif tag == 'windDirection' then
   forecast[ #forecast ].wind_direction = attributes.code
 elseif tag == 'windSpeed' then
   forecast[ #forecast ].wind_speed = attributes.mps
 elseif tag == 'temperature' then
   forecast[ #forecast ].temperature = attributes.value
 elseif tag == 'pressure' then
   forecast[ #forecast ].pressure = attributes.value
 end
end

function yrno_fetch()
 local url = 'http://www.yr.no/place/Czech_Republic/Prague/Prague/varsel.xml'
 local data, err = socket.http.request(url)

 if data then
   require('lxp').new({
     StartElement = parsetag
   }):parse(data)
   
   
 else
   alert('Fetch failed: ' .. tostring(err))
 end
end

function minmax_temp_tomorrow()
 local ld_minTemp
 local ld_maxTemp
 local next_day={}

 yrno_fetch()
 if (not forecast) then
   return
 end
 local ll_tomorrow=os.time()+24*3600 -- tomorrow as long
 local lt_tomorrow= os.date("*t",ll_tomorrow) -- tomorrow as table for use if forecast_write

 --gets date of tomorrow
 local ls_match=os.date("%Y--%m--%d",ll_tomorrow)

 
for index, value in ipairs(forecast) do
   if (value.from:match("^"..ls_match)) then
     local ld_temp=tonumber(value.temperature)
     if (ld_minTemp == nil) then
       ld_minTemp=ld_temp
     end
     if (ld_maxTemp == nil) then
       ld_maxTemp=ld_temp
     end
     if (ld_temp<ld_minTemp or index==1) then
       ld_minTemp=ld_temp
     end
     if (ld_temp>ld_maxTemp or index==1) then
       ld_maxTemp=ld_temp
     end
   end
end
  return ld_minTemp,ld_maxTemp,lt_tomorrow
end



RE: Weather service not working anymore? - Evens - 08.01.2019

(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.
Code:
require('socket.http')

forecast = {}

function parsetag(parser, tag, attributes)
 if tag == 'time' then
   table.insert(forecast, {})
   forecast[ #forecast ].from=attributes.from
   forecast[ #forecast ].to=attributes.to
   forecast[ #forecast ].period=attributes.period
 elseif tag == 'symbol' then
   forecast[ #forecast ].symbol = attributes.name
 elseif tag == 'precipitation' then
   forecast[ #forecast ].precipitation = attributes.value
 elseif tag == 'windDirection' then
   forecast[ #forecast ].wind_direction = attributes.code
 elseif tag == 'windSpeed' then
   forecast[ #forecast ].wind_speed = attributes.mps
 elseif tag == 'temperature' then
   forecast[ #forecast ].temperature = attributes.value
 elseif tag == 'pressure' then
   forecast[ #forecast ].pressure = attributes.value
 end
end

function yrno_fetch()
 local url = 'http://www.yr.no/place/Czech_Republic/Prague/Prague/varsel.xml'
 local data, err = socket.http.request(url)

 if data then
   require('lxp').new({
     StartElement = parsetag
   }):parse(data)
   
   
 else
   alert('Fetch failed: ' .. tostring(err))
 end
end

function minmax_temp_tomorrow()
 local ld_minTemp
 local ld_maxTemp
 local next_day={}

 yrno_fetch()
 if (not forecast) then
   return
 end
 local ll_tomorrow=os.time()+24*3600 -- tomorrow as long
 local lt_tomorrow= os.date("*t",ll_tomorrow) -- tomorrow as table for use if forecast_write

 --gets date of tomorrow
 local ls_match=os.date("%Y--%m--%d",ll_tomorrow)

 
for index, value in ipairs(forecast) do
   if (value.from:match("^"..ls_match)) then
     local ld_temp=tonumber(value.temperature)
     if (ld_minTemp == nil) then
       ld_minTemp=ld_temp
     end
     if (ld_maxTemp == nil) then
       ld_maxTemp=ld_temp
     end
     if (ld_temp<ld_minTemp or index==1) then
       ld_minTemp=ld_temp
     end
     if (ld_temp>ld_maxTemp or index==1) then
       ld_maxTemp=ld_temp
     end
   end
end
  return ld_minTemp,ld_maxTemp,lt_tomorrow
end

Hi Thomas,

Do you have an example of how to write the forecast to GA? and what datatype the different object needs to be?

BR Even Sundgot.


RE: Weather service not working anymore? - Thomas - 09.01.2019

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)

Code:
function forecast_write(low,high,next_day)
 low = low or 0
 high = high or 0
 next_day = next_day or 0
 grp.write('7/2/30', low, dt.float16)
 grp.write('7/2/31', high, dt.float16)
 grp.write('7/2/32', next_day, dt.date)
end  

require ('user.ecl_yrno')
forecast_write(minmax_temp_tomorrow())



RE: Weather service not working anymore? - jetsetter - 14.01.2019

(08.01.2019, 14:46)admin Wrote: As for Yahoo, we are still waiting for them to accept our access request since their API changed again.

Hi, any news or estimations from Yahoo regarding when you will have access to repair the existing weather service?


RE: Weather service not working anymore? - admin - 14.01.2019

No response from them, we will probably have to move to a more reliable data provider.


RE: Weather service not working anymore? - admin - 18.01.2019

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)



RE: Weather service not working anymore? - permar - 18.01.2019

(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.

Code:
require('socket.http')

forecast = {}

function parsetag(parser, tag, attributes)
 if tag == 'time' then
   table.insert(forecast, {})
 elseif tag == 'symbol' then
   forecast[ #forecast ].symbol = attributes.name
 elseif tag == 'precipitation' then
   forecast[ #forecast ].precipitation = attributes.value
 elseif tag == 'windDirection' then
   forecast[ #forecast ].wind_direction = attributes.code
 elseif tag == 'windSpeed' then
   forecast[ #forecast ].wind_speed = attributes.mps
 elseif tag == 'temperature' then
   forecast[ #forecast ].temperature = attributes.value
 elseif tag == 'pressure' then
   forecast[ #forecast ].pressure = attributes.value
 end
end

url = 'http://www.yr.no/place/United_Kingdom/England/London/varsel.xml'
data, err = socket.http.request(url)

if data then
 require('lxp').new({
   StartElement = parsetag
 }):parse(data)

 log(forecast)
else
 alert('Fetch failed: ' .. tostring(err))
end

Hi!

This works fine when im checking the log but how do I modify it to write the values to bus?

Best Regards!

P


RE: Weather service not working anymore? - Daniel - 18.01.2019

Hi
I'm doing it like that

Code:
require('socket.http')

forecast = {}

function parsetag(parser, tag, attributes)
 if tag == 'time' then
   table.insert(forecast, {})
 elseif tag == 'symbol' then
   forecast[ #forecast ].symbol = attributes.name
 elseif tag == 'precipitation' then
   forecast[ #forecast ].precipitation = attributes.value
 elseif tag == 'windDirection' then
   forecast[ #forecast ].wind_direction = attributes.code
 elseif tag == 'windSpeed' then
   forecast[ #forecast ].wind_speed = attributes.mps
 elseif tag == 'temperature' then
   forecast[ #forecast ].temperature = attributes.value
 elseif tag == 'pressure' then
   forecast[ #forecast ].pressure = attributes.value
 end
end

url = 'http://www.yr.no/place/United_Kingdom/England/Farnborough/varsel.xml'
data, err = socket.http.request(url)

if data then
 require('lxp').new({
   StartElement = parsetag
 }):parse(data)


 grp.update('Weather precipitation', tonumber(forecast[1].precipitation))
 grp.update('Weather symbol', forecast[1].symbol)
 grp.update('Weather windDirection', forecast[1].wind_direction)
 grp.update('Weather windSpeed', tonumber(forecast[1].wind_speed))
 grp.update('Weather temperature', tonumber(forecast[1].temperature))
 grp.update('Weather pressure', tonumber(forecast[1].pressure))

 --log(forecast)
 
else
 alert('Fetch failed: ' .. tostring(err))
end



RE: Weather service not working anymore? - balatis - 18.01.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)
hi 
for me do not  work where is the fault?
thanks in advance.
////////////
require('json')
https = require('ssl.https')
escape = require('socket.url').escape

key = 'dd14841bec7c428a8ed154420191801'
location = 'https://www.apixu.com/weather/q/patra-west-greece-greece-2855484'

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)




how is possible to put in visu a widget weather like this?


RE: Weather service not working anymore? - admin - 18.01.2019

Try this:
Code:
location = 'patra, greece'

For widget you will need to create a separate html page, upload it via ftp and then display by using iframe element.


RE: Weather service not working anymore? - balatis - 20.01.2019

(18.01.2019, 16:31)admin Wrote: Try this:
Code:
location = 'patra, greece'

For widget you will need to create a separate html page, upload it via ftp and then display by using iframe element.

Thanks admin 
can i have information for sunset and sunrise.


RE: Weather service not working anymore? - admin - 21.01.2019

Use this for sunrise/sunset. Object data type must be set to text/string.
Code:
astro = data.forecast.forecastday[ 1 ].astro

grp.write('32/4/1', astro.sunrise)
grp.write('32/4/2', astro.sunset)
grp.write('32/4/3', astro.moonrise)
grp.write('32/4/4', astro.moonset)

You can also use built-in rscalc function for this: https://forum.logicmachine.net/showthread.php?tid=1010