Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rain forecast on dashboard #57

Open
alanmilinovic opened this issue Jun 24, 2022 · 13 comments
Open

Rain forecast on dashboard #57

alanmilinovic opened this issue Jun 24, 2022 · 13 comments
Labels
enhancement New feature or request

Comments

@alanmilinovic
Copy link

Hi, I would like to display on my dashboard when the next rain will start, what is the level (low, medium, strong) and when it will end.
Is it possible with this integration? I saw there are precipitation sensors that one can play with, but didn't found any example of YML code that I can reuse.

something like this:
Strong precipitation possible around 08:25 will end around 11:30.

Basically, I just want to know when the next rain will start and how long it will rain. If it is not that day maybe to display next date when the rain is forecasted.

@FL550
Copy link
Owner

FL550 commented Jun 24, 2022

You can do this with this integration via the weather or precipitation sensor and a template sensor where you describe your logic.

@alanmilinovic
Copy link
Author

Any tips how to do it? :)

@nikipore
Copy link

Yes ;-)

The following code interpolates the temperature forecast from the hourly temperature sensor:

template:
      - name: weather_forecast_temperature_interpolated
        state_class: measurement
        unit_of_measurement: "°C"
        state: >
          {% set temperature = state_attr('sensor.temperature_wiesbaden_biebrich_1h', 'data') %}
          {% set t = now() %}
          {% set index = ((as_timestamp(t) - as_timestamp(temperature[0]['datetime'])) // 3600) | int %}
          {% if index < 0 %}
            {% set result = temperature[0]['value'] %}
          {% else %}
            {% set result = temperature[index]['value'] + (temperature[index+1]['value'] - temperature[index]['value']) * t.minute / 60 %}
          {% endif %}
          {{ result | round(1) }}
        device_class: temperature

I hope you get the idea. You should study the Home Assistant template documentation, and then it should be straightforward to write your own template.

The hourly weather sensor should be your friend:

temperature: 24.4
humidity: 56
pressure: 1007.4
wind_bearing: 233
wind_speed: 14.8
visibility: 28.9
forecast: 
- datetime: '2022-06-24T00:00:00Z'
  condition: lightning-rainy
  temperature: 24
  templow: 18
  precipitation: 2.7
  wind_bearing: 245.57
  wind_speed: 4.12
  wind_gusts: 8.75
  precipitation_probability: 51
- datetime: '2022-06-25T00:00:00Z'
  condition: sunny
  temperature: 27
  templow: 15
  precipitation: 0
  wind_bearing: 198.46
  wind_speed: 3.09
  wind_gusts: 6.17
  precipitation_probability: 13
[...]

A possible (imperative) strategy would be to

  1. loop over the forecast attribute of the hourly weather sensor (which is an array),
  2. remember the datetime (and precipitation or condition) of the first entry with nonzero precipitation,
  3. remember the datetime of the last entry before the precipitation becomes zero,
  4. translate the timestamps to local time and render a result.

With advanced filters (like Python's takewhile) I would have implemented this in a functional way, but Jinja2 has very limited built-in filters, so I believe you'll have to live with imperative for loops (no, there is no break or while).

I could write the solution up, but you have to know what you want and you'll have to maintain it – "Give a man a fish, and you feed him for a day. Teach a man to fish, and you feed him for a lifetime."

@alanmilinovic
Copy link
Author

Thank you for explanation. I get the idea. Let's see if I will have some time to play around with it.

@FL550
Copy link
Owner

FL550 commented Jun 24, 2022

Maybe it's easier if this is implemented directly within the integration. There's more flexibility with python.

I cannot promise if I find time (and delight) the next days.

@alanmilinovic
Copy link
Author

alanmilinovic commented Nov 3, 2022

Maybe it's easier if this is implemented directly within the integration. There's more flexibility with python.

I cannot promise if I find time (and delight) the next days.

Hi, any news on this topic? Have you found some time to implement this? I think it would be super usefull and easier directly in python.

@alanmilinovic
Copy link
Author

I think I found a solution.
https://www.ajfriesen.com/rain-warning-sensor-with-home-assistant/

@duczz
Copy link

duczz commented Sep 22, 2023

@FL550 i have also a question to the forecast?
Where i can aktivate that feature, i dont have any forecast entity from your integration

@FL550
Copy link
Owner

FL550 commented Sep 22, 2023

Please see issue #77.

@FL550 FL550 added the enhancement New feature or request label Oct 5, 2023
@sevorl
Copy link

sevorl commented Sep 19, 2024

alterative solution might be this: https://morgenwirdes.de/api/index.php

@alanmilinovic
Copy link
Author

I am relying on my custom code that is based on Openweathermap, and it is working great and very accurate.

Solution from Morgenwirdes is nor reliable and API is not providing allot of data.

@duczz
Copy link

duczz commented Sep 19, 2024

Please see issue #77.

i have the forecasts but how i create this card?
image

@FL550
Copy link
Owner

FL550 commented Sep 20, 2024

@duczz Please see https://github.com/FL550/dwd_weather/wiki#how-to-add-a-weather-chart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants