Rules and Expressions with Open Weather API

This is what I use.

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.

This is really cool !.. I got this weather report ready to send it to Alexa or Pushover message…

“At this moment there is 20 C. For today there will be scattered clouds and a mild weather, with a minimum of 14 C and a maximum of 22 C. Enjoy your day.”

I will be to make the same but for a night report for next day weather …


Would you mind sharing your http string for pulling the today, tonight and tomorrow reports? All I seem to get is “scattered clouds”, “sunny” etc.

Hi my friend. The http call is the same, but the expression has to ask for the correct context value. For tomorrow data I am using:


“1” value is the 2nd array of the context response (tomorrow) and “0” value is the 1st array of the weather context response (weather data), also you can use “description” instead “main” for a deeply data of the weather. I hope this helps !


Hi Friends !
Does anybody knows how to get the day of the week (DOW) from forecast daily “dt” (UTC time stamp) value ?

I know for example that 1646326800: is “Thu Mar 03 2022 17:00:00 GMT+0000”, but I want to get “Thu” to translate to the Spanish “Jue”.


Hi @Carlos_Juarez-
This Custom Tiles tile should automatically display the days of week based on the language code you enter. Are you perhaps referring to the work you were doing in the Rules to Query Open Weather where you are querying the weather with rules?

1 Like

Hi Josh… Oh yes !.. Im referring to the rules to query Open Weather, I think in the wrong post. !

Hi @Carlos_Juarez - I merged the posts into your main Open Weather Rule API thread.

You could use an Expression to format the dt value that you mentioned. The Date Functions and Date Formats help documents might be helpful here. The formatDate() method can be used to format your timestamps to a string to get the day of week:

formatDate(now(), 'ddd', 'es')

So if you have the timestamp in seconds from the Open Weather request in a variable, we just need to convert it into milliseconds by multiplying it by 1000 to be used with the formatDate() function. You could also just reference the $ if desired.

formatDate($myTimestamp * 1000, 'ddd', 'es')
1 Like

Can someone tell me what I have wrong in these 2 expressions querying the OpenWeather API?
They are string variables and return <>

This is the what I use for wind speed but I use the manual method.

{{round($}} mph

It will return a string like this

3 mph

1 Like

That worked for wind speed. Still getting an error for wind gust. I reformatted gust to what you are using.

This should work.

{{round($}} mph

I have got this … !! Icons are animated gifs made by myself …


I’m using the API call to pull in this information and it works just fine. To pull it in, mine looks like this:

and the output looks like this:

My questions are about the json response:

  • Since the ‘alert’ section won’t always be included in the response, is there an appropriate way to process it only when data exists (maybe an if statement to check to see if it exists before processing it).
  • Since I wouldn’t know how many values for the ‘alert’ exist (today it is both wind and tornado) – how should I handle this to only process the correct number of ‘events’ that exist in the json file?
  • Is there any way to insert a carriage return into the text?

If it’s an array, using the map() concept below accounts for this.

Otherwise, using a conditional ternary expression works:

condition ? trueOperation : falseOperation

Since it’s an array, I would probably use a map() and join() to handle it.

alerts = $
myString = map(alerts, concat(x.event, " until ", formatDate(x.end * 1000, "h:mm a")))
join(myString, "\r\n")

The General Functions in Expressions documentation covers the basics above the above functions or you can search the community as there were a few recent posts about expressions and arrays that may be helpful. This discussion links to a few Array related discussions of interest.

The \r\n in my example above inserts a new line (Carriage Return / Line Feed). It won’t show up in the variable preview or variable editor, but it will in a notification or a dashboard variable tile.


I’m missing something yet… Could you please share your API pull statement?

You can get it from the below, there are several topics on opening an account, getting a key and calling the OpenWeatherMap API.


Aug '22

You can do this with the HTTP Action in SharpTools today. I agree that it makes for a good feature request as a native integration though to simplify this process for people who don’t have weather devices attached to their SmartThings. :smiley:

Let’s take the Open Weather /weather endpoint which provides the current weather. The URL is in the format:{{ApiKey}}

And the response is in the format:

         "description":"light rain",

So if we wanted to get the main weather report, we would be looking for the weather.0.main element in the response. So we can make the HTTP call and then get the response data using Context Variables (Response > HTTP > Data) and use the object property notation to grab that nested property for use in our notification:

1 Like

ok, I had a OpenWeather 3.0 API and it seems to be able to pull the response. I appear to have an issue with the CONCAT statement: << expression evaluation error >>

Couple of things:

  • The one I’m using is the 3.0 version as well:
  • If you don’t have a weather update today (hopefully you don’t) - you’ll get the ‘<< expression evaluation error >>’ – but you can check by pasting your openweather API link into a browser, copying that response and then pasting into a json formatter. It’ll look something like this when you have an alert (this was mine from yesterday):

What I can’t figure out is how to set a boolean variable to true if the alert exists and then set the alert field, and if its false to set to plain language such as ‘No Weather Alerts Today’

I keep trying something like this, but no luck as the $ doesn’t exist in the json