OH3 XPath

I’ve been playing around some more with this. Whilst it was fairly intuitive using the UI, I found it quite slow. It is also not so easy to share configurations of the Items (and Links, which would come as a separate JSON) from the UI, so tonight I’ve had a play with using Things and Items files and it was a breeze!

At the moment I’m just playing around with daily forecasts, grabbing the temperature, feels-like temperature, precipitation and weather type for today and the next 4 days.

Things

Replace SITEID and APIKEY

Thing http:url:datapointforecast "Data Point Forecast" [
	baseURL = "http://datapoint.metoffice.gov.uk/public/data/val/wxfcs/all/json/SITEID?res=daily&key=APIKEY",
	refresh = "900",
	ignoreSSLErrors = "true"
]
{
	Channels:
		Type number : forecast_today_temperature_maximum "Forecast Today Temperature Maximum" [
			mode = "READONLY",
			stateTransformation = "JSONPATH:$.SiteRep.DV.Location.Period[0].Rep[0].Dm"
		]
		Type number : forecast_today_temperature_feels_like_maximum "Forecast Today Temperature Maximum" [
			mode = "READONLY",
			stateTransformation = "JSONPATH:$.SiteRep.DV.Location.Period[0].Rep[0].FDm"
		]
		Type number : forecast_today_precipitation "Forecast Today Precipitation" [
			mode = "READONLY",
			stateTransformation = "JSONPATH:$.SiteRep.DV.Location.Period[0].Rep[0].PPd"
		]
		Type string : forecast_today_weather_type "Forecast Today Weather Type" [
			mode = "READONLY",
			stateTransformation = "JSONPATH:$.SiteRep.DV.Location.Period[0].Rep[0].W∩MAP:weathertype.map"
		]
		Type number : forecast_tomorrow_temperature_maximum "Forecast Tomorrow Temperature Maximum" [
			mode = "READONLY",
			stateTransformation = "JSONPATH:$.SiteRep.DV.Location.Period[1].Rep[0].Dm"
		]
		Type number : forecast_tomorrow_temperature_feels_like_maximum "Forecast Tomorrow Temperature Maximum" [
			mode = "READONLY",
			stateTransformation = "JSONPATH:$.SiteRep.DV.Location.Period[1].Rep[0].FDm"
		]
		Type number : forecast_tomorrow_precipitation "Forecast Tomorrow Precipitation" [
			mode = "READONLY",
			stateTransformation = "JSONPATH:$.SiteRep.DV.Location.Period[1].Rep[0].PPd"
		]
		Type string : forecast_tomorrow_weather_type "Forecast Tomorrow Weather Type" [
			mode = "READONLY",
			stateTransformation = "JSONPATH:$.SiteRep.DV.Location.Period[1].Rep[0].W∩MAP:weathertype.map"
		]
		Type number : forecast_day3_temperature_maximum "Forecast Day3 Temperature Maximum" [
			mode = "READONLY",
			stateTransformation = "JSONPATH:$.SiteRep.DV.Location.Period[2].Rep[0].Dm"
		]
		Type number : forecast_day3_temperature_feels_like_maximum "Forecast Day3 Temperature Maximum" [
			mode = "READONLY",
			stateTransformation = "JSONPATH:$.SiteRep.DV.Location.Period[2].Rep[0].FDm"
		]
		Type number : forecast_day3_precipitation "Forecast Day3 Precipitation" [
			mode = "READONLY",
			stateTransformation = "JSONPATH:$.SiteRep.DV.Location.Period[2].Rep[0].PPd"
		]
		Type string : forecast_day3_weather_type "Forecast Day3 Weather Type" [
			mode = "READONLY",
			stateTransformation = "JSONPATH:$.SiteRep.DV.Location.Period[2].Rep[0].W∩MAP:weathertype.map"
		]
		Type number : forecast_day4_temperature_maximum "Forecast Day4 Temperature Maximum" [
			mode = "READONLY",
			stateTransformation = "JSONPATH:$.SiteRep.DV.Location.Period[3].Rep[0].Dm"
		]
		Type number : forecast_day4_temperature_feels_like_maximum "Forecast Day4 Temperature Maximum" [
			mode = "READONLY",
			stateTransformation = "JSONPATH:$.SiteRep.DV.Location.Period[3].Rep[0].FDm"
		]
		Type number : forecast_day4_precipitation "Forecast Day4 Precipitation" [
			mode = "READONLY",
			stateTransformation = "JSONPATH:$.SiteRep.DV.Location.Period[3].Rep[0].PPd"
		]
		Type string : forecast_day4_weather_type "Forecast Day4 Weather Type" [
			mode = "READONLY",
			stateTransformation = "JSONPATH:$.SiteRep.DV.Location.Period[3].Rep[0].W∩MAP:weathertype.map"
		]
		Type number : forecast_day5_temperature_maximum "Forecast Day5 Temperature Maximum" [
			mode = "READONLY",
			stateTransformation = "JSONPATH:$.SiteRep.DV.Location.Period[4].Rep[0].Dm"
		]
		Type number : forecast_day5_temperature_feels_like_maximum "Forecast Day5 Temperature Maximum" [
			mode = "READONLY",
			stateTransformation = "JSONPATH:$.SiteRep.DV.Location.Period[4].Rep[0].FDm"
		]
		Type number : forecast_day5_precipitation "Forecast Day5 Precipitation" [
			mode = "READONLY",
			stateTransformation = "JSONPATH:$.SiteRep.DV.Location.Period[4].Rep[0].PPd"
		]
		Type string : forecast_day5_weather_type "Forecast Day5 Weather Type" [
			mode = "READONLY",
			stateTransformation = "JSONPATH:$.SiteRep.DV.Location.Period[4].Rep[0].W∩MAP:weathertype.map"
		]
}

Items

These include semantic notation. Today’s forecast should appear in your model inside a Met Office equipment, outdoors.

//OUTDOOR GROUP
Group gOutdoor "Outdoor" <outdoor> ["Outdoor"]

//EQUIPMENT
Group gMetOfficeForecast "Met Office Forecast []" <sensor> (gOutdoor) ["Sensor"]

//TODAY
Number nForecastTodayTemperatureMaximum "Maximum Temperature [%d°C]" <temperature> (gMetOfficeForecast) ["Temperature", "Measurement"] { channel="http:url:datapointforecast:forecast_today_temperature_maximum" }
Number nForecastTodayTemperatureFeelsLikeMaximum "Feels like [%d°C]" <temperature> (gMetOfficeForecast) ["Temperature", "Measurement"] { channel="http:url:datapointforecast:forecast_today_temperature_feels_like_maximum" }
Number nForecastTodayPrecipitation "Rain [%d%%]" <rain> (gMetOfficeForecast) ["Rain", "Measurement"] { channel="http:url:datapointforecast:forecast_today_precipitation" }
String strForecastTodayWeatherType "Forecast" <status> (gMetOfficeForecast) ["Status"] { channel="http:url:datapointforecast:forecast_today_weather_type" }

//TOMORROW
Number nForecastTomorrowTemperatureMaximum "Forecast Tomorrow Temperature Maximum [%d°C]" <temperature> (gMetOfficeForecast) { channel="http:url:datapointforecast:forecast_tomorrow_temperature_maximum" }
Number nForecastTomorrowTemperatureFeelsLikeMaximum "Forecast Tomorrow Temperature Feels Like Maximum [%d°C]" <temperature> (gMetOfficeForecast) { channel="http:url:datapointforecast:forecast_tomorrow_temperature_feels_like_maximum" }
Number nForecastTomorrowPrecipitation "Forecast Tomorrow Precipitation [%d%%]" <rain> (gMetOfficeForecast) { channel="http:url:datapointforecast:forecast_tomorrow_precipitation" }
String strForecastTomorrowWeatherType "Forecast Tomorrow Weather Type" <status> (gMetOfficeForecast) { channel="http:url:datapointforecast:forecast_tomorrow_weather_type" }

//DAY3
Number nForecastDay3TemperatureMaximum "Forecast Day3 Temperature Maximum [%d°C]" <temperature> (gMetOfficeForecast) { channel="http:url:datapointforecast:forecast_day3_temperature_maximum" }
Number nForecastDay3TemperatureFeelsLikeMaximum "Forecast Day3 Temperature Feels Like Maximum [%d°C]" <temperature> (gMetOfficeForecast) { channel="http:url:datapointforecast:forecast_day3_temperature_feels_like_maximum" }
Number nForecastDay3Precipitation "Forecast Day3 Precipitation [%d%%]" <rain> (gMetOfficeForecast) { channel="http:url:datapointforecast:forecast_day3_precipitation" }
String strForecastDay3WeatherType "Forecast Day3 Weather Type" <status> (gMetOfficeForecast) { channel="http:url:datapointforecast:forecast_day3_weather_type" }

//DAY4
Number nForecastDay4TemperatureMaximum "Forecast Day4 Temperature Maximum [%d°C]" <temperature> (gMetOfficeForecast) { channel="http:url:datapointforecast:forecast_day4_temperature_maximum" }
Number nForecastDay4TemperatureFeelsLikeMaximum "Forecast Day4 Temperature Feels Like Maximum [%d°C]" <temperature> (gMetOfficeForecast) { channel="http:url:datapointforecast:forecast_day4_temperature_feels_like_maximum" }
Number nForecastDay4Precipitation "Forecast Day4 Precipitation [%d%%]" <rain> (gMetOfficeForecast) { channel="http:url:datapointforecast:forecast_day4_precipitation" }
String strForecastDay4WeatherType "Forecast Day4 Weather Type" <status> (gMetOfficeForecast) { channel="http:url:datapointforecast:forecast_day4_weather_type" }

//DAY5
Number nForecastDay5TemperatureMaximum "Forecast Day5 Temperature Maximum [%d°C]" <temperature> (gMetOfficeForecast) { channel="http:url:datapointforecast:forecast_day5_temperature_maximum" }
Number nForecastDay5TemperatureFeelsLikeMaximum "Forecast Day5 Temperature Feels Like Maximum [%d°C]" <temperature> (gMetOfficeForecast) { channel="http:url:datapointforecast:forecast_day5_temperature_feels_like_maximum" }
Number nForecastDay5Precipitation "Forecast Day5 Precipitation [%d%%]" <rain> (gMetOfficeForecast) { channel="http:url:datapointforecast:forecast_day5_precipitation" }
String strForecastDay5WeatherType "Forecast Day5 Weather Type" <status> (gMetOfficeForecast) { channel="http:url:datapointforecast:forecast_day5_weather_type" }

Transforms

Ensure that the JSONPATH and MAP transforms are installed. I use the MAP transform to convert the weather type number into a description (from page 10 of the DataPoint reference PDF)

Save the below into a new file called weathertype.map into the transform folder.

NA=Not available
0=Clear night
1=Sunny day
2=Partly cloudy (night)
3=Partly cloudy (day)
4=Not used
5=Mist
6=Fog
7=Cloudy
8=Overcast
9=Light rain shower (night)
10=Light rain shower (day)
11=Drizzle
12=Light rain
13=Heavy rain shower (night)
14=Heavy rain shower (day)
15=Heavy rain
16=Sleet shower (night)
17=Sleet shower (day)
18=Sleet
19=Hail shower (night)
20=Hail shower (day)
21=Hail
22=Light snow shower (night)
23=Light snow shower (day)
24=Light snow
25=Heavy snow shower (night)
26=Heavy snow shower (day)
27=Heavy snow
28=Thunder shower (night)
29=Thunder shower (day)
30=Thunder
1 Like