I just cant figure out how to use weather forcast data.
What i want, is to be able to run an automation if any of the forcast days are below 2degrees.
I can get the forcast data from the ‘weather:getforecast’ i understand that it then stores in my response variable… but hwo do i use that?
i’ve clocked through all the ‘actions’ and cant find a way of using that.
I want the templow attribute from each day to check if its below 2, but yeah, i’m lost…
thanks in advance!
So i kinda got this, it creates 4 sensors, but no values in there…
No clue if i’m going in the right direction
- trigger:
- platform: time_pattern
minutes: 10
action:
- service: weather.get_forecasts
data:
type: daily
target:
entity_id: weather.xxx
response_variable: daily_forecast
sensor:
- name: "Day TempLow Forecast 1"
unique_id: "day_templowforecast_1"
state: "{{ daily_forecast['weather.xxx'].forecast[0].templow }}"
- name: "Day TempLow Forecast 2"
unique_id: "day_templowforecast_2"
state: "{{ daily_forecast['weather.xxx'].forecast[1].templow }}"
- name: "Day TempLow Forecast 3"
unique_id: "day_templowforecast_3"
state: "{{ daily_forecast['weather.xxx'].forecast[2].templow }}"
- name: "Day TempLow Forecast 4"
unique_id: "day_templowforecast_4"
state: "{{ daily_forecast['weather.xxx'].forecast[3].templow }}"
it really feels like daily_forecast as a varibable is not getting to the sensor section…
So my configuration.yaml file is this
template: !include weatherdata.yaml
And the previous content is all in weatherdata.yaml
I cant even get teh example directly on the weather page to work
template:
- trigger:
- platform: time_pattern
hours: /1
action:
- action: weather.get_forecasts
data:
type: hourly
target:
entity_id: weather.home
response_variable: hourly
sensor:
- name: Temperature forecast next hour
unique_id: temperature_forecast_next_hour
state: "{{ hourly['weather.home'].forecast[0].temperature }}"
unit_of_measurement: °C
the sensors just say unavalible for the state
Edwin_D
(Edwin D.)
September 29, 2024, 3:23pm
6
Demarcation101:
weather.xxx
Did you replace all occurrences of weather.xxx with your weather entity?
Edwin_D
(Edwin D.)
September 29, 2024, 3:24pm
7
It uses an hourly trigger, so you may need to wait an hour for it tot populate. Try triggering per minute first, if it works you can update fewer times.
Yes, I actually xxx it out as its my house number and road name, these are all correct and match the entityid for the weather entity
The ‘default’ example one is hourly but my original one is every 10 min
Latest copy of my weather data.yaml
- trigger:
- platform: time_pattern
minutes: 1
- platform: homeassistant
event: start
action:
- service: weather.get_forecasts
data:
type: daily
target:
entity_id: weather.xxx
response_variable: dailyforecast
- variables:
today_forecast: "{{ dailyforcast['weather.xxx'].forecast[0] }}"
sensor:
- name: "Day TempLow Forecast 5"
unique_id: "day_templowforecast_1"
state: "{{ today_forecast }}"
- name: "Day TempLow Forecast 6"
unique_id: "day_templowforecast_2"
state: 42
- name: "Day TempLow Forecast 7"
unique_id: "day_templowforecast_3"
state: "{{ dailyforecast['weather.xxx'].forecast[2].templow }}"
- name: "Day TempLow Forecast 8"
unique_id: "day_templowforecast_4"
state: "{{ dailyforecast['weather.xxx'].forecast[3].templow }}"
- trigger:
- platform: time_pattern
minutes: 1
- platform: homeassistant
event: start
action:
- action: weather.get_forecasts
data:
type: hourly
target:
entity_id: weather.xxx
response_variable: hourly
sensor:
- name: Temperature forecast next hour
unique_id: temperature_forecast_next_hour
state: "{{ hourly['weather.xxx'].forecast[0].temperature }}"
unit_of_measurement: °C
All the sensors are created but none work
Edwin_D
(Edwin D.)
September 29, 2024, 4:45pm
11
Demarcation101:
minutes: 1
This is still once an hour, on the first minute of the hour. You are missing the /
Troon
(Troon)
September 29, 2024, 4:48pm
12
Typo:
response_variable: dailyforecast
- variables:
today_forecast: "{{ dailyforcast['weather.xxx'].forecast[0] }}"
^^
dbs
(David)
September 29, 2024, 4:51pm
13
I include this in my templates so they auto-repopulate when I reload the code:
- trigger:
- platform: time_pattern
hours: "/1"
- platform: homeassistant
event: start
- platform: event
event_type: event_template_reloaded
I also have two sensors that tell me the minimum temperature and hour in the next day. You could probably do something similar for getting temps below -2.
- trigger:
- platform: time_pattern
hours: "/1"
- platform: homeassistant
event: start
- platform: event
event_type: event_template_reloaded
action:
- service: weather.get_forecasts
target:
entity_id: weather.smhi_home
data:
type: hourly
response_variable: forecast
sensor:
- name: "Min Forecast Temperature Hour in Next Day"
unique_id: min_forecast_temperature_hour_in_next_day
state: >
{% set min_temp = forecast["weather.smhi_home"].forecast[:] | map(attribute='temperature')|min %}
{% set min_index = (forecast["weather.smhi_home"].forecast[:] | map(attribute='temperature')|list).index(min_temp) %}
{% set coldest_hour = as_timestamp(forecast["weather.smhi_home"].forecast[min_index]['datetime']) | timestamp_custom("%H") | int(0) %}
{{coldest_hour}}
attributes:
state_class: measurement
unit_of_measurement: h
icon: mdi:thermometer
- trigger:
- platform: time_pattern
hours: "/1"
- platform: homeassistant
event: start
- platform: event
event_type: event_template_reloaded
action:
- service: weather.get_forecasts
target:
entity_id: weather.smhi_home
data:
type: hourly
response_variable: forecast
sensor:
- name: "Min Forecast Date in Next Day"
unique_id: min_forecast_date_in_next_day
state: >
{% set min_temp = forecast["weather.smhi_home"].forecast[:] | map(attribute='temperature')|min %}
{% set min_index = (forecast["weather.smhi_home"].forecast[:] | map(attribute='temperature')|list).index(min_temp) %}
{% set coldest_hour = forecast["weather.smhi_home"].forecast[min_index]['datetime'] %}
{{coldest_hour}}
attributes:
state_class: measurement
device_class: timestamp
icon: mdi:thermometer
@troon , Fixed that, no effect
@dbs - so i just tried your code, same issue
(yes i updated the entity name for the weather entity)
i think this could be more a ‘my instance’ issue than a code issue…
maybe i need to run up a clean HA install for testing…
Edwin_D
(Edwin D.)
September 29, 2024, 5:22pm
17
First try the action in the developer tools to see if the attributes you are after are in the weather entity you use. I highly doubt a fresh HA install will fix this, it is bound to be something simple. templow is not an attribute my weather service has, for instance. Every service has different things on offer. Some offer hourly, some do not, attibutes may differ per type too.
i tried the developer tools already, ran the weather forecast action and got the results happily.
just spun up a VM and installed clean HA… the code works fine…
thats a lil upsetting… any idea on how to troubleshoot that?
Edwin_D
(Edwin D.)
September 29, 2024, 5:41pm
19
Have you tries the check configuration button and checked the logs for errors? For instance I find it hard to believe you have no other templates, so this might very well be a duplicate. Hou can only have one template: in configuration.yaml.
So, not sure how to explain this, after the clean ha instance worked.
I went to the configuration.yaml file and hashed out everything, then re-enabled everything one part at a time… now it all works fine… it doesn’t make sense… but it works perfect now…