service: tts.google_say
data:
entity_id: media_player.1234
message: >-
Good morning.
It is {{ now().hour}} {{ now().minute }}
and the forecast is {{ states('weather.home') }}
New
action:
- service: weather.get_forecast
data:
type: daily
target:
entity_id: weather.home
response_variable: forecast_daily
- service: tts.google_say
data:
entity_id: media_player.1234
message: >-
Good morning. It is {{ now().hour}} {{ now().minute }}
The forecast is {{ forecast_daily.forecast[0].condition }}.
With a temperature of {{ forecast_daily.forecast[0].temperature|round(1) }}, wind speed of {{ forecast_daily.forecast[0].wind_speed|round(0) }}, and precip of {{ forecast_daily.forecast[0].precipitation|round(0) }}
At {{ as_timestamp(forecast_daily.forecast[0].datetime) | timestamp_custom('%H %M %A') }}
Notes
The service call to weather.get_forecast using the default service seems to bring back six days of forecasts.
After some experimentation with loops, only the first is read out for brevity and forecast_daily.forecast[0] is used to get the first entry.
A few round() calls are used to make the numeric values easier to listen to.
The time and day of the forecast is read out at the end as a check that it is current (in case the service changes).
The ability to call specific weather services and process different elements of the result is interesting, but less relevant in this “alarm clock” use-case.
Thanks to all who added to this discussion as many of your ideas and code snippets helped with this update!
Hi,
After banging my head against more deeply nested JSON returned by the newly changed 2023.12 weather.get_forecasts (note the extra s on get_forecasts), here’s an updated, updated implementation:
# weather.get_forecasts example service call and TTS template functions
action:
- service: weather.get_forecasts
data:
type: daily
target:
entity_id: weather.home
response_variable: forecast_daily
- service: tts.google_say
data:
entity_id: media_player.nesthub1234
message: >-
Good morning.
It is {{ now().hour}} {{ now().minute }} on {{ states('sensor.date_in_text') }}.
The forecast is {{ forecast_daily['weather.home']['forecast'][0].condition }}.
With a temperature of {{ forecast_daily['weather.home']['forecast'][0].temperature|round(1) }}, wind speed of {{ forecast_daily['weather.home']['forecast'][0].wind_speed|round(0) }}, and precip of {{ forecast_daily['weather.home']['forecast'][0].precipitation|round(0) }}
At {{ as_timestamp(forecast_daily['weather.home']['forecast'][0].datetime) | timestamp_custom('%H %M %A') }}
Hopefully by the time you read this post, the HASS docs will have been updated with the 2023.12 changes to weather.get_forecasts. Last I checked, the PR was being reviewed in GitHub, and the docs are moving around so I can’t provide a link at the moment.
APIs get changed, designs don’t workout, but this one has become a bit of a pain.
I was also looking for this info and I’m unfortunately not a regular user of the Discord channels. It’s just too much info I can’t keep up with, given my day.
I truly think the release notes could’ve said just a little bit more than just “the schema changed”.
I think a number of people will trip over how to index the fields, because one can usually just use dot notation. It’s a done deal now (and not upset about it in any way), but if I caught this earlier I would’ve suggested to not use the entity ID, but just the slug part of it, e.g. forecast_daily.home.forecast.... Now that I’ve written this, I realise you need to use the indexing notation anyway on lists, so maybe this is moot.
Hi,
i currently have a sensor for get the forcast with the service weather.get_forecast. How do i switch my attributes to work with weather.get_forecasts?
Right I’m still confused and don’t see an example of how to reproduce my logic / workings. As I understand my configurations I have some logic that I use both in a template sensor and an automation, that evaluates the next 12 hours forecasts. The sensor records the lowest temperature for graphing / historical purposes. The automation does a point in time evaluation everynight as a prompt if I need to do things because of the temperature.
The sensor which records the lowest temp (don’t forget I’ve got 4 of these for each weather service).
Then an automation on a daily schedule of 20:30 that sends a prompt to my phone giving me mins and max’s overnight.
service: notify.mobile_app_iphone_13_pro
data:
title: Tonights temperature
message: >-
{% set tomorrow = (as_timestamp(now() + timedelta(hours=12)) |
timestamp_utc) .replace(' ', 'T') ~ '+00:00' %} {% set today =
state_attr('weather.openweathermap_onecall_hourly', 'forecast') |
selectattr('datetime', 'lt', tomorrow) | map(attribute='temperature') | list
%} Openweather says it is now
{{state_attr('weather.openweathermap_onecall_hourly', 'temperature')}} °C
outsid and they say the forecast for the next 12 hours today says it will be
max {{ today | max }} °C with a low of {{ today | min }} °C
data:
push:
interruption-level: time-sensitive
tag: daily-weather-update
sticky: "true"
I can’t see how I can reproduce this with the service calls etc?
This was my initial use case and reason for setting up and getting into HA in the first place some 2 years ago, and now I am looking to try and use some new weather integrations only to stumble across this and that my existing setup will stop working in 4 months.
Right another night and I’ve made progress, I even managed to use the new get_forcecasts, but I’m sure someone will tell me a better way of doing this.
Thanks, it wasn’t broken, but its less broken now!
Also I figured out how to limit the returned forecast items to a days worth, couldn’t just limit to the temperature, but its good enough for my use case.
A small variation on creating one single forecast sensor, one can also create dedicated template sensors for each forecast element of interest. In the example below temperature, wind_speed and precipitation. The data size of these sensors is kept minimal, as the forecast lists only contain the values for that sensor
Note: removing the attributes from the weather sensor I can understand, but deprecating weather.get_forecast caused me a lot of extra work, and seems just a variation of weather.get_forecasts with a single entity.
Keeping those variations available causes a lot of confusion and frustration for new and less knowledgeable users… better to just rip the bandage off quickly.
In my opinion the new version get_forcasts is harder to understand how to parse the response for less experienced users. Users who typically have just one weather entity as well.