Rules and Expressions with Open Weather API

Since Weather DTH is deprecated… Anybody has done this ?..
Create some Rules to get weather data, set it to variables, and then display as wish, also use variables to trigger Alexa announcements (like “Tomorrow will be cold…”).

I’m looking into it now, with the free tier I can only pull 5 days at 3 hour increments. Trying to decide on what part of the day would be best to pull the forecast for. We have 00:00am,
03:00am, 06:00am, 09:00am, 12:00pm, 15:00pm, 18:00am, and 21:00pm.

1 Like

Go for it my friend !!!
I think hours you are thinking are fine ! … are you going to share ? :pensive: I will invite you a couple of :beers:

Yes, there were a few other posts where people are querying the various Open Weather APIs. :slight_smile:

Here’s a few reference threads:

Edit: I can’t seem to find it now, but someone had also recently done something with the Open Weather API and they were using the new expressions feature. @Jason_K_Jennings was that perhaps you?

2 Likes

Check out the last link in my reply above. In that thread, @JKB121 was using the ‘OneCall’ API endpoint from OpenWeather which also has forecast data. OneCall used to be available with a free account – it still is, but now it requires that you add a credit card even if you still set your daily limit within the free allotment. :slight_smile:

2 Likes

Thanks Josh !..I think… I need a guide for dummies, anyway I will fool around a bit to find it how … :muscle:

Works great. Haven’t had a charge yet… LOL

1 Like

Many options with this.

1 Like

Thanks, no use reinventing the wheel.

Oooohhh Im getting !.. how can I know all the “value using expression” I can get from openweather ? b.e. I can see: “data.daily.0.temp.max” and “…min”… which others ? THANKS !

Check out OpenWeatherMap API guide - OpenWeatherMap

There are about 1700 line items that are returned with the API call. Basically anything you can imagine is there.

1 Like

thanks my friend…You rock !!

Hi my friend. This is really cool…I had made some attempts with that…and it works for:

  • round($context.response.data.current.temp)
  • round($context.response.data.daily.0.temp.min)
  • round($context.response.data.daily.0.temp.max)

And they work !!.. but I had not got set next ones, Sharptools variables are text type, but they are set to blanks when rule is triggered, do you know why ?:

  • $context.response.data.current.weather.description
  • $context.response.data.daily.weather.description

In other idea the “0” value in .daily.0 expression is referred to number of the day ? …how can I get temperature o weather forecasting for next day ?

THANKS !

Based on their sample data, it looks like the current weather is nested within an array.

{
  "lat": 39.31,
  "lon": -74.5,
  "timezone": "America/New_York",
  "timezone_offset": -18000,
  "current": {
    "dt": 1646318698,
    "sunrise": 1646306882,
    "sunset": 1646347929,
    "temp": 282.21,
    "feels_like": 278.41,
    "pressure": 1014,
    "humidity": 65,
    "dew_point": 275.99,
    "uvi": 2.55,
    "clouds": 40,
    "visibility": 10000,
    "wind_speed": 8.75,
    "wind_deg": 360,
    "wind_gust": 13.89,
    "weather": [
      {
        "id": 802,
        "main": "Clouds",
        "description": "scattered clouds",
        "icon": "03d"
      }
    ]
  },

Notice that immediately after "weather": there is a [ which indicates an array. That means you would need something like the following to grab the first array item.

$context.response.data.current.weather.0.description

Like the above, the 0 is referring to the position of the item within the array. Arrays start at ‘0’ rather than ‘1’. You can find more details on how properties are accessed from objects in this thread.

1 Like

Thanks Josh… I will play around with it while enjoy the World Cup !!

1 Like

Don’t know if this is relevant here, but Todd Austin has made an Edge weatherstation.
The catch is it needs his edgebridge running on a server to link to an API. Since I have my camera server running and also using his phone presence app, I added this one as well. Simply use it in a rule or create a tile with the relevant info…

2 Likes

This is a long shot from me !!

$context.response.data.daily.0.weather.0.description

Nested array !

1 Like

That looks right.

For future reference here is an example of the data found under each of the 9 days of DAILY data provided by the OneCall API.


    "daily": [
        {
            "dt": 1669662000,
            "sunrise": 1669647705,
            "sunset": 1669682682,
            "moonrise": 1669665600,
            "moonset": 1669701420,
            "moon_phase": 0.18,
            "temp": {
                "day": 55.92,
                "min": 46.11,
                "max": 58.71,
                "night": 46.11,
                "eve": 57.33,
                "morn": 47.46
            },
            "feels_like": {
                "day": 53.65,
                "night": 45.1,
                "eve": 55.06,
                "morn": 46.38
            },
            "pressure": 1014,
            "humidity": 52,
            "dew_point": 38.05,
            "wind_speed": 6.89,
            "wind_deg": 157,
            "wind_gust": 11.63,
            "weather": [
                {
                    "id": 803,
                    "main": "Clouds",
                    "description": "broken clouds",
                    "icon": "04d"
                }
            ],
            "clouds": 81,
            "pop": 0.06,
            "uvi": 1.78
        },
1 Like

This is what I use.

{{$context.response.data.daily.1.weather.0.description}}
1 Like

I should have been clear that I was referring to the format only. The number after daily should correspond to the day for data is wanted.