Open alanmilinovic opened 2 years ago
You can do this with this integration via the weather or precipitation sensor and a template sensor where you describe your logic.
Any tips how to do it? :)
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
forecast
attribute of the hourly weather sensor (which is an array),datetime
(and precipitation
or condition
) of the first entry with nonzero precipitation
,datetime
of the last entry before the precipitation
becomes zero,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."
Thank you for explanation. I get the idea. Let's see if I will have some time to play around with it.
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.
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.
I think I found a solution. https://www.ajfriesen.com/rain-warning-sensor-with-home-assistant/
@FL550 i have also a question to the forecast? Where i can aktivate that feature, i dont have any forecast entity from your integration
Please see issue #77.
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.