WeatherFlow Widget for iOS/iPadOS 14

Very cool! I tweaked mine slightly to add wind gust and last lightning strike distance. Thanks!

2 Likes

Very good: maybe you could share the settings? Thanks in advance

You can find and change the following parts.
To add Wind Gust:

wind = convertWindSpeed(data.obs[0].wind_avg, data.station_units.units_wind)
windgust = convertWindSpeed(data.obs[0].wind_gust, data.station_units.units_wind)

if(wind == 0) {
displayWind = “Calm”
} else {
windDirection = convertWindDirection(data.obs[0].wind_direction, data.station_units.units_direction)
displayWind = windDirection[“display”] + “” + windDirection[“unit”] + " " + wind[“display”] + ", " + windgust[“display”] + " " + wind[“unit”]
}

To add Last Lightning Distance (in miles):

lightningDist = (Math.round(((data.obs[0].lightning_strike_last_distance/1.61) + Number.EPSILON) * 100) / 100)
let lightningLine = w.addText(“:zap:” + data.obs[0].lightning_strike_count_last_3hr + ", " + lightningDist + “m”)

To add Last Lightning Distance (in kilometers):

let lightningLine = w.addText(“:zap:” + data.obs[0].lightning_strike_count_last_3hr + ", " + data.obs[0].lightning_strike_last_distance + “km”)

Of course, this will be from the last time the widget updated, which could be a while (up to like 20 minutes), so not as useful as we would like.

I have mine in a stack of rectangular widgets, so at some point I will likely tweak it a bit more to increase the font size, make it 2 columns and add a couple more bits of data (precipitation chance and such). Though hopefully WeatherFlow will add their own widget before I get too involved in it.

2 Likes

Hey hi,

would there be a possibility to add a custom background to the script?

Greetings Chris

If you only want to change the background color, just modify this line:

w.backgroundColor = Color.black()

But, if you mean a background image, then it is more complex. You can save the image as a file, and add it to file bookmarks in the Scriptable app settings, name it background-image (or whatever) then find this line in the widget code:

w.backgroundColor = Color.black()

and replace it with this:

Let backImage = filemanager.icloud.bookmarkedpath(“background-image”)
w.background(
Image(“backImage”)
.resizable()
.scaledToFill()
)

I haven’t actually tried this, so no guarantees that it will work. The image will need to be like 164x164 pixels, I think. You will also need to make sure that CONFIG_DYNAMIC_BACKGROUND is set to FALSE near the top of the widget code.

Finally made it :slightly_smiling_face:

Custom background

[Code addition]

if(CONFIG_DYNAMIC_BACKGROUND) {
let bgColor = new LinearGradient()
bgColor.colors = [new Color("#000000"), new Color(temperature[“color”])]
bgColor.locations = [0.0, 1.0]
w.backgroundGradient = bgColor
} else {

let fm = FileManager.iCloud()
let path = fm.documentsDirectory() + "/Pictures/image.jpg";
w.backgroundImage = fm.readImage(path);

}

[/Code addition]

Here the Scriptable solution for getting custom backgrounds

1 Like

I’m trying to setup this on my iOS 14 and I’m getting the error below. I created a new Token and copied it but not sure why I’m getting syntax error. Any idea?

There should be quotes before and after your api key.
const CONFIG_API_KEY = “xxxxx”

No quotes for the station ID.
const CONFIG_STATION_ID = 12345

Thank baff, I had missing the “quotes”.

Just copied the script and followed your excellent instructions, this makes a very convenient way to check the Tempest data. Thank you for sharing your work.

Just installed. Thanks. Very nice.

Thanks for the revisions. I tweaked it a bit more to my liking (first time editing Javascript, too).

1 Like

Nice work @stuartgoldman. I like the Gust report. I’ll try to add it to mine.

What a great piece of code. It works great! Can we get the widget to launch the Weatherflow/Tempest app when you touch the widget?

Also, what’s the code segment to add wind gust?

Thanks,
Jeff

To add wind gust, find the wind related code and change it to this:

wind = convertWindSpeed(data.obs[0].wind_avg, data.station_units.units_wind)
windgust = convertWindSpeed(data.obs[0].wind_gust, data.station_units.units_wind)

if(wind == 0) {
displayWind = “Calm”
} else {
windDirection = convertWindDirection(data.obs[0].wind_direction, data.station_units.units_direction)
displayWind = windDirection[“display”] + “” + windDirection[“unit”] + " " + wind[“display”] + " G " + windgust[“display”] + " " + wind[“unit”]
}

To launch the Tempest app on tap:

Tap and hold the widget, then select: Edit “Scriptable”
Tap “When Interacting” and change to “Open URL”
Tap URL and type in: smartweather://
Tap Done
Tap anywhere outside the window to close it.

The first time you tap the widget it will ask permission to open the Tempest app. After that it should just open. Though it does also open the Scriptable app at the same time, but it gets pushed to the background when Tempest opens.

4 Likes

Perfect. Thanks for that tip.

Can you paste the code for lightning distance?

To add Last Lightning Distance (in miles):

lightningDist = (Math.round(((data.obs[0].lightning_strike_last_distance/1.61) + Number.EPSILON) * 10) / 10)
let lightningLine = w.addText(“:zap:” + data.obs[0].lightning_strike_count_last_3hr + ", " + lightningDist + “miles”)

To add Last Lightning Distance (in kilometers):

let lightningLine = w.addText(“:zap:” + data.obs[0].lightning_strike_count_last_3hr + ", " + data.obs[0].lightning_strike_last_distance + “km”)

The widget only updates a max of like 4 times per hour (limit set by Apple), so this often isn’t a useful as it may sound.

1 Like

I am impressed by your work and your talent to keep calm while people constantly are asking for modifications ! Great job !