Homeassistant 12h local weather forecast. ~94% accurate*

How did you compare, e.g I find it quite hard to compare 50% chance of rain…either way this is correct :roll_eyes:

EDIT (now 19.5) it is raining slightly and heavily clouded, the ‘regular’ forecast shows that but below it is different. Yesterday I had reverse info…aargh.
image
image

The rain probabilities of the forecast are just estimated by me by analysing the text forecast. This is also where the changes for the tweaked version V1.1 happened. For now the most accurate should be the text forecast. (the first sunny is also just the state of the pressure and doesnt represent the current condition!

The forecast is also pretty depandant on wind direction do have set this up? This could explain the settled fine. This sould mean like rain is just over. For me this is only there when there is no wind!
For me these short term forecasts also nearly never match with reality.
For me today the V1.1 with wind data matches exactly reality!
It is cloudy and getting better. The forecast says:grafik

If you want to tweak the icons and rain percentage you can look here in the code:

As you can see the chance of rain beening 50% is only on one specific condition with the latest version!

I also now use my own ecowitt integration to get even better data locally you can look here if you are interested:

OK, will try v1.1 later today.
The wind direction is from meteofrance.
With curren 0.2, the card changed a bit unexpected … times moved about 2.5h backwards in time
Note that I am only providing the info so you know, not to ask for improvements (only if you know how)
image

ok thats strange. I actually don’t know how this can even happen. Maybe a reboot of HA fixes it :thinking:

Still checking and for now ‘your’ sensor is more wrong then right, sadly…not saying the regular ones are better.

A few times forecast_short_term was not good, I have 1026 now and this leads to “sunny” where it is raining quite a lot. I think I will remove this one as it also has no added value, I can SEE current condition :slight_smile:

I will continue comparing

Found an error in row 85: this needs to be 1020 and not 120

            {% elif p0>=120 and p0<1040 %}

Q on p0… I am at 127m above sea level and 6km from the coast. At the start, being not sea-level I set this to 0 … if I set it to 1 then it will take my local pressure which is more in line to what I see. …will recommence testing

Just as information for other. The “short term forecast” is more a general weather condition. So high pressure area or low pressure area. For me the forecast still works…

My weather sensors produce pressure readings in inches of mercury, temperature in degrees Fahrenheit, and wind speed in miles per hour. What changes should I make in the code to accommodate? Thanks.

Perhaps changing your unit system in general settings

Had this working for 5 days, nothing happens to the card.
Please make a screencast how to set it up correctly.

Hi all,

I 've tried integrate this forecast. I found in your code this comments

# The sampling_size values should add up to slightly less than the amount of sensor updates in the max_age time to work around Home Assistant's statistics integration
# e.g. a pressure sensor that updates every ~5 seconds in 180 minutes is 2160 updates, -12.5%, gives 1890 samples

I’m combine two temp value to one it means( netatmo outdoor temp (15min update) and aqara temp(5min) , pressure is taken from aqara(5min)

I 'm getting error in log regarding temp was unvailable or pressure

I think errors are from UI but it has depends on backend because in this time was short temp and some forecast null

Logger: homeassistant.helpers.event
Zdroj: helpers/template.py:633
Prvýkrát sa vyskytol: 28. decembra 2024 o 14:24:07 (732 výskytov)
Naposledy prihlásený: 19:50:34

Error while processing template: Template<template=(- {%if states.sensor.local_forecast.attributes.forecast_temp_short[1] >= 0%}{{states.sensor.local_forecast.attributes.temperature}}°C{%endif%}) renders=2522>
Error while processing template: Template<template=({{states.sensor.local_forecast_neg_zam_detail.attributes.icons[0]}}) renders=2134>
Error while processing template: Template<template=(Rain: {{states.sensor.local_forecast_neg_zam_detail.attributes.rain_prob[0]}}% {%if states.sensor.local_forecast.attributes.forecast_temp_short[1] == 0%}{{states.sensor.local_forecast.attributes.forecast_temp_short[0]}}°C{%endif%}) renders=2382>
Error while processing template: Template<template=({{states.sensor.local_forecast_neg_zam_detail.attributes.icons[1]}}) renders=2134>
Error while processing template: Template<template=(Rain: {{states.sensor.local_forecast_neg_zam_detail.attributes.rain_prob[1]}}% {%if states.sensor.local_forecast.attributes.forecast_temp_short[1] == 1%}{{states.sensor.local_forecast.attributes.forecast_temp_short[0]}}°C{%endif%}) renders=2382>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 631, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2733, in _render_with_context
    return template.render(**kwargs)
           ~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/site-packages/jinja2/environment.py", line 939, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 4, in top-level template code
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2352, in forgiving_float_filter
    return float(value)
jinja2.exceptions.UndefinedError: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'temperature'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 748, in async_render_to_info
    render_info._result = self.async_render(  # noqa: SLF001
                          ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
        variables, strict=strict, log_fn=log_fn, **kwargs
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 633, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'temperature'

Logger: homeassistant.components.template.template_entity
Zdroj: components/template/template_entity.py:203
Integrácia: Template (dokumentácia, problémy)
Prvýkrát sa vyskytol: 28. decembra 2024 o 14:24:07 (613 výskytov)
Naposledy prihlásený: 19:50:32

TemplateError('UndefinedError: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'first_time'') while processing template 'Template<template=({# ultra short term temperature prognosis #} {% set temp = states.sensor.local_forecast.attributes.temperature|float(0)%} {%set temp_change = states.sensor.local_forecast_temperaturechange.state|float(0)%} {%set first_time = states.sensor.local_forecast_zambretti_detail.attributes.first_time[1]|float(0)%} {%set second_time = states.sensor.local_forecast_zambretti_detail.attributes.second_time[1]|float(0)%} {%if first_time>0%}{%set t_forecast = ((temp_change/60*first_time)+temp)|round(1)%}{%set interval = 0%} {%elif second_time>0%}{%set t_forecast = ((temp_change/60*second_time)+temp)|round(1)%}{%set interval = 1%} {%else%}{%set t_forecast = "unavailable"%}{%set interval = -1%}{%endif%} {{[t_forecast,interval]}}) renders=6546>' for attribute 'forecast_temp_short' in entity 'sensor.local_forecast'
TemplateError('UndefinedError: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'forecast'') while processing template 'Template<template=({# give approx. values for rain probability #} {%set forecast = states.sensor.local_forecast_zambretti_detail.attributes.forecast%} {%if forecast[0]==0 and forecast[1]==0 %}{%set rain_prob = [0,0]%} {%elif forecast[0]==2 and forecast[1]==1 %}{%set rain_prob = [60,10]%} {%elif forecast[0]==1 and forecast[1]==1 %}{%set rain_prob = [30,30]%} {%elif forecast[0]==1 and forecast[1]==0 %}{%set rain_prob = [10,0]%} {%elif forecast[0]==1 and forecast[1]>=2 %}{%set rain_prob = [20,60]%} {%elif forecast[0]==2 and forecast[1]==2 %}{%set rain_prob = [50,50]%} {%elif forecast[0]==2 and forecast[1]>2 %}{%set rain_prob = [50,70]%} {%elif forecast[0]>=2 and forecast[1]<2 %}{%set rain_prob = [50,10]%} {%else%}{%set rain_prob = [90,90]%}{%endif%} {{rain_prob}}) renders=4980>' for attribute 'rain_prob' in entity 'sensor.local_forecast_zambretti_detail'
TemplateError('UndefinedError: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'forecast'') while processing template 'Template<template=({%set forecast = states.sensor.local_forecast_zambretti_detail.attributes.forecast%} {%set conditions = [('mdi:weather-sunny','mdi:weather-night'),('mdi:weather-partly-cloudy', 'mdi:weather-night-partly-cloudy'),('mdi:weather-partly-rainy','mdi:weather-partly-rainy'),('mdi:weather-cloudy','mdi:weather-cloudy'),('mdi:weather-rainy','mdi:weather-rainy'),('mdi:weather-pouring','mdi:weather-pouring'),('mdi:weather-lightning-rainy','mdi:weather-lightning-rainy')]%} {# [State][day/night], available states: sunny (0), partlycloudy(1), partlycloudyrain(2), cloudy(3), rainy(4), pouring(5), lightning-rainy(6) #} {%if is_state('sun.sun', 'below_horizon')==true%}{%set daynight=1%}{%else%}{%set daynight=0%}{%endif%} {%set now = conditions[forecast[0]|int(0)][daynight|int(0)]%} {%set later = conditions[forecast[1]|int(0)][daynight|int(0)]%} {{(now,later)}}) renders=5324>' for attribute 'icons' in entity 'sensor.local_forecast_zambretti_detail'
TemplateError('UndefinedError: str object has no element 0') while processing template 'Template<template=({# give approx. values for rain probability #} {%set forecast = states.sensor.local_forecast_neg_zam_detail.attributes.forecast%} {%if forecast[0]<2 and forecast[1]<2 %}{%set rain_prob = [0,0]%} {%elif forecast[0]==1 and forecast[1]>=2 %}{%set rain_prob = [20,60]%} {%elif forecast[0]==2 and forecast[1]==2 %}{%set rain_prob = [50,50]%} {%elif forecast[0]==2 and forecast[1]>2 %}{%set rain_prob = [50,70]%} {%else%}{%set rain_prob = [90,90]%}{%endif%} {{rain_prob}}) renders=5300>' for attribute 'rain_prob' in entity 'sensor.local_forecast_neg_zam_detail'
TemplateError('UndefinedError: str object has no element 0') while processing template 'Template<template=({%set forecast = states.sensor.local_forecast_neg_zam_detail.attributes.forecast%} {%set conditions = [('mdi:weather-sunny','mdi:weather-night'),('mdi:weather-partly-cloudy', 'mdi:weather-night-partly-cloudy'),('mdi:weather-partly-rainy','mdi:weather-partly-rainy'),('mdi:weather-cloudy','mdi:weather-cloudy'),('mdi:weather-rainy','mdi:weather-rainy'),('mdi:weather-pouring','mdi:weather-pouring'),('mdi:weather-lightning-rainy','mdi:weather-lightning-rainy')]%} {# [State][day/night], available states: sunny (0), partlycloudy(1), partlycloudyrain(2), cloudy(3), rainy(4), pouring(5), lightning-rainy(6) #} {%if is_state('sun.sun', 'below_horizon')==true%}{%set daynight=1%}{%else%}{%set daynight=0%}{%endif%} {%set now = conditions[forecast[0]|int(0)][daynight|int(0)]%} {%set later = conditions[forecast[1]|int(0)][daynight|int(0)]%} {{(now,later)}}) renders=5774>' for attribute 'icons' in entity 'sensor.local_forecast_neg_zam_detail'

Logger: homeassistant.components.template.template_entity
Zdroj: components/template/template_entity.py:203
Integrácia: Template (dokumentácia, problémy)
Prvýkrát sa vyskytol: 22:02:58 (9 výskytov)
Naposledy prihlásený: 22:02:58

TemplateError('UndefinedError: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'first_time'') while processing template 'Template<template=({# ultra short term temperature prognosis #} {% set temp = states.sensor.local_forecast.attributes.temperature|float(0)%} {%set temp_change = states.sensor.local_forecast_temperaturechange.state|float(0)%} {%set first_time = states.sensor.local_forecast_zambretti_detail.attributes.first_time[1]|float(0)%} {%set second_time = states.sensor.local_forecast_zambretti_detail.attributes.second_time[1]|float(0)%} {%if first_time>0%}{%set t_forecast = ((temp_change/60*first_time)+temp)|round(1)%}{%set interval = 0%} {%elif second_time>0%}{%set t_forecast = ((temp_change/60*second_time)+temp)|round(1)%}{%set interval = 1%} {%else%}{%set t_forecast = "unavailable"%}{%set interval = -1%}{%endif%} {{[t_forecast,interval]}}) renders=7244>' for attribute 'forecast_temp_short' in entity 'sensor.local_forecast'
TemplateError('UndefinedError: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'forecast'') while processing template 'Template<template=({# give approx. values for rain probability #} {%set forecast = states.sensor.local_forecast_zambretti_detail.attributes.forecast%} {%if forecast[0]==0 and forecast[1]==0 %}{%set rain_prob = [0,0]%} {%elif forecast[0]==2 and forecast[1]==1 %}{%set rain_prob = [60,10]%} {%elif forecast[0]==1 and forecast[1]==1 %}{%set rain_prob = [30,30]%} {%elif forecast[0]==1 and forecast[1]==0 %}{%set rain_prob = [10,0]%} {%elif forecast[0]==1 and forecast[1]>=2 %}{%set rain_prob = [20,60]%} {%elif forecast[0]==2 and forecast[1]==2 %}{%set rain_prob = [50,50]%} {%elif forecast[0]==2 and forecast[1]>2 %}{%set rain_prob = [50,70]%} {%elif forecast[0]>=2 and forecast[1]<2 %}{%set rain_prob = [50,10]%} {%else%}{%set rain_prob = [90,90]%}{%endif%} {{rain_prob}}) renders=5516>' for attribute 'rain_prob' in entity 'sensor.local_forecast_zambretti_detail'
TemplateError('UndefinedError: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'forecast'') while processing template 'Template<template=({%set forecast = states.sensor.local_forecast_zambretti_detail.attributes.forecast%} {%set conditions = [('mdi:weather-sunny','mdi:weather-night'),('mdi:weather-partly-cloudy', 'mdi:weather-night-partly-cloudy'),('mdi:weather-partly-rainy','mdi:weather-partly-rainy'),('mdi:weather-cloudy','mdi:weather-cloudy'),('mdi:weather-rainy','mdi:weather-rainy'),('mdi:weather-pouring','mdi:weather-pouring'),('mdi:weather-lightning-rainy','mdi:weather-lightning-rainy')]%} {# [State][day/night], available states: sunny (0), partlycloudy(1), partlycloudyrain(2), cloudy(3), rainy(4), pouring(5), lightning-rainy(6) #} {%if is_state('sun.sun', 'below_horizon')==true%}{%set daynight=1%}{%else%}{%set daynight=0%}{%endif%} {%set now = conditions[forecast[0]|int(0)][daynight|int(0)]%} {%set later = conditions[forecast[1]|int(0)][daynight|int(0)]%} {{(now,later)}}) renders=5872>' for attribute 'icons' in entity 'sensor.local_forecast_zambretti_detail'
TemplateError('UndefinedError: str object has no element 0') while processing template 'Template<template=({# give approx. values for rain probability #} {%set forecast = states.sensor.local_forecast_neg_zam_detail.attributes.forecast%} {%if forecast[0]<2 and forecast[1]<2 %}{%set rain_prob = [0,0]%} {%elif forecast[0]==1 and forecast[1]>=2 %}{%set rain_prob = [20,60]%} {%elif forecast[0]==2 and forecast[1]==2 %}{%set rain_prob = [50,50]%} {%elif forecast[0]==2 and forecast[1]>2 %}{%set rain_prob = [50,70]%} {%else%}{%set rain_prob = [90,90]%}{%endif%} {{rain_prob}}) renders=5850>' for attribute 'rain_prob' in entity 'sensor.local_forecast_neg_zam_detail'
TemplateError('UndefinedError: str object has no element 0') while processing template 'Template<template=({%set forecast = states.sensor.local_forecast_neg_zam_detail.attributes.forecast%} {%set conditions = [('mdi:weather-sunny','mdi:weather-night'),('mdi:weather-partly-cloudy', 'mdi:weather-night-partly-cloudy'),('mdi:weather-partly-rainy','mdi:weather-partly-rainy'),('mdi:weather-cloudy','mdi:weather-cloudy'),('mdi:weather-rainy','mdi:weather-rainy'),('mdi:weather-pouring','mdi:weather-pouring'),('mdi:weather-lightning-rainy','mdi:weather-lightning-rainy')]%} {# [State][day/night], available states: sunny (0), partlycloudy(1), partlycloudyrain(2), cloudy(3), rainy(4), pouring(5), lightning-rainy(6) #} {%if is_state('sun.sun', 'below_horizon')==true%}{%set daynight=1%}{%else%}{%set daynight=0%}{%endif%} {%set now = conditions[forecast[0]|int(0)][daynight|int(0)]%} {%set later = conditions[forecast[1]|int(0)][daynight|int(0)]%} {{(now,later)}}) renders=6336>' for attribute 'icons' in entity 'sensor.local_forecast_neg_zam_detail'



Hi, my you share your the weather_forecast.yaml as is? it’s not clear for me how to edit it, setting the proper variables. Thank you

@HAuser1234 Many thanks for this great integration, exactly what I was searching for.

I’ve installed the weather_forecast.yaml integration, and it’s obviously working well. In the developer tools, I have the “local” states, so I did it correctly, it seems:

I then created a custom dashboard, edited it as YAML in the “Raw Configuration Editor”, and appended the weather_card_de.yaml YAML code to it. It looks like this now:

views:
  - title: Home
type: custom:vertical-stack-in-card
cards:
  - type: custom:mushroom-title-card
    title: '{{states.sensor.local_forecast.state}}'
  - type: horizontal-stack
[...]
  - type: custom:mushroom-template-card
    primary: 'Zukunft: {{states.sensor.local_forecast.attributes.forecast_zambretti[0]}}'
    secondary: >-
      Luftdruck:
      {{states.sensor.local_forecast.attributes.forecast_pressure_trend[0]}}  
      {{states.sensor.local_forecast_pressurechange.state}} hpa in 3h
    icon: mdi:weather-cloudy-arrow-right
    multiline_secondary: true
    icon_color: grey
    fill_container: false

I’ve also installed the two custom cards that you’re using in the above. I did it properly, as I can see in the browser console that the JS is loaded.

Still, my dashboard is completely empty… :frowning:

Can you please help me understand what’s going wrong?

Many thanks ahead for any help.

Kind regards,

Ralf

Nevermind, I played with the UI editor a bit and found that your code needs to be embedded in a section.

It looks like this now and is working fine (well, about the prediction accuracy I can make no statement yet…):

views:
  - title: Home
    sections:
      - type: custom:vertical-stack-in-card
        cards:
          - type: custom:mushroom-title-card
            title: '{{states.sensor.local_forecast.state}}'
          - type: horizontal-stack
            cards:
              - type: custom:mushroom-template-card
                primary: >-
                  {{states.sensor.local_forecast.attributes.forecast_short_term[0]}}
[...]

Here’s the current view:

(BTW, I only have the outside temperature and the air pressure as sensors, maybe I’ll try to integrate further sensors via a public weather API…)

Thank you.

Kind regards,

Ralf

Perhaps update the README so it points to your repository in the installation instructions :wink:

Also, even though I have both absolute and relative pressure sensor entities using hPa, I can’t add them?

Perhaps due to the device_class not being atmospheric_pressure?

UPDATE: I worked around it by adding a template sensor with device class atmospheric_pressure

I removed my post because I found some issues during conversion from yaml to to integration. You want to add as atmospheric_pressure, is it right?

The sensors of my weather station use device_class: pressure, and I can’t select them because the integration only supports device_class: atmospheric_pressure

But like I said, I worked around it by creating a new template sensor with the correct device class.

I’v changed atmospheric_pressure to pressure in line 94 of config_flow.py.
Wich can be found in custom_components\local_weather_forecast. Perhaps this should be default. Then you don’t need to make a extra pressure sensor.
But great work @peter.jurik the intergration is much improved and more user friendly.

Hi everyone! :sun_behind_small_cloud:

I’m excited to announce Version 3.0.0 of the Local Weather Forecast integration - a major release achieving complete compatibility with the original YAML implementation!

Key Highlights:
:white_check_mark: 100% Entity ID Match - All entity IDs now identical to original YAML
:white_check_mark: Automatic Migration - Seamless upgrade from v2.x
:white_check_mark: New Features - Temperature forecast, weather states, day/night icons
:white_check_mark: Extended Support - Both atmospheric_pressure and pressure device classes

Breaking Changes: Entity IDs have changed to match YAML format exactly (e.g., sensor.local_forecast instead of sensor.local_weather_forecast_local_forecast)

Migration: Automatic! Just update and restart.

GitHub: Release Version 3.0.0 - 100% YAML Compatibility · wajo666/homeassistant-local-weather-forecast · GitHub

Available via HACS or manual installation.

Feedback and questions welcome! :rocket:

2 Likes

The wind speed and direction say they’re optional but it won’t let me save with them empty?