I need the lowest temperature at night. I looked inside the API and found this at the daily section:
daily.temp.night = Night temperature.
Can this be implemented in the future?
I need the lowest temperature at night. I looked inside the API and found this at the daily section:
daily.temp.night = Night temperature.
Can this be implemented in the future?
I actually use the temperature_low. But this is not the lowest temperature at night
Hello!
I understand that this thread is old, but as I am curious if there is still some development going on, I would like to point to a blog where the lowest forecast temperature using OpenWeatherMap is calculated for a frost alert. The blog is in German but non-German speakers will understand the code.
BTW, I did some minor adjustments to the final code that I use in my HA:
/homeassistant/templates.yaml:
sensor:
### Frost alert
- name: Frost Alert
unique_id: frost_alert
state: >
{% set start = (now().date()+ timedelta(days=1)) | string + "T04:00:00+00:00"%}
{% set end = (now().date()+ timedelta(days=1)) | string + "T08:00:00+00:00"%}
{% set temp_frost_alert = (state_attr('weather.openweathermap_hourly', 'forecast') | selectattr("datetime", ">=", start) | selectattr("datetime", "<=", end) | map(attribute="temperature") | list | min)%}
{% set result_frost_alert = temp_frost_alert < 6 %}
{{result_frost_alert}}
- name: Frost Temperature
unique_id: frost_temperature
state: >
{% set start = (now().date()+ timedelta(days=1)) | string + "T04:00:00+00:00"%}
{% set end = (now().date()+ timedelta(days=1)) | string + "T08:00:00+00:00"%}
{% set temp_frost_alert = (state_attr('weather.openweathermap_hourly', 'forecast') | selectattr("datetime", ">=", start) | selectattr("datetime", "<=", end) | map(attribute="temperature") | list | min)%}
{{temp_frost_alert}}
- name: Frost Time
unique_id: frost_time
state: >
{% set start = (now().date()+ timedelta(days=1)) | string + "T04:00:00+00:00"%}
{% set end = (now().date()+ timedelta(days=1)) | string + "T08:00:00+00:00"%}
{% set temp_frost_alert = (state_attr('weather.openweathermap_hourly', 'forecast') | selectattr("datetime", ">=", start) | selectattr("datetime", "<=", end) | map(attribute="temperature") | list | min)%}
{% set result_frost_alert = temp_frost_alert < 6 %}
{% set time_frost_alert = (state_attr('weather.openweathermap_hourly', 'forecast') | selectattr("datetime", ">=", start) | selectattr("datetime", "<=", end) | selectattr("temperature", "eq", temp_frost_alert)| map(attribute="datetime") | list | first )%}
{{as_timestamp(time_frost_alert) | timestamp_custom("%H:%M") if time_frost_alert else ''}}
And the alert:
alias: Frost warning (OpenWeatherMap.org)
description: >-
Check in the evening if the min. temp. next day is below x °C and trigger warning if yes (incl. time and expected temp.)
trigger:
- platform: time
at: "17:00:00"
- platform: time
at: "18:00:00"
- platform: time
at: "19:00:00"
- platform: time
at: "20:00:00"
condition:
- condition: state
entity_id: sensor.frost_alert
state: "true"
action:
- service: notify.notify
data:
title: Frost warning (OWM.org)
message: >-
At {{states("sensor.frost_time")}} we will have
{{states("sensor.frost_temperature")}} °C.
mode: single
I’m not sure if it makes sense to trigger the checks 4 times (5 pm to 20 pm) or if just once suffices.
BTW:
Where does OWM store the API key and geo position in HA? Is it possible to place them elsewhere, i.e. in a secrets.yaml file?
Hello!
I have this in my configuration.yaml
:
template: !include templates.yaml
The templates.yaml
contains this to allow me an automation for a frost alert (<3 °C), which worked for a while but no longer:
sensor:
### Frost alert
- name: Frost Alert
unique_id: frost_alert
state: >
{% set start = (now().date()+ timedelta(days=1)) | string + "T04:00:00+00:00"%}
{% set end = (now().date()+ timedelta(days=1)) | string + "T08:00:00+00:00"%}
{% set temp_frost_alert = (state_attr('weather.openweathermap', 'forecast') | selectattr("datetime", ">=", start) | selectattr("datetime", "<=", end) | map(attribute="temperature") | list | min)%}
{% set result_frost_alert = temp_frost_alert < 3 %}
{{result_frost_alert}}
- name: Frost Temperature
unique_id: frost_temperature
state: >
{% set start = (now().date()+ timedelta(days=1)) | string + "T04:00:00+00:00"%}
{% set end = (now().date()+ timedelta(days=1)) | string + "T08:00:00+00:00"%}
{% set temp_frost_alert = (state_attr('weather.openweathermap', 'forecast') | selectattr("datetime", ">=", start) | selectattr("datetime", "<=", end) | map(attribute="temperature") | list | min)%}
{{temp_frost_alert}}
- name: Frost Time
unique_id: frost_time
state: >
{% set start = (now().date()+ timedelta(days=1)) | string + "T04:00:00+00:00"%}
{% set end = (now().date()+ timedelta(days=1)) | string + "T08:00:00+00:00"%}
{% set temp_frost_alert = (state_attr('weather.openweathermap', 'forecast') | selectattr("datetime", ">=", start) | selectattr("datetime", "<=", end) | map(attribute="temperature") | list | min)%}
{% set result_frost_alert = temp_frost_alert < 3 %}
{% set time_frost_alert = (state_attr('weather.openweathermap', 'forecast') | selectattr("datetime", ">=", start) | selectattr("datetime", "<=", end) | selectattr("temperature", "eq", temp_frost_alert)| map(attribute="datetime") | list | first )%}
{{as_timestamp(time_frost_alert) | timestamp_custom("%H:%M") if time_frost_alert else ''}}
Now I see this error in the log:
Error while processing template: Template<template=({% set start = (now().date()+ timedelta(days=1)) | string + "T04:00:00+00:00"%} {% set end = (now().date()+ timedelta(days=1)) | string + "T08:00:00+00:00"%} {% set temp_frost_alert = (state_attr('weather.openweathermap', 'forecast') | selectattr("datetime", ">=", start) | selectattr("datetime", "<=", end) | map(attribute="temperature") | list | min)%} {% set result_frost_alert = temp_frost_alert < 3 %} {{result_frost_alert}}) renders=2>
Error while processing template: Template<template=({% set start = (now().date()+ timedelta(days=1)) | string + "T04:00:00+00:00"%} {% set end = (now().date()+ timedelta(days=1)) | string + "T08:00:00+00:00"%} {% set temp_frost_alert = (state_attr('weather.openweathermap', 'forecast') | selectattr("datetime", ">=", start) | selectattr("datetime", "<=", end) | map(attribute="temperature") | list | min)%} {% set result_frost_alert = temp_frost_alert < 3 %} {% set time_frost_alert = (state_attr('weather.openweathermap', 'forecast') | selectattr("datetime", ">=", start) | selectattr("datetime", "<=", end) | selectattr("temperature", "eq", temp_frost_alert)| map(attribute="datetime") | list | first )%} {{as_timestamp(time_frost_alert) | timestamp_custom("%H:%M") if time_frost_alert else ''}}) renders=2>
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 586, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2545, in _render_with_context
return template.render(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 1301, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 1, in top-level template code
jinja2.exceptions.UndefinedError: No aggregated item, sequence was empty.
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 712, in async_render_to_info
render_info._result = self.async_render(
^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 588, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: No aggregated item, sequence was empty.
I understand that HA had a change about the weather integrations and also OpenWeatherMap is about to switch from API 2.5 to 3.0. I wonder if there is a way to still use this, and if yes, how I would need to adjust it.
Maybe meanwhile there is a much easier method available to get “frost alerts” than like this.
Thanks for pointing me into the right direction!