Weather addons

From Official Kodi Wiki
Jump to: navigation, search

Contents

1 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>


2 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)

3 How Kodi runs a weather addon

Kodi can run a weather addon in two modes:

3.1 To 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 the 'Location 2' setting, Kodi will pass 'Loc2' to your addon.

3.2 To 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.


4 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 and do unit conversions if needed, depending on the regional settings in Kodi.


The name of the window property set by the weather addon and the resulting window property for the skin will differ in a few occasions:

* Current.OutlookIcon (addon) -> Current.ConditionIcon (skin)
* Current.Wind (addon) -> Current.WindSpeed (skin)
* Current.Wind / Current.WindDirection (addon) -> Current.Wind (skin)

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

In addition, several window properties set by the addon, will be made available to the skin as infolabels:

* Current.Condition (addon) -> Weather.Conditions (skin)
* Current.Temperature (addon) -> Weather.Temperature (skin)
* Current.FanartCode (addon) -> Weather.FanartCode (skin)

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. for locations that are not configured, set an empty property.)
* Locations (the total number of locations that have been set up by the user. don't count the ones that have not been configured!)

Once the addon has finished, Kodi will make one additional infolabel available to the skin:

* Weather.Location (the name of the current weather location)

The name of the weather addon, can be displayed by the skin using:

* Weather.Plugin (the name of the weather addon)

5 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:

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


6 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
Personal tools
Namespaces

Variants
Actions
Navigation
Wiki help
Toolbox