- resource: https://data.hub.api.metoffice.gov.uk/sitespecific/v0/point/hourly?datasource=BD1&includeLocationName=true&latitude=[LATITUDE]&longitude=[LONGITUDE]&excludeParameterMetadata=true
headers:
apikey: "YOUR_LONG_API_KEY"
scan_interval: 3600
sensor:
- name: Datahub Hourly
value_template: "{{ value_json['features'][0]['properties']['modelRunDate'] }}"
json_attributes_path: $.features.0.properties
json_attributes:
- timeSeries
Then you can pull out the nearest “forecast” as the current weather into attributes of a sensor, and one example of pulling out one of those attributes into a sensor state:
template:
- sensor:
- name: Current weather
state: >
{% set tsl = state_attr('sensor.datahub_hourly','timeSeries')|map(attribute='time')|map('as_timestamp')|list %}
{% set ts = tsl|select('>=',(now()-timedelta(minutes=30))|as_timestamp())|first %}
{{ tsl.index(ts) }}
attributes:
status: "{{ state_attr('sensor.datahub_hourly','timeSeries')[this.state|int(0)] }}"
- sensor:
- name: Wind speed
state: "{{ state_attr('sensor.current_weather','status')['windSpeed10m'] }}"
unit_of_measurement: 'm/s'
device_class: wind_speed
attributes:
timestamp: "{{ state_attr('sensor.current_weather','status')['time'] }}"
The state of sensor.current_weather
is the index of the forecast block in the hourly Datahub sensor timeSeries
list that is closest to the current time.
Use this macro to return a description for the significantWeatherCode
:
[click to expand]
{% macro weather_code(x) -%}
{{ {
0: "Clear night",
1: "Sunny day",
2: "Partly cloudy",
3: "Partly cloudy",
4: "Not used",
5: "Mist",
6: "Fog",
7: "Cloudy",
8: "Overcast",
9: "Light rain shower",
10: "Light rain shower",
11: "Drizzle",
12: "Light rain",
13: "Heavy rain shower",
14: "Heavy rain shower",
15: "Heavy rain",
16: "Sleet shower",
17: "Sleet shower",
18: "Sleet",
19: "Hail shower",
20: "Hail shower",
21: "Hail",
22: "Light snow shower",
23: "Light snow shower",
24: "Light snow",
25: "Heavy snow shower",
26: "Heavy snow shower",
27: "Heavy snow",
28: "Thunder shower",
29: "Thunder shower",
30: "Thunder"}.get(x, "n/a") -}}
{% endmacro %}
This doesn’t provide a weather
object, though. Perhaps I need to learn how to create an integration.