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 }}"
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