/wttr-widget

Awesomewm Weather Widget Based on wttr

Primary LanguageLua

Awesomewm Weather Widget Based on wttr

Inspired by The Streetturtle Weather Widget, wttr-widget use wttr under the hood and does not need any API key.

This widget has three modes :

  1. Used in the widget-bar :

    screenshot widget in the widget-bar

  2. Used as a tooltip when mouse enter hover the widget in the widgets-bar :

    screenshot widget in a tooltip

  3. Used in a terminal popup to fetch the forecasts clicking on the widgets :

    screenshot of popup forecasts

Customization

It is possible to customize the widget by providing a table with all or some of the following config parameters :

Name Default Description
location "Oymyakon" See the supported location types
timeout 120 Refresh timeout
format "%c%t/%f+%m" The online output used in the widget-bar. See the One-line output
format_tooltip "%c%C+🌡️%t/%f+💦%p/%h+💨%w+〽%P+%m" The online output used in the tooltip.
font beautiful.font:gsub("%s%d+$", "") .. " 9" The font to use in the widget bar/tooltip
units "m" See the supported units
lang "ru" See the supported languages
terminal "urxvt" The terminal used to see the forecasts

Examples:

local weather_widget = require("wttr-widget.weather")
local wttr = weather_widget({
            location = "ccf",
            lang = "fr",
}),

Installation

  1. Clone this repo under ~/.config/awesome/:

    git clone git@github.com:pivaldi/wttr-widget.git ~/.config/awesome/wttr-widget
  2. Require weather widget at the beginning of rc.lua:

    local weather_widget = require("wttr-widget.weather")
  3. Add widget to the tasklist:

    s.mytasklist, -- Middle widget
        { -- Right widgets
            layout = wibox.layout.fixed.horizontal,
            ...
            weather_widget({
                location = "ccf",
                lang = "fr",
            }),
            ...

Widget placement in one screen only

In order to place a widget only in one monitor, you can use this snippet :

local my_text_font = beautiful.font:gsub("%s%d+$", "") .. " bold 9"
local weather_widget = require("wttr-widget.weather")
local wttr = weather_widget({
            location = "ccf",
            lang = "fr",
            font = my_text_font,
})

…

awful.screen.connect_for_each_screen(function(s)
…
    local weather_wdg = nil
    if s == screen.primary then
      weather_wdg = {
        layout = awful.widget.only_on_screen,
        screen = screen.primary, -- Only display on primary screen
        wttr,
      }
    end

    -- Create the wibox
    s.mywibox = awful.wibar({
        position = "top",
        screen = s,
        bg = beautiful.pi_wibar_bg,
    })

    -- Add widgets to the wibox
    s.mywibox:setup {
      layout = wibox.layout.align.horizontal,
      { -- Left widgets
        layout = wibox.layout.fixed.horizontal,
        …
      },
      s.mytasklist, -- Middle widget
      { -- Right widgets
        layout = wibox.layout.fixed.horizontal,
        …
        weather_wdg,
        …
      },
    }
end
)

Key bindings

It is possible to bind key shortcut with toggling tooltip or opening terminal forecast :

  awful.key({"Mod4",}, "m", wttr.toggle_tooltip,
    {description="show wttr weather tooltip", group="awesome"}),
  awful.key({"Mod4", "Shift"}, "m", wttr.show_forecast,
    {description="show wttr weather forecast", group="awesome"}),