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 http://datapoint.metoffice.gov.uk/public/data/val/wxobs/all/xml/sitelist?key=APIKey

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) http://datapoint.metoffice.gov.uk/public/data/val/wxobs/all/json/3628?res=hourly&key=APIKey

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="<[http://datapoint.metoffice.gov.uk/public/data/val/wxobs/all/json/3628?res=hourly&key=APIKey:3600000:JS(metofficeLatestObsTemp.js)]"}

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

Capture

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

2 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 – http://the.cyclingengineer.co.uk/2015/02/01/max-thermostat-pairing-procedure-protocol-information/

      All the best!
      Paul

Leave a Reply

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