Weather addons

From Official Kodi Wiki
Jump to navigation Jump to search

addon.xml

Weather addons use the 'xbmc.python.weather' extension point. The basic layout of the addon.xml of a weather addon will look like:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="weather.name" name="My Weather" version="1.2.3" provider-name="me">
	<requires>
		<import addon="xbmc.python" version=""/>
	</requires>
	<extension point="xbmc.python.weather" library=""/>
	<extension point="xbmc.addon.metadata">
		<summary lang="en"></summary>
		<description lang="en"></description>
		<language></language>
		<platform></platform>
		<license></license>
		<forum></forum>
		<website></website>
		<email></email>
		<source></source>
	</extension>
</addon>


Things you need to know!

There's a few things (quirks) you need to be aware of when creating a weather addon...

  • Kodi will automatically run a weather addon when the skins asks to display one of these weather specific infolabels:
  • Weather.Conditions
  • Weather.Temperature
  • Weather.Location
  • Kodi will run the weather addon at a 30 min interval (as long the current skin window displays one of the specific weather infolabels mentioned before)
  • In the weather window, kodi will automatically try to translate all the weather strings
  • Kodi will also handle transformations between units (for instance, Celsius to Fahrenheit, km/h to mph)

How Kodi runs a weather addon

Kodi can run a weather addon in two modes

Setup a weather location in the weather addon settings

In order to set up a weather addon, you need to include a settings.xml file for your weather addon. It needs to have this structure:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<settings>
	<category>
		<setting id="Location1" label="Location 1" type="action" action="RunScript($ID,Loc1)" default=""/>
		<setting id="Location2" label="Location 2" type="action" action="RunScript($ID,Loc2)" enable="!eq(-1,)" default=""/>
		<setting id="Location3" label="Location 3" type="action" action="RunScript($ID,Loc3)" enable="!eq(-1,)" default=""/>
		<setting id="Location4" label="Location 4" type="action" action="RunScript($ID,Loc4)" enable="!eq(-1,)" default=""/>
		<setting id="Location5" label="Location 5" type="action" action="RunScript($ID,Loc5)" enable="!eq(-1,)" default=""/>
	</category>
</settings>

You can define as much weather locations as you want in your settings.xml file.

When you're going to set up a location in the weather addon settings, Kodi will pass the argument you've defined in the RunScript() action above to your addon. For instance, if you select to 'Location 2' setting, Kodi will pass 'Loc2' to your addon.


Retrieve weather for a location

When weather information needs to be retrieved, Kodi will pass the location number to your addon. For instance, if the weather for Location 4 is requested, Kodi will pass '4' to the weather addon.


Info a weather addon needs to return

When a weather addon is asked to retrieve weather information it needs to return this info to Kodi. This is done by making the various pieces of information available as window properties of the weather window.

The basic python code needed to provide a window property:

WINDOW = xbmcgui.Window(12600)
WINDOW.setProperty(name, value)

Kodi expects a weather addon to return these properties:

  • Current.Condition (the weather forecast)
  • Current.Temperature (temperature in degrees celcius)
  • Current.Wind (windspeed in km/h)
  • Current.WindDirection (wind direction, NNE)
  • Current.Humidity (humidity in %)
  • Current.FeelsLike (feels-like temperature in degrees celcius)
  • Current.UVIndex (the uv-index)
  • Current.DewPoint (dewpoint in degrees celcius)
  • Current.OutlookIcon (weather icon, 34.png)
  • Current.FanartCode (condition code, 34)
  • Day%i.Title (name of the day)
  • Day%i.HighTemp (high temp of the day in degrees celcius)
  • Day%i.LowTemp (low temp of the day in degrees celcius)
  • Day%i.Outlook (the weather forecast)
  • Day%i.OutlookIcon (weather icon, 18.png)
  • Day%i.FanartCode (condition code, 18)

Kodi will read those window properties, do unit conversions if needed and make them available to the skin as infolabels.


The name of the window property and the resulting infolabel will differ in a few occasions:

  • Current.OutlookIcon (property) -> Current.ConditionIcon (infolabel)
  • Current.Wind (property) -> Current.WindSpeed (infolabel)
  • Current.Wind / Current.WindDirection (property) -> Current.Wind (infolabel)

Kodi combines the Wind and WindDirection into a Wind infolabel with this format: 'From <wind dir> at <speed> <unit>'


Finally, at the end of your script, you need to set the following window properties:

  • Location%i (the name of each weather location that has been configured by the user. don't include the empty ones!)
  • Locations (the total number of lactions that have been set up by the user)

Advanced weather info (optional)

Besides the weather infolabels mentioned above, your addon can return many more, basically there are no limits. Keep in mind though, that it requires skin support to display this additional information in Kodi.

If you want to go this route, have a look at the infolabels provided by the Openweathermap and Wunderground addons
https://github.com/xbmc/repo-scripts/blob/krypton/weather.openweathermap.extended/README.txt
https://github.com/xbmc/repo-scripts/blob/jarvis/weather.wunderground/README.txt

The infolabels provided by those addon are reasonably well supported by a number of skins already, so try if you can use the same infolabel names in your addon.


Weather Codes

Kodi ships with an icon pack that includes an icon for each weather condition.
(https://github.com/xbmc/xbmc/tree/master/addons/resource.images.weathericons.default)
Several additional weather icon packs are available through the official Kodi repository.

The following condition-code table is used for the icon names:

0 	tornado
1 	tropical storm
2 	hurricane
3 	severe thunderstorms
4 	thunderstorms
5 	mixed rain and snow
6 	mixed rain and sleet
7 	mixed snow and sleet
8 	freezing drizzle
9 	drizzle
10 	freezing rain
11 	showers
12 	showers
13 	snow flurries
14 	light snow showers
15 	blowing snow
16 	snow
17 	hail
18 	sleet
19 	dust
20 	foggy
21 	haze
22 	smoky
23 	blustery
24 	windy
25 	cold
26 	cloudy
27 	mostly cloudy (night)
28 	mostly cloudy (day)
29 	partly cloudy (night)
30 	partly cloudy (day)
31 	clear (night)
32 	sunny
33 	fair (night)
34 	fair (day)
35 	mixed rain and hail
36 	hot
37 	isolated thunderstorms
38 	scattered thunderstorms
39 	scattered thunderstorms
40 	scattered showers
41 	heavy snow
42 	scattered snow showers
43 	heavy snow
44 	partly cloudy
45 	thundershowers
46 	snow showers
47 	isolated thundershowers
na 	not available