I have (had) a template sensor which would show me the upcoming high temperature in the next 24 hours, using the long deprecated and recently removed “daynight” forecast attribute in the NWS integration. Here is my old sensor:
day_max_temp:
friendly_name: "Upcoming high temp"
unique_id: upcoming_temp_unique_id
#unit_of_measurement: "°F"
value_template: >
{% set ns = namespace(tomorrowHigh = -999, goalDay = now().day + 1) %}
{% if now().hour < 12 %}{% set ns.goalDay = now().day %} {% endif %}
{% for fcst in state_attr('weather.kbdn_daynight' , 'forecast')%}
{% set dt = strptime(fcst.datetime, "%Y-%m-%dT%H:%M:%S%z") %}
{% if ns.goalDay == dt.day and fcst.is_daytime %}
{% set ns.tomorrowHigh = fcst.temperature %}
{% endif %}{%- endfor %}
{{ ns.tomorrowHigh | float }}
temperature: 39
temperature_unit: °F
humidity: 75
pressure: 30
pressure_unit: inHg
wind_bearing: 0
wind_speed: 0
wind_speed_unit: mph
visibility: 10
visibility_unit: mi
precipitation_unit: in
attribution: Data from National Weather Service/NOAA
friendly_name: KBDN
supported_features: 6
so nothing that could easily be used to get the same information. I see that there is a _async_forecast_twice_daily() function on the forecast integration itself, but I can’t seem to find any documentation anywhere on how to actually get that information out of my existing weather entity and into the logic to determine the upcoming high. Does anyone know how to do this?
Okay, here’s what I got working. Here’s the hacky workaround to get back to the previously working state of having the forecast data in the “attributes” of something so that it’s usable. in configuration.yaml I added template: !include templates.yaml, and the contents of templates.yaml is as follows: