Forecast

A forecast is one of the most common widgets. Is it one of the simplest to make? Yes. And no.

This tutorial is divided in two parts. The first part is for the simple daily forecast and the second upgrades it with hourly intervals.

Daily Forecast

Calculation is based on a horizontal stack of condition groups. Each weather condition group is a vertical stack group containing all the weather info.

Global Formulas

To control the forecast, create 2 number globals:

gv(interval)

min: 1

description: days between forecasts (1 = every day, 2 = every 2 days, etc.)

gv(offset)

min: 0

description: start of the forecast (0 = today, 1 = tomorrow, 2 = 2 days from now, etc.)

NOTE: You can make an even simpler daily forecast by not including gv(interval) and gv(offset). Just keep in mind that it won't be as customizable anymore.

ALSO: These globals can be list or text globals, depending on your use case (for touch input).


For the forecast info, create 6 text globals with these formulas:

gv(index)

$si(mindex,1)*gv(interval)+gv(offset)$

Can be different based on how you set up groups.

gv(time)

$df("EEE d", a+gv(index)+d)$

"EEE d" is an example. Formula can display almost anything from the df() section.

gv(cond)

$wf(cond, gv(index))$

gv(wicon)

$wf(icon, gv(index))$

Returns the equivalent of $wi(icon)+ai(isday)$. Change based on the weather icon pack.

gv(temp)

$wf(max, gv(index))$

Can also display wf(temp, if you don't use the next global.

gv(tempmin)

$wf(min, gv(index))$

Making the Group

  • Make a horizontal stack group;

  • in it create a vertical stack group;

  • inside add text objects linking them to one of the global formulas above (link gv(wicon) to the fonticon/bitmap).

Just copy and paste the vertical stack group as many times as you like and the forecast will be generated automatically.


Hourly Forecast

Adding hourly intervals to the forecast requires the same group structure, the only difference are the global formulas which have to do more heavy-lifting.

Global Formulas

The number globals that control the forecast change their function:

gv(interval)

min: 1

description: hours between forecasts (1 = every hour, 2 = every 2 hours, etc.) - 24 is daily

gv(offset)

min: 0

description: start of the forecast (0 = now, 1 = 1 hour from now, 2 = 2 hours from now, etc.)

Upgrade these forecast info text globals:

gv(time)

$df(if(tc(split, gv(interval)/24, ".", 1)+0 <= 0, "EEE d", h+if(df(a)="", ":00", " a")),

a+mu(round, mu(floor, gv(index)/24))+d+

mu(round, (gv(index)/24-mu(floor, gv(index)/24))*24)+h)$

gv(cond)

$if(tc(split, gv(interval)/24, ".", 1)+0 <= 0,

wf(cond,

mu(round, mu(floor, (gv(index)+df(H))/24))),

wf(cond,

mu(round, mu(floor, gv(index)/24)),

mu(round, (gv(index)/24-mu(floor, gv(index)/24))*24)))$

gv(wicon)

$if(tc(split, gv(interval)/24, ".", 1)+0 <= 0,

wf(icon,

mu(round, mu(floor, (gv(index)+df(H))/24))),

wf(icon,

mu(round, mu(floor, gv(index)/24)),

mu(round, (gv(index)/24-mu(floor, gv(index)/24))*24))

+

(df(H,

dp(a+mu(round, mu(floor, gv(index)/24))+d+

mu(round, (gv(index)/24-mu(floor, gv(index)/24))*24)+h))

>= df(H, ai(sunrise))

&

df(H,

dp(a+mu(round, mu(floor, gv(index)/24))+d+

mu(round, (gv(index)/24-mu(floor, gv(index)/24))*24)+h))

<= df(H, ai(sunset))))$Returns the equivalent of $wi(icon)+ai(isday)$.

Change based on the weather icon pack.

gv(temp)

$if(tc(split, gv(interval)/24, ".", 1)+0 <= 0,

wf(max,

mu(round, mu(floor, (gv(index)+df(H))/24))),

wf(temp,

mu(round, mu(floor, gv(index)/24)),

mu(round, (gv(index)/24-mu(floor, gv(index)/24))*24)))$

gv(tempmin)

$if(tc(split, gv(interval)/24, ".", 1)+0<=0,

wf(min,

mu(round, mu(floor, (gv(index)+df(H))/24))))$

To hide the minimum temperature (because there's no point in displaying it every hour) use this formula for its color:

$if(tc(split, gv(interval)/24, ".", 1)+0 <= 0, #FFFFFFFF, #00FFFFFF)$


Copyright (c) 2021 Erik Bucik

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

BSD-3-Clause

Kustom formatted version