Page 1 of 2

Current weather

Posted: 13 Feb 2017 15:06
by Akt
Hi,
How to show current weather in widget?
Which site supply variable or how to get weather report from installed weather app?

Re: Current weather

Posted: 13 Feb 2017 23:38
by Scotty
1. Get a (free) API key from weather underground, here. You'll have to sign up, but that's free, too.

2. In automagic, do an http request (GET) using the URL below (replacing the info that I have put in CAPS):

http://api.wunderground.com/api/YOUR_API_KEY_HERE/conditions/q/DESIRED_WEATHER_INFO.xml

That xml info is saved in a variable whose name you define (e.g., weather).

Then you can extract the desired items from the xml info contained in the variable "weather", and feed that to your widget

Re: Current weather

Posted: 14 Feb 2017 14:58
by Akt
Hi scotty,
I tried to follow all your steps, but I am facing some problem.
The location is showing in U.S. And I live in India.
And how to get weather information from that.

Re: Current weather

Posted: 14 Feb 2017 19:16
by Scotty
@Akt

1. Your flow contains your API key, in text format - I'd delete that ASAP.

2. Your http request is aimed at "weather.xml", which delivers a DEFAULT report from Pennsylvania USA. To get weather from India, you simply need to change the text from "weather.xml" to (for example) "mumbai.xml"

Re: Current weather

Posted: 15 Feb 2017 03:27
by Akt
Hi
Could you post your flow after deleting your key.
And what all can we write in xml, only city names or anything else also?

Re: Current weather

Posted: 17 Feb 2017 20:46
by Scotty
flow_Bare_bones_weather_flow_20170217_122205.xml
Bare bones weather flow
(3.04 KiB) Downloaded 1007 times
I attach a bare bones flow. It is triggered by Time, but you can change that.

In the http request action, you need to replace two things: (i) apikeyhere (replace with your API key) and (ii) desiredlocationhere (replace with mumbai, as a test instance)

Then, when executed, the flow will obtain the weather info for Mumbai, saving it (in xml format) in the variable weather

The script then extracts (from weather) the current temp info (in F), and writes that numerical value to the variable global_CurrentTemp.

Then (merely as an example of what you could do) there's a condition (expression) to determine how to act on that information (if the current temp is 57 or less, returns TRUE).

Note 1: You may want to see the entire content of the weather information that was returned by the http request. There are several ways to do that. I suggest that you change where the HTTP request action stores the info (change it from Variable to File). Then, after executing the http request, you can open the xml file, and view it at your leisure. Seeing all of the weather info that is returned will allow you to change the flow's script, to extract information other than (or in addition to) the current temp.

Note 2: re/ your specific question. I can use, for example, a US ZIP code (e.g., 92110.xml) to successfully get weather forecast in that ZIP. I suggest that you identify the region from which you want the forecast, and then see what is available on Weather Underground. For example, in the USA a lot of people have personal weather stations that report to weather underground, and you can use them as a source (pws:InsertStationCodeHere.xml).

Re: Current weather

Posted: 17 Feb 2017 23:36
by Akt
Hi scotty,
Thanks for detailed information and explanation and I love your flow.
It is of very use to me.

Re: Current weather

Posted: 22 Feb 2017 15:43
by Akt
Hi scotty,
I tried to extract weather forecast but I was unable to do that .

Can you give me the script to get weather forecast.

Re: Current weather

Posted: 22 Feb 2017 19:58
by Scotty
Akt wrote:Hi scotty,
I tried to extract weather forecast but I was unable to do that .

Can you give me the script to get weather forecast.
You don't get the weather forecast using a script, you get it using the http request action, and then you use a script to extract the desired information (for example, maybe you want only the forecast for tomorrow).

So, look at the http request action in the bare bones flow that I provided, above. You'll see, in the URL, the word "conditions". That means that you're requesting to download the current weather conditions for the area you're interested in.

To obtain the forecast for that same area, replace "conditions" with "forecast", save it, and run the http request. Then, the variable weather will contain all of the forecast info, and you design a script to extract what you want....

Re: Current weather

Posted: 23 Feb 2017 02:16
by Akt
Thanks scotty.
What else can be written in place of conditions?