Maximum temperature of Met.no

I would like to create my own sensor that retrieves the maximum temperature from met.no. My weather entity is called weather.home.

Are there any code examples, etc. for this?

Thank you very much!

Yes there’s plenty of examples, have you tried searching?

Yes, I’ve seen that too:

These codes always just don’t work; there are always errors.

It would be very helpful if you showed your code and where you are stuck (what errors?).

If I try to take this code here:

{{ (state_attr('weather.zuhause', 'forecast')|selectattr('datetime', 'lt', (now().replace(hour=23,minute=59)).isoformat()))| map(attribute='temperature') | list | max }}

which has also been marked as a solution, I always get this error:

No aggregated item, sequence was empty.

Read the release notes, forecast in the weather sensor has been deprecated, multiple posts explain how to create a workaround template sensor

The code below is for finding max wind speed the next days. You can use it as an example of how to find max temperature.

template:
    - trigger:
        - platform: state
          entity_id: weather.orstad_utsyn
      action:
        - service: weather.get_forecasts
          data:
            type: daily
          target:
            entity_id: weather.orstad_utsyn
          response_variable: wd
      sensor:
        - unique_id: vindstyrke_i_morgen
          name: "Vindstyrke i morgen"
          unit_of_measurement: "m/s"
          state: "{{ [state_attr('weather.orstad_utsyn', 'wind_gust_speed')|float(0), (wd['weather.orstad_utsyn'].forecast | rejectattr('wind_gust_speed', 'undefined') | map(attribute='wind_gust_speed')|list|max)]|max|round(1) }}"

The following example reports the maximum temperature in an hourly weather forecast. If you want the maximum temperature for a daily forecast, replace the value hourly with daily.

template:
  - trigger:
      - platform: time_pattern
        hours: /1
      - platform: event
        event_type: event_template_reloaded
    action:
      - variables:
          w: weather.home
      - service: weather.get_forecasts
        data:
          type: hourly
        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 | map(attribute='temperature')
            | reject('string') | max }}

UndefinedError: 'r' is undefined

This error always appears for me.

You made a mistake somewhere because the example I posted works without any errors for me.

Compare your version to my example. Start by confirming this line:

response_variable: r

:tada:

Thank you!

I don’t know what I did wrong earlier…
Now it works!
Thank you!

1 Like

this works perfectly for me. But i would like to get the max temperature of the current day. In that case i would use type = daily. But how i can write the first and not the max temperature in temperature_max?

Edit: I found the answer in a post from you here: How to migrate from weather integration approach to new weather.get_forecast service? - #13 by 123
Thank you anyway