HA Forecast

As stated in the previous post of this series, the notification is missing one thing: taking the forecast into account. This feature would be good because if the weather is dropping down to 52F during the night I do not want to be opening the windows. My current solution is to double the weather on my phone, but it would be nice to have this automated.

Problem

The National Weather Service Integration doesn’t actually have an assessable forecast entity, but the lovelace card shows it so I know the data is there.

My first step is checking the states in the Developer Tools section. This is what I see for the weather.kmop_daynight entity:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
temperature: 76
temperature_unit: °F
humidity: 53
# etc..
forecast:
  - detailed_description: Partly sunny, with a high near 80. East southeast wind around 10 mph.
    datetime: '2023-08-05T12:00:00-04:00'
    daytime: true
    condition: cloudy
    precipitation_probability: 0
    wind_bearing: 112.5
    temperature: 80
    wind_speed: 10
  - detailed_description: Partly cloudy, with a low around 57. East northeast wind 5 to 10 mph.
    datetime: '2023-08-05T18:00:00-04:00'
    daytime: false
    condition: partlycloudy
    precipitation_probability: 0
    wind_bearing: 67.5
    temperature: 57
    wind_speed: 7.5
  # etc..

Playing around with the template section in the Developer Tools section I have come up with this, {{ state_attr("weather.kmop_daynight", "forecast") }}, which has the output of:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[
  {
    'detailed_description': 'Partly sunny, with a high near 80. East southeast wind around 10 mph.',
    'datetime': '2023-08-05T13:00:00-04:00',
    'daytime': True,
    'condition': 'cloudy',
    'precipitation_probability': 0,
    'wind_bearing': 112.5,
    'temperature': 80,
    'wind_speed': 10.0
  },
  {
    'detailed_description': 'Partly cloudy, with a low around 57. East northeast wind 5 to 10 mph.',
    'datetime': '2023-08-05T18:00:00-04:00',
    'daytime': False,
    'condition': 'partlycloudy',
    'precipitation_probability': 0,
    'wind_bearing': 67.5,
    'temperature': 57,
    'wind_speed': 7.5
  },
  # etc
]

From what I can see with this output is that

  • daynight is to determine if it’s a Night forecast
  • The future items are at 6AM and 6PM.
  • The first item seems to be closer to the current time’s forecast and not 6AM/PM

The Entity

Note: See the edited and final version at the bottom of this post

My first idea is this {{ state_attr("weather.kmop_daynight", "forecast").1.temperature }}, Which would be the simplest way of accomplishing what I want.

Path: configuration.yaml
1
2
3
4
5
6
7
8
sensor:
 - platform: template
   sensors:
      forecast_temperature_template:
        friendly_name: "Next Temperature Forecast"
        unit_of_measurement: '°F'
        value_template: >- 
          {{ state_attr("weather.kmop_daynight", "forecast").1.temperature }}  

A quick reload later and the entity exists!

Main Automation Change

I’ve added a new condition for the Main Automation created in the previous post

Condition, Numerical State

  • Entity: sensor.forecast_temperature_template
  • Above:
    • Fixed Number
    • 62
  • Below: blank
Updated Raw YAML in Another Main Automation Change

The Updated Entity

When the clock hits 6PM the next forecast element is the next day’s 6AM, This will not work because the next day’s 6AM isn’t the projected temp at 6AM, but the high for that day.

This is the updated version that picks the different forecasts depending on the day; 18 being 6PM in 24-hour time

Path: configuration.yaml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
sensor:
 - platform: template
   sensors:
      forecast_temperature_template:
        friendly_name: "Next Temperature Forecast"
        unit_of_measurement: '°F'
        value_template: >- 
          {% if now().hour >= 18 -%}
            {{ state_attr("weather.kmop_daynight", "forecast").0.temperature }}
          {%- else -%}
            {{ state_attr("weather.kmop_daynight", "forecast").1.temperature }}
          {%- endif %}

Another Main Automation Change

After real world use, and weirdly cold nights in Michigan, I’ve noticed the behavior that the National Weather Service isn’t reliably updating the forecast at 6pm. Instead of adding more complexity to the forecast_temperature_template entity, I will skip the 6PM check.

To do this I will replace the Time Pattern trigger with hardcoded times and the Time trigger, This will also remove the 4:30pm-11:59pm time condition. I was avoiding this because it would be a lot of fields to enter, but I’m going to write it in YAML

Trigger: Time

  • click 3 dots + Edit in YAML
  • Paste contents of code block
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
platform: time
at:
  - "16:30:00"
  - "16:40:00"
  - "16:50:00"
  - "17:00:00"
  - "17:10:00"
  - "17:20:00"
  - "17:30:00"
  - "17:40:00"
  - "17:50:00"
  - "18:10:00"
  - "18:20:00"
  - "18:30:00"
  - "18:40:00"
  - "18:50:00"
  - "19:00:00"
  - "19:10:00"
  - "19:20:00"
  - "19:30:00"
  - "19:40:00"
  - "19:50:00"
  - "20:00:00"
  - "20:10:00"
  - "20:20:00"
  - "20:30:00"
  - "20:40:00"
  - "20:50:00"
  - "21:00:00"
  - "21:10:00"
  - "21:20:00"
  - "21:30:00"
  - "21:40:00"
  - "21:50:00"
  - "22:00:00"
  - "22:10:00"
  - "22:20:00"
  - "22:30:00"
  - "22:40:00"
  - "22:50:00"
  - "23:00:00"
  - "23:10:00"
  - "23:20:00"
  - "23:30:00"
  - "23:40:00"
  - "23:50:00"
Updated Raw YAML
Series:
ha-temperature
Post:
2/2
comments powered by Disqus