Metoffice Observations in OpenHAB

The article explains how to access MetOffice Observations in OpenHAB via the JSON API they provide. In the UK the MetOffice offer free weather observations and forecasts via their DataPoint service. This could be used for a variety of rules relating to external weather conditions.

To obtain MetOffice observations in OpenHAB you’ll first neet to get an API key from the MetOffice datapoint service by registering with them.

Once you are registered and logged in grab you API key from the link on the right and you’ll now need to find your site location using a query (just enter it into your browser) such as

You’ll have to manually find your closest site from the list of 140 or so. My nearest site is Filton – so I will use ID 3628.

The MetOffice current supply the last 24 hours of data. To get the last 24 hours of observations we will use a URL such as (replacing 3628 from with your location)

Once you have working URLs you should get a load of JSON data ready to feed into OpenHAB.

First you’ll need to setup your transform. Create a new file in the configurations/transform directory. I called mine metofficeLatestObsTemp.js. Copy the following into it.

var metofficeData = JSON.parse(input)
metofficeData.SiteRep.DV.Location.Period[metofficeData.SiteRep.DV.Location.Period.length-1].Rep[metofficeData.SiteRep.DV.Location.Period[metofficeData.SiteRep.DV.Location.Period.length-1].Rep.length - 1].T

You can replace T with any of the data types listed in the metoffice documentation to get other information such as wind speed, direction, humidity, etc.

Next you’ll need to configure your OpenHAB item. I used the following line:
Number house_heating_externalTemp "External Temperature [%.1f °C]" (persist) { http="<[]"}

You can now add this to your sitemap and display it in the openhab interface.


This entry was posted in Home Automation, Howto and tagged , , , . Bookmark the permalink.

4 Responses to Metoffice Observations in OpenHAB

  1. Robert Delbrück says:

    Hello cyclingengineer,

    You have added the Max CUL Binding to openHAB. I’m missing the shutter contacts. Have you planned to implement this soon? Otherwise i will implement this on my own (extending your implementation and adding this to openHAB main fork)

    Kind regards…

    • cyclingengineer says:

      Hi Robert,

      You found me 😉

      I very limited start on the shutter contact implementation but I haven’t gotten anywhere useful – I have lacked the time and I doubt I’ll have much in the near future. Do have a go if you are able to. I have shutter contacts available to me so I am happy to test and review your contribution to the project.

      Just a note of warning – it seems in general the pairing procedure can be a bit buggy – the devices don’t respond as I would have expected according to the analysis I have done. I have tried to work out why but I don’t have any more info.

      I have posted the protocol analysis I did in relation to the window shutter and also the pairing procedure here –

      All the best!

  2. Adam Brackpool says:

    Trying to pull data from the website and started out by using this as reference

    However, I believe it’s missing a rule to actually go and get the data and ‘transform’ it out? I’ve created all of the config files as stated – and understand how to write the rules to control my things once I have each of the parameters stored as items.

    Can you nudge me in the correct direction for getting the data and updating the items please?

    • cyclingengineer says:

      Given the age of this post (2014) it’s likely their API has changed. Have you looked for relevant updated docs from them?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.