Sept 2023 Ha announced that the use of weather attributes will be depreciated in March of 2024 I did not have time to fix this issue until now.
Weather forecast service
If you use the old way of using the weather attributes in a template they would no longer work.
OLD WAY
- obj: "p5b51" # Forecast time +8h
properties:
"text": >
{%- if not is_state('weather.barb_s_place_hourly','unavailable') %}
{%- set update = states('sensor.date') %}
{%- set midnight = now().replace(hour=0, minute=0, second=0, microsecond=0).timestamp() %}
{%- set event = as_timestamp(strptime(state_attr('weather.barb_s_place_hourly','forecast')[8]['datetime'], '%Y-%m-%dT%H:%M:%S%z', default='2020-01-00T00:00:00+00:00')) %}
{%- set delta = ((event - midnight) // 86400) | int %}
{%- if delta == 0 %}
Today
{%- elif delta == 1 %}
Tomorrow
{%- endif %}
{{- event | timestamp_custom(" %-I %p") }}
{%- endif %}
- obj: "p5b52" # Forecast temp +8h
properties:
"text": "{{ state_attr('weather.barb_s_place_hourly','forecast')[8]['temperature'] if not is_state('weather.barb_s_place_hourly','unavailable') else '-' }}"
- obj: "p5b53" # Forecast condition +8h
properties:
"src": >
{%- if not is_state('weather.barb_s_place_hourly','unavailable') %}
L:/w-32-{{ state_attr('weather.barb_s_place_hourly','forecast')[8]['condition'] }}.png
{%- endif %}
Solution:
Create a Hourly weather sensor. sensor.weather_hourly
useing the service: weather.get_forecasts
This does not work for accuweather I needed to use the Meteorologisk institutt (Met.no) integration.
Just for less confusion I created a new weather service called home forecast
then created new sensor sensor.weather_hourly
in my template.yaml
hourly forecast sensor
#weather forcast hourly sensor
- trigger:
- platform: time_pattern
minutes: /1
- platform: homeassistant
event: start
action:
- service: weather.get_forecasts
data:
type: hourly
target:
entity_id: weather.home
response_variable: hourly
sensor:
- name: Weather Hourly
state: "{{ states('weather.home') }}"
attributes:
temperature: "{{ state_attr('weather.home', 'temperature') }}"
dew_point: "{{ state_attr('weather.home', 'dew_point') }}"
temperature_unit: "{{ state_attr('weather.home', 'temperature_unit') }}"
humidity: "{{ state_attr('weather.home', 'humidity') }}"
cloud_coverage: "{{ state_attr('weather.home', 'cloud_coverage') }}"
pressure: "{{ state_attr('weather.home', 'pressure') }}"
pressure_unit: "{{ state_attr('weather.home', 'pressure_unit') }}"
wind_bearing: "{{ state_attr('weather.home', 'wind_bearing') }}"
wind_speed: "{{ state_attr('weather.home', 'wind_speed') }}"
wind_speed_unit: "{{ state_attr('weather.home', 'wind_speed_unit') }}"
visibility_unit: "{{ state_attr('weather.home', 'visibility_unit') }}"
precipitation_unit: "{{ state_attr('weather.home', 'precipitation_unit') }}"
forecast: "{{ hourly['weather.home'].forecast }}"
Here is another one using the National weather service integration twice daily.
For testing I recommend changing the
- platform: time_pattern
hours: /1
to minutes or seconds so you don’t have to wait for data update then change back to at 1 hour or more
Below has been edited for USE with the National weather service forecast
action:
- service: nws.get_forecasts_extra
from
action:
- service: weather.get_forecasts
#My templet for weather forecast
#national weather service
- trigger:
- platform: time_pattern
hours: /1
action:
- service: nws.get_forecasts_extra
data:
type: twice_daily
target:
entity_id: weather.pg425
response_variable: twice_daily
- variables:
nextday: "{{ twice_daily['weather.pg425'].forecast[2] }}"
day: "{{ twice_daily['weather.pg425'].forecast[0] }}"
evening: "{{ twice_daily['weather.pg425'].forecast[1] }}"
sensor:
- name: "Forcast next morning Details NWS"
unique_id: next_morningdetailed_descriptions
state: "{{ nextday.detailed_description }}"
- name: "Forcast TODAY Details NWS"
unique_id: morningdetailed_descriptions2
state: "{{ day.detailed_description }}"
- name: "Forcast evening Details NWS"
unique_id: eveningdetailed_descriptions2
state: "{{ evening.detailed_description }}"
- name: "Forcast Eve temperature NWS"
unique_id: eveningtempNWS
state: "{{ evening.temperature }}"
- name: "Forcast today's temperature NWS"
unique_id: todaytempNWS
state: "{{ day.temperature }}"
- name: "Forcast Today chance of rain NWS"
unique_id: todaychanceofrain
state: "{{ day.precipitation_probability }}"
- name: "Forcast Evening chance of rain NWS"
unique_id: eveningchanceofrain
state: "{{ evening.precipitation_probability }}"
- name: "Forcast Today condition NWS"
unique_id: todaycondition
state: "{{ day.condition }}"
- name: "Forcast Evening condition NWS"
unique_id: eveningcondition
state: "{{ evening.condition }}"
- name: "Forcast Today wind_speed NWS"
unique_id: todaywind_speed
state: "{{ day.wind_speed }}"
- name: "Forcast Evening wind_speed NWS"
unique_id: eveningwind_speed
state: "{{ evening.wind_speed }}"
New yaml for plates for my openhasp +8 hour data to be displayed. Basicly replace all weather.barb_s_place_hourly'
with sensor.weather_hourly
yaml
- obj: "p5b51" # Forecast time +8h
properties:
"text": >
{%- if not is_state('sensor.weather_hourly','unavailable') %}
{%- set update = states('sensor.date') %}
{%- set midnight = now().replace(hour=0, minute=0, second=0, microsecond=0).timestamp() %}
{%- set event = as_timestamp(strptime(state_attr('sensor.weather_hourly','forecast')[8]['datetime'], '%Y-%m-%dT%H:%M:%S%z', default='2020-01-00T00:00:00+00:00')) %}
{%- set delta = ((event - midnight) // 86400) | int %}
{%- if delta == 0 %}
Today
{%- elif delta == 1 %}
Tomorrow
{%- endif %}
{{- event | timestamp_custom(" %-I %p") }}
{%- endif %}
- obj: "p5b52" # Forecast temp +8h
properties:
"text": "{{ state_attr('sensor.weather_hourly','forecast')[8]['temperature'] if not is_state('sensor.weather_hourly','unavailable') else '-' }}"
- obj: "p5b53" # Forecast condition +8h
properties:
"src": >
{%- if not is_state('sensor.weather_hourly','unavailable') %}
L:/w-32-{{ state_attr('sensor.weather_hourly','forecast')[8]['condition'] }}.png
{%- endif %}
For more on my personal openhasp project.
Home assistant Forums Openhasp on a Lanbon L8 and WT32-SC01 Plus
Gethub openhasp-
sources
Weather forecast service
HA dev Weather forecasts
Unsure How To Use Hourly Forecast Information (Since 2024.3.0) #112628