Template weather provider from UK Met Office DataHub API

How do I change from the UI showing km for Wind / Visibility when the weather config code shows m/s & m

Click the cog icon on the Weather card:

That just gives me the cannot be changed in UI blurp

This entity (‘weather.met_office_datahub’) does not have a unique ID, therefore its settings cannot be managed from the UI. See the documentation for more detail.

Huh, I must have added that to my config after making this topic.

Add a unique_id: line to the top of your weather file, like this:

- platform: template
  name: "Met Office Datahub"
  unique_id: 884233c7-4b31-4181-bef7-d5562110df5f

It can be anything you like: I use this site: https://www.uuidgenerator.net/

Now to update the original post…

1 Like

Yep that sorted it cheers

1 Like

I’m almost embarrassed to ask this question, as it’s almost certain that I’ve just missed something obvious, but…
Having followed your fantastic guidance in this topic, @Troon, it all looks good for forecast data, but the “local_current_weather” sensor has not been created. What am I missing? Any thoughts would be massively appreciated!

There are a couple of log warnings:

Logger: homeassistant.helpers.template
Source: helpers/template.py:2651
First occurred: 19:21:43 (2 occurrences)
Last logged: 19:21:44
Template variable warning: 'None' has no attribute 'screenTemperature' when rendering '{{ state_attr('sensor.local_current_weather','status')['screenTemperature'] }}'
Logger: homeassistant.components.recorder.db_schema
Source: components/recorder/db_schema.py:625
integration: Recorder (documentation, issues)
First occurred: 19:21:52 (6 occurrences)
Last logged: 20:19:48

State attributes for sensor.local_datahub_hourly exceed maximum size of 16384 bytes. This can cause database performance issues; Attributes will not be stored
State attributes for sensor.local_datahub_3_hourly exceed maximum size of 16384 bytes. This can cause database performance issues; Attributes will not be stored

My template yaml is below (which I think is a direct copy of the original) & resides in my configuration.yaml. I’ve set up separate yaml files for ‘rest’ (named MetOffice-rest.yaml) and ‘weather’ (MetOffice-weather.yaml), again pasted from the original (with the appropriate api key & latitude/longitude), with the following in my configuration.yaml:

rest: !include MetOffice-rest.yaml
weather: !include MetOffice-weather.yaml
template:
  - sensor:
      - name: Local current weather
        state: >
          {% set tsl = state_attr('sensor.local_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.local_datahub_hourly','timeSeries')[this.state|int(0)] }}"
        availability: "{{ states('sensor.local_datahub_hourly') not in ('unavailable', 'unknown') }}"

  - sensor:
      - name: Local weather condition
        state: >
          {% from 'met_office_codes.jinja' import code2ha %}
          {{ code2ha(state_attr('sensor.local_current_weather','status')['significantWeatherCode']) }}
        attributes:
          timestamp: "{{ state_attr('sensor.local_current_weather','status')['time'] }}"
        availability: "{{ states('sensor.local_current_weather') not in ('unavailable', 'unknown') }}"

  - sensor:
      - name: Local wind bearing
        state: >
          {% from 'direction.jinja' import dir %}
          {{ dir(state_attr('sensor.local_current_weather','status')['windDirectionFrom10m']) }}
        attributes:
          timestamp: "{{ state_attr('sensor.local_current_weather','status')['time'] }}"
        availability: "{{ states('sensor.local_current_weather') not in ('unavailable', 'unknown') }}"

Can you check that sensor.local_datahub_hourly works? It should look something like this SettingsDeveloper Tools:

Thx for your reply. Yes it does work.

Panic over. All working now. I had another “template:” statement in my configuration.yaml file. All moved to a separate templates.yaml file and all’s well. YAML syntax strikes again!

1 Like

glad you got it working as I was unable to find any typos in your yaml!

1 Like