Pebble.Companion.Weather
Platform-provided weather for companion apps.
Weather is supplied by the companion bridge:
- In the IDE debugger, values come from simulator settings. These functions do not take a city name or other query parameters. - On a phone, the bridge fetches live data over HTTP (Open-Meteo) using the device location from geolocation. Apps still do not pass a city name or other query string to current or forecast.
Use current, forecast, and onWeather directly — no separate registration commands.
import Pebble.Companion.Weather as Weather
type Msg
= GotCurrent (Result String Weather.WeatherInfo)
| GotForecast (Result String (List Weather.WeatherInfo))
| GotWeatherPush (Result String Weather.WeatherUpdate)
init _ =
( model, Weather.current GotCurrent )
subscriptions _ =
Weather.onWeather GotWeatherPush
update msg model =
case msg of
GotCurrent (Ok info) ->
( { model | tempC = info.temperatureC }, Cmd.none )
GotCurrent (Err error) ->
( { model | weatherError = Just error }, Cmd.none )
GotForecast _ ->
( model, Cmd.none )
GotWeatherPush (Ok (Weather.Current info)) ->
( { model | tempC = info.temperatureC }, Cmd.none )
GotWeatherPush _ ->
( model, Cmd.none )Types
Condition
type Condition
= Clear
| Cloudy
| Fog
| Drizzle
| Rain
| Snow
| Showers
| Storm
| UnknownWeatherPlatform-normalized weather condition.
WeatherInfo
type alias WeatherInfo =
{ temperatureC : Int
, condition : Condition
, humidityPercent : Maybe Int
, pressureHpa : Maybe Int
, windKph : Maybe Int
}Current or forecast weather values.
WeatherUpdate
type WeatherUpdate
= Current WeatherInfo
| Forecast (List WeatherInfo)A pushed weather update from the companion bridge.
Commands
current
current : (Result String WeatherInfo -> msg) -> Cmd msgRequest the current platform weather snapshot.
Registers bridge handlers needed for weather command responses and push updates.
forecast
forecast : (Result String (List WeatherInfo) -> msg) -> Cmd msgRequest forecast snapshots from the platform weather service.
Registers the bridge handler needed for forecast command responses.
Subscriptions
onWeather
onWeather : (Result String WeatherUpdate -> msg) -> Sub msgReceive pushed weather updates from the companion bridge.
Pair with current (or forecast) in init so the bridge registers interest and can deliver pushed updates. Calling current also sends the bridge subscribe operation for ongoing weather events.
onCurrent
onCurrent : (Result String WeatherInfo -> msg) -> Sub msgReceive current-weather command responses on the dedicated weather port.
Pair with current in init so command responses are routed to this handler.
onForecast
onForecast : (Result String (List WeatherInfo) -> msg) -> Sub msgReceive forecast command responses on the dedicated weather port.
Pair with forecast in init so command responses are routed to this handler.