Maximum temperature of Met.no

Thank you so much for posting this. It’s the only one of all the code snippets in the multitude of threads about this issue that A) still works and 2) gives me the high for today, not the high for tomorrow or the high in the next 24 hours.

hi all,

looking ot get this working too. (to check on my cell phone what the actual temperaturen outside is and what it will be at the warmes point of the day - so I know what to wear :slight_smile: )

unfortunately this doesn’t work with me ?

I copied the code above in my configuration.yaml , but changed the name (since the met.no forecast sits in weather.forecast_thuis .

template:
  - trigger:
      - platform: state
        entity_id: weather.forecast_thuis
    action:
      - variables:
          w: weather.forecast_thuis
      - service: weather.get_forecasts
        data:
          type: daily
        target:
          entity_id: '{{ w }}'
        response_variable: r
    sensor:
      - name: 'Temperature Max'
        unique_id: 'temperature_max'
        unit_of_measurement: '°C'
        device_class: temperature
        state: "{{ r[w].forecast[0].temperature }}"

the template sensor (don’t know if I call it like that?) shows up between my entities:

but the values stays empty :frowning:
every help is appreciated

Sorry @123 but I’m having the same issue.

Can I not just paste the code in the TEMPLATE EDITOR and it should run?

template:
  - trigger:
      - platform: state
        entity_id: weather.home
    action:
      - variables:
          w: weather.home
      - service: weather.get_forecasts
        data:
          type: daily
        target:
          entity_id: '{{ w }}'
        response_variable: r
    sensor:
      - name: 'Temperature Max'
        unique_id: 'temperature_max'
        unit_of_measurement: '°C'
        device_class: temperature
        state: "{{ r[w].forecast[0].temperature }}"

I get ‘r’ is undefined. Just pasted the example.

No.

The Template Editor is ised to test templates, not entire blocks of YAML. The Template Editor doesn’t process YAML.

I’m confused, where does this code go? Tried config.yml, template.yml, new automation.

The example is designed to be placed in the configuration.yaml file.

You may wish to review the documentation for the Template integration, specifically the section for YAML configuration.

If your configuration.yaml file contains something like this:

template: !include template.yaml

Then it means you have configured it to store Template entities in a separate file named template.yaml. In that case, the first line of the example containing the word template: should not be copy-pasted into the template.yaml file.

Okay, here is a snippet from my config.yml

Not sure what I’m doing wrong.

All I’m trying to do is the high and low forecast temp for the day. Maybe I’m going about this all wrong.

You’re using the Visual Studio Code add-on which includes Config Helper which adds validation features specific to Home Assistant.

One of those validation features is to identify invalid YAML syntax (as used specifically by Home Assistant). In the screenshot you posted, it is complaining about the use of platform: and service: in the example’s configuration.

It’s an old example (over a year old). It predates Home Assistant’s change from using the word platform: to trigger: and from the word service: to action:. In addition, the word trigger: was changed to its plural form triggers:.

The updated version looks like this:

template:
  - triggers:
      - trigger: state
        entity_id: weather.home
    action:
      - variables:
          w: weather.home
      - action: weather.get_forecasts
        data:
          type: daily
        target:
          entity_id: '{{ w }}'
        response_variable: r
    sensor:
      - name: 'Temperature Max'
        unique_id: 'temperature_max'
        unit_of_measurement: '°C'
        device_class: temperature
        state: "{{ r[w].forecast[0].temperature }}"

NOTE

Home Assistant still supports the use of platform: and service: so it’s not absolutely necessary to update old examples. It’s only Config Helper, in Visual Studio Code, that identifies them as being problematic. However, if want to eliminate those red warning messages in Visual Studio Code then you’ll need to update the example.

1 Like

You are amazing!! I will give that a try and let you know how it goes.

Okay, so now it’s working. Weird. Here is my code. Maybe I didn’t wait long enough for the update. Tks!

ttemplate:
  - trigger:
      - trigger: state
        entity_id: weather.forecast_home
    action:
      - variables:
          w: weather.forecast_home
      - action: weather.get_forecasts
        data:
          type: daily
        target:
          entity_id: "{{ w }}"
        response_variable: r
    sensor:
      - name: "Temperature Max"
        unique_id: "temperature_max"
        unit_of_measurement: "°F"
        device_class: temperature
        state: "{{ r[w].forecast[0].temperature }}"