“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 !
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?
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 $context.response.data.your.value if desired.
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?
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.
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.
Let’s take the Open Weather /weather endpoint which provides the current weather. The URL is in the format:
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:
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 $context.response.data.alerts doesn’t exist in the json
In the second line, we’re using isEmpty() which can check for an empty string, empty array, or in this case a missing property (eg. undefined). And even if the property did exist and was empty, this doesn’t hurt as it’s still just using an empty array in that case. And if it does exist and does have content, it uses the content.
Same concept as above with using isEmpty(). This ones a bit shorter, but I personally find the logic of the other one easier to interpret… which is important when I try to edit an expression a few months later and need to remember what the heck I did!