Home / i3weather
Name Modified Size InfoDownloads / Week
Parent folder
README.md 2018-12-26 6.7 kB
weather.lua 2018-12-24 361 Bytes
config.ini 2018-12-24 156 Bytes
i3weather 2018-12-24 644.6 kB
Totals: 4 Items   651.8 kB 0

I3Weather

Table of contents

  1. Files needed to run
  2. Setting up the widget
  3. config.ini Setup
  4. The Template
  5. Using with the Awesome Window Manager
  6. Using with I3Blocks
  7. Tools Used

Welcome to the I3 Weather Widget. Like any project this took an unexpected turn as I switched from I3 to the Awesome WM because awesome has better support for floating windows. I wanted this because I was using the Lazarus IDE. Lazarus is a very nice Pascal IDE but it uses separate windows instead of a single window.

During the switch over I found that my new I3 Weather Widget worked with Awesome without making any changes to my Pascal code. This was a bonus.

Files needed to run.

Download the following files

I3Weather : This is the binary compiled for 64 bit X86 Linux. You can get the source from the GIT repository if you need to compile for a different system.

config.ini : This sets up the configuration for the Weather Widget

weather.lua : The Lua code to allow Awesome to interact with the Weather Widget.

Setting up the widget

  1. Copy config.ini and I3Weather to a location where you can run I3Weather. Be sure that I3Weather has execute permissions.
  2. Get an OpenWeather API Key. This can be gotten form OpenWeather. Get the API Key for Current weather and forecasts collections

config.ini Setup

[required]

key= : This is the API key you can get at Open Weather.

location= : This will seem a little strange but what is needed here is the the actual key information you will send to Open Weather. So if you want to send them a zip code your ini file will look like this *location=zip=99999. See https://openweathermap.org/current for other possible queries.

[view]

template= : This is how you describe what you want to see on the widget. I'll explain more about this below.

unit= : This is the units you want the temperature in. there is imperial, kelvin, metric

[network]

runonce= : Normally, the program stays running and updates the information. However if you set runonce to 1 instead of 0 it will terminate after on run.

betweenrequests= : This is how many milliseconds between requests sent to OpenWeather. Keep this large since Open Weather does not like close requests and will lock your account. by default it is 3600000 which is one hour.

betweenretries= : This is how many millisecodes between retries if the program cannot access a network. Once it gets on a network it will switch to using between requests.

The Template

The template loosely follow the JSON returned by Open Weather. I say loosely, because I had to change one of the variables name because the JSON matched to a Pascal reserved word and I broke out an array which only has one value in it any way.

Basically, the template consists of variables which are enclosed in {} and any text you want displayed.

A variable.

String variable

This is an example of a string variable. {Conditions.description} This says that the contents of Conditions.description will be printed

Number variable.

A number variable will look like this. {main.temp,###} This says that main.temp will be printented with up to 3 digits. The ,### is optionaly

For a complete guide to the formatting see https://www.freepascal.org/docs-html/rtl/sysutils/formatfloat.html.

Date/Time variable

This works like a Number variable but has a completely different set of formatting strings. See https://www.freepascal.org/docs-html/current/rtl/sysutils/formatchars.html

Complete example

template={Conditions.description} {main.temp,###}℉

Available variables.

I will list the variables and what type they are (string, number, date/time). Consult https://openweathermap.org/current for complete explanation of what each one means.

coord.lon : number

coord.lat : number

Note: The Conditions correspond to what Open Weather calls weather. I needed to break out the array.

Conditions.id : number

Conditions.main : string

Conditions.description : string

Conditions.icon : string

base : string

main.temp : number

main.pressure : number

main.humidity : number

main.temp_min : number

main.temp_max : number

visibility : number

wind.speed : number

wind.deg : number

wind.gust : number

clouds.all : string

dt : date/time

sys.type : number

sys.id : number

sys.message : string

sys.country : string

sys.sunrise : date/time

sys.sunset : date/time

id : number

name : string

cod : number

Using with the Awesome Window Manager.

In your rc.lua insert the require statement for this widget. The file you are requiring is the weather.lua that you downloaded.

require("weather")

Then add the weatherWidget to your Bar definition.

s.mytasklist, -- Middle widget
{ -- Right widgets
    layout = wibox.layout.fixed.horizontal,
    weatherWidget, 
    wibox.widget.systray(),
    require("battery-widget"){},
    volumecfg.widget,
    mytextclock,
    s.mylayoutbox,
},

Inside of the weather.lua change the weather command to correctly point to the i3 weather executalble and to the correct ini file. You can name the ini file anything you want.

local wibox = require("wibox")
local awful = require("awful")

weatherWidget = wibox.widget.textbox()
weatherWidget.font = "sans 10"

local weatherCommand = "i3weather --ini=/home/brucehaugland/.config/i3blocks/i3weather.ini"

awful.spawn.with_line_callback(weatherCommand, {
stdout = function(line)
    weatherWidget:set_text(" "..line.." ")
end,
})

Using with I3Blocks

This is the entry that you need to make in you i3blocks config file. Point the command to the correct executable and to the correct ini file.

Also note the interval is persist. This is used as long as the runonce flag is 0.

[weather]
command=i3weather --ini=/home/brucehaugland/.config/i3blocks/i3weather.ini
separator=true
interval=persist
markup=pango

Tools Used

Source: README.md, updated 2018-12-26