Skip to content

Weather: Add v2 weather parsing in Weather App (forecast support) #3910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion apps/weather/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@
0.24: Redraw clock_info on update and provide color field for condition
0.25: Added monochrome parameter to drawIcon in lib
0.26: Expose update function (for use by iOS integration)
0.27: Add UV index display
0.27: Add UV index display
0.28: Refactor code to more modern javascript style
Split settings and weather data into two files in storage
Add support for new version of weather data and forecast from GadgetBridge (requires version 0.86.0 or higher)
Add support to automatically fetch weather at time interval defined in settings (requires GadgetBridge version 0.86.0 or higher)
Add button to settings to force fetch weather data (requires GadgetBridge version 0.86.0 or higher)
Add new API to get weather from Weather App for other Apps
87 changes: 71 additions & 16 deletions apps/weather/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,38 @@ You can view the full report through the app:

![Screenshot](screenshot.png)
## iOS Setup

Use the iOS shortcut [here](https://www.icloud.com/shortcuts/dbf7159200d945179e0938c15e64f102). The shortcut uses Apple Weather for weather updates, and sends a notification, which is read by Bangle.js. To push weather every hour, or interval, you will need to create a shortcut automation for every time you want to push the weather.
## Android Setup

1. Install [Gadgetbridge for Android](https://f-droid.org/packages/nodomain.freeyourgadget.gadgetbridge/) on your phone.
2. Set up [Gadgetbridge weather reporting](https://codeberg.org/Freeyourgadget/Gadgetbridge/wiki/Weather).
## Android Setup

If using the `Bangle.js Gadgetbridge` app on your phone (as opposed to the standard F-Droid `Gadgetbridge`) you need to set the package name
to `com.espruino.gadgetbridge.banglejs` in the settings of the weather app (`settings -> gadgetbridge support -> package name`).
1. Install [Gadgetbridge for Android](https://f-droid.org/packages/nodomain.freeyourgadget.gadgetbridge/) on your phone
2. Set up [Gadgetbridge weather reporting](https://gadgetbridge.org/basics/features/weather/)

### Android Weather Apps

There are two weather apps for Android that can connect with Gadgetbridge:
There are multiple weather apps for Android that can connect with Gadgetbridge:

* Tiny Weather Forecast Germany
* F-Droid - https://f-droid.org/en/packages/de.kaffeemitkoffein.tinyweatherforecastgermany/
* Source code - https://codeberg.org/Starfish/TinyWeatherForecastGermany
* F-Droid - https://f-droid.org/en/packages/de.kaffeemitkoffein.tinyweatherforecastgermany/
* Source code - https://codeberg.org/Starfish/TinyWeatherForecastGermany

* QuickWeather
* F-Droid - https://f-droid.org/en/packages/com.ominous.quickweather/
* Google Play - https://play.google.com/store/apps/details?id=com.ominous.quickweather
* Source code - https://github.com/TylerWilliamson/QuickWeather

* F-Droid - https://f-droid.org/en/packages/com.ominous.quickweather/
* Google Play - https://play.google.com/store/apps/details?id=com.ominous.quickweather
* Source code - https://github.com/TylerWilliamson/QuickWeather

* Breezy Weather
* F-Droid - https://f-droid.org/en/packages/org.breezyweather/
* Source code - https://github.com/breezy-weather/breezy-weather

### Tiny Weather Forecast Germany

Even though Tiny Weather Forecast Germany is made for Germany, it can be used around the world. To do this:

1. Tap on the three dots in the top right hand corner and go to settings
2. Go down to Location and tap on the checkbox labeled "Use location services". You may also want to check on the "Check Location checkbox". Alternatively, you may select the "manual" checkbox and choose your location.
3. Scroll down further to the "other" section and tap "Gadgetbridge support". Then tap on "Enable". You may also choose to tap on "Send current time".
3. Scroll down further to the "other" section and tap "Gadgetbridge support". Then tap on "Enable". You may also choose to tap on "Send current time".
4. If you're using the specific Gadgetbridge for Bangle.JS app, you'll want to tap on "Package name." In the dialog box that appears, you'll want to put in "com.espruino.gadgetbridge.banglejs" without the quotes. If you're using the original Gadgetbridge, leave this as the default.

### QuickWeather
Expand All @@ -47,6 +50,14 @@ If you're using OpenWeatherMap you will need the "One Call By Call" plan, which

When you first load QuickWeather, it will take you through the setup process. You will fill out all the required information as well as put your API key in. If you do not have the "One Call By Call", or commonly known as "One Call", API, you will need to sign up for that. QuickWeather will work automatically with both the main version of Gadgetbridge and Gadgetbridge for Bangle.JS.

### Breezy Weather

Enabling connection to Gadgetbridge:

1. Tap on the three dots in the top right hand corner and go to settings
2. Find "Widgets & Live wallpaper" settings
3. Under "Data sharing" tap on "Send Gadgetbridge data" and enable for Gadgetbridge flavor you are using

### Weather Notification

**Note:** at one time, the Weather Notification app also worked with Gadgetbridge. However, many users are reporting it's no longer seeing the OpenWeatherMap API key as valid. The app has not received any updates since August of 2020, and may be unmaintained.
Expand All @@ -60,9 +71,12 @@ Adds:
* Wind speed ClockInfo.
* Chance of rain ClockInfo.
* Temperature ClockInfo without condition icon.

## Settings

* Expiration timespan can be set after which the local weather data is considered as invalid
* Expiration time span can be set after which the local weather data is considered as invalid
* Automatic weather data request interval can be set (weather data are pushed to Bangle automatically, but this can help in cases when it fails) (requires Gadgetbridge v0.86+)
* Extended or forecast weather data can be enabled (this requires other App to use this data, Weather App itself doesn't show the forecast data) (requires Gadgetbridge v0.86+)
* Widget can be hidden
* To change the units for wind speed, you can install the [`Languages app`](https://banglejs.com/apps/?id=locale) which
allows you to choose the units used for speed/distance/temperature and so on.
Expand All @@ -71,3 +85,44 @@ allows you to choose the units used for speed/distance/temperature and so on.

* BTN2: opens the launcher (Bangle.js 1)
* BTN: opens the launcher (Bangle.js 2)

## Weather App API

Note: except `getWeather()` and `get()` it is android only for now

Weather App can provide weather and forecast data to other Apps.

* Get weather data without forecast/extended:
```javascript
const weather = require("weather");
weatherData = weather.getWeather(false); // or weather.get()
```

* Get weather data with forecast/extended (needs forecast/extended enabled in settings):
```javascript
const weather = require("weather");
weatherData = weather.getWeather(true);
```

* Fetch new data from Gadgetbridge:
```javascript
const weather = require("weather");
weather.updateWeather(false); // Can set to true if we want to ignore debounce
```

* React to updated weather data:
```javascript
const weather = require("weather");

// For weather data without forecast
weather.on("update", () => {
currentData = weather.getWeather(false);
// console.log(currentData);
}

// For weather data with forecast
weather.on("update2", () => {
currentData = weather.getWeather(true);
// console.log(currentData);
}
```
18 changes: 9 additions & 9 deletions apps/weather/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ var layout = new Layout({type:"v", bgCol: g.theme.bg, c: [
render: l => {
if (!current || current.uv === undefined) return;
const uv = Math.min(parseInt(current.uv), 11); // Cap at 11

// UV color thresholds: [max_value, color] based on WHO standards
const colors = [[2,"#0F0"], [5,"#FF0"], [7,"#F80"], [10,"#F00"], [11,"#F0F"]];
const color = colors.find(c => uv <= c[0])[1];

// Setup and measure label
g.setFont("6x8").setFontAlign(-1, 0);
const label = "UV: ";
const labelW = g.stringWidth(label);

// Calculate centered position (4px block + 1px spacing) * blocks - last spacing
const totalW = labelW + uv * 5 - (uv > 0 ? 1 : 0);
const x = l.x + (l.w - totalW) / 2;
const y = l.y + l.h;

// Draw label
g.setColor(g.theme.fg).drawString(label, x, y);

// Draw UV blocks
g.setColor(color);
for (let i = 0; i < uv; i++) {
Expand Down Expand Up @@ -70,7 +70,7 @@ var layout = new Layout({type:"v", bgCol: g.theme.bg, c: [
]}, {lazy: true});

function formatDuration(millis) {
let pluralize = (n, w) => n + " " + w + (n == 1 ? "" : "s");
let pluralize = (n, w) => `${n} ${w}${n === 1 ? "" : "s"}`;
if (millis < 60000) return /*LANG*/"< 1 minute";
if (millis < 3600000) return pluralize(Math.floor(millis/60000), /*LANG*/"minute");
if (millis < 86400000) return pluralize(Math.floor(millis/3600000), /*LANG*/"hour");
Expand All @@ -83,10 +83,10 @@ function draw() {
const temp = locale.temp(current.temp-273.15).match(/^(\D*\d*)(.*)$/);
layout.temp.label = temp[1];
layout.tempUnit.label = temp[2];
layout.hum.label = current.hum+"%";
layout.hum.label = `${current.hum}%`;
const wind = locale.speed(current.wind).match(/^(\D*\d*)(.*)$/);
layout.wind.label = wind[1];
layout.windUnit.label = wind[2] + " " + (current.wrose||'').toUpperCase();
layout.windUnit.label = `${wind[2]} ${(current.wrose||'').toUpperCase()}`;
layout.cond.label = current.txt.charAt(0).toUpperCase()+(current.txt||'').slice(1);
layout.loc.label = current.loc;
layout.updateTime.label = `${formatDuration(Date.now() - current.time)} ago`; // How to autotranslate this and similar?
Expand Down Expand Up @@ -140,4 +140,4 @@ Bangle.setUI("clock");
// This matters for widgets that hide themselves for clocks, like widclk or widclose
delete Bangle.CLOCK;

Bangle.drawWidgets();
Bangle.drawWidgets();
6 changes: 3 additions & 3 deletions apps/weather/clkinfo.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
(function() {
(() => {
var weather;
var weatherLib = require("weather");

function updateWeather() {
weather = weatherLib.get();
if(weather){
weather.temp = require("locale").temp(weather.temp-273.15);
weather.hum = weather.hum + "%";
weather.hum = `${weather.hum}%`;
weather.wind = require("locale").speed(weather.wind).match(/^(\D*\d*)(.*)$/);
weather.wind = Math.round(weather.wind[1]) + "kph";
weather.wind = `${Math.round(weather.wind[1])}kph`;
} else {
weather = {
temp: "?",
Expand Down
Loading