Sensors to give the hour of min/max temperature from forecast

If you’d like to know when the temperature will be min/max (which hour of the day) and the value, here are four sensors that will get that. This assumes you have the forecast in a sensor called “weather.home_hourly” and that that sensors has an entry for each forecast with attributes ‘temperature’ and ‘datetime’. (I use met.no locally.)

- sensor:
  - name: "Min Forecast Temperature in Next Day"
    unique_id: min_forecast_temperature_in_next_day
    state: >
        {{ state_attr('weather.home_hourly','forecast')[:] | map(attribute='temperature')|min }}
    attributes:
      state_class: measurement
      device_class: temperature
      unit_of_measurement: °C
      icon: mdi:thermometer

- sensor:
  - name: "Min Forecast Temperature Hour in Next Day"
    unique_id: min_forecast_temperature_hour_in_next_day
    state: >
        {% set min_temp = state_attr('weather.home_hourly','forecast')[:] | map(attribute='temperature')|min %}
        {% set min_index = (state_attr('weather.home_hourly','forecast')[:] | map(attribute='temperature')|list).index(min_temp) %}
        {% set coldest_hour = as_timestamp(state_attr('weather.home_hourly','forecast')[min_index]['datetime']) | timestamp_custom("%H") %}
        {{coldest_hour}}
    attributes:
      icon: mdi:hours-24

- sensor:
  - name: "Max Forecast Temperature in Next Day"
    unique_id: max_forecast_temperature_in_next_day
    state: >
        {{ state_attr('weather.home_hourly','forecast')[:] | map(attribute='temperature')|max }}
    attributes:
      state_class: measurement
      device_class: temperature
      unit_of_measurement: °C
      icon: mdi:thermometer

- sensor:
  - name: "Max Forecast Temperature Hour in Next Day"
    unique_id: max_forecast_temperature_hour_in_next_day
    state: >
        {% set max_temp = state_attr('weather.home_hourly','forecast')[:] | map(attribute='temperature')|max %}
        {% set max_index = (state_attr('weather.home_hourly','forecast')[:] | map(attribute='temperature')|list).index(max_temp) %}
        {% set warmest_hour = as_timestamp(state_attr('weather.home_hourly','forecast')[max_index]['datetime']) | timestamp_custom("%H") %}
        {{warmest_hour}}
    attributes:
      icon: mdi:hours-24

2 Likes

Thank you. Just used max temperature part.
Just a small addition met.no entity weather.home_hourly reports forecast for next ~24 hours. So tehcnically it’s not a “Next day” :slight_smile:

I use the following automation to send me a daily message about the weather:-

alias: Todays Temperature
description: ""
trigger:
  - platform: time
    at: "07:30:00"
condition: []
action:
  - device_id: a47f7db07a4a9c7633ac807ab9d13457
    domain: mobile_app
    type: notify
    title: Daily Forecast
    message: >
      Good Morning! The temperature outside is currently
      {{state_attr('weather.forecast_home_hourly','temperature')}} degrees, 
      {%set highof = state_attr('weather.forecast_home_hourly','forecast')
      |       selectattr('datetime', 'search', now().timestamp() |
      timestamp_custom('%Y-%m-%d')) | map(attribute='temperature') | max %} {%
      if highof is defined and highof %} with a high of {{highof}} degrees
      {%endif%} {%set lowof =
      state_attr('weather.forecast_home_hourly','forecast') |   
      selectattr('datetime', 'search', now().timestamp() |
      timestamp_custom('%Y-%m-%d')) | map(attribute='temperature') | min %} {%
      if lowof is defined and lowof %} and a low of {{lowof}}{%endif%}. The
      weather is forecast to be {{states('weather.forecast_home_hourly')}}{% set
      currently_raining = states('weather.forecast_home_hourly') == 'rainy'
      %}{%set check_for_rain =
      state_attr('weather.forecast_home_hourly','forecast') |
      selectattr('datetime', 'search', now().timestamp() |
      timestamp_custom('%Y-%m-%d')) | selectattr('condition','equalto','rainy')
      | list%}{%if not currently_raining%}{% if check_for_rain is defined and
      check_for_rain %} and rainy. {% else %}, with no rain. {%endif%} {%else%}.
      {%endif%} The house is currently
      {{state_attr('climate.main_house','current_temperature')}} degrees.
mode: single
1 Like