It’s been windy in the UK over the last few days!
The Met Office issues Weather Warnings (Yellow, Amber, Red) for events which are likely to cause disruption. I had assumed that I could get this data using the new Weather DataHub, but not so.
Instead, it’s trusty RSS feeds linked from this page.
To get this data into OpenHAB:
- Install the Feed Binding
- Create a new Feed Thing, with the URL pointing to the relevant regional feed that you’re interested in.
- Link Items to the Thing Channels
You will now have Items which contain the last issued Weather Warning.
Example
I am subscribed to the North East feed.
Thing
UID: feed:feed:MetOfficeWeatherWarning
label: Met Office Weather Warning
thingTypeUID: feed:feed
configuration:
refresh: 20
URL: https://www.metoffice.gov.uk/public/data/PWSCache/WarningsRSS/Region/ne
Channels are automatically created by this binding. You can create linked Items quickly by using the Add Equipment To Model from the Channel tab of the above Thing.
I then trigger a rule if the LatestDescription Item changes, sending the description and link URL to a Matrix room, and the colour of the weather warning (or BLACK if there is none) to an Item called MetOfficeWeatherWarning_Colour
:
Rule
configuration: {}
triggers:
- id: "1"
configuration:
itemName: MetOfficeWeatherWarning_LatestDescription
type: core.ItemStateChangeTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/javascript
script: >
var colour, description, link, i;
var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
colour = 'BLACK';
description = itemRegistry.getItem('MetOfficeWeatherWarning_LatestDescription').getState();
link = itemRegistry.getItem('MetOfficeWeatherWarning_LatestLink').getState();
description += '';
var i_list = ['YELLOW', 'AMBER', 'RED'];
for (var i_index in i_list) {
i = i_list[i_index];
if (description.toUpperCase().indexOf(i) + 1 != 0) {
colour = i;
}
}
logger.error(colour);
events.sendCommand('MetOfficeWeatherWarning_Colour', colour);
if (description != 'UNDEF') {
events.sendCommand('strMatrixMessageHomeRoom', description);
} else {
events.sendCommand('strMatrixMessageHomeRoom', 'Weather warning cleared.');
}
if (link != 'UNDEF') {
events.sendCommand('strMatrixMessageHomeRoom', link);
}
type: script.ScriptAction