Extracting Temperature out of forecast in a template

Hi,

i use this weatherforecast integration. Meteorologisk institutt (Met.no) - Home Assistant

First of all, i’m new to template. I know how to get an attribute out of an entity. BUT

I want to have the templow from tommorrow. So i need to get 1 level deeper in the attributes to get the templow but i has to be from the next day?

Weather forcast

‘{{ state_attr(‘weather.forecast_sharlynsland’,‘pressure’)}}
{{ state_attr(‘weather.forecast_sharlynsland’,‘forecast’)}}’

Weather forcast

992.6
[{‘condition’: ‘cloudy’, ‘datetime’: ‘2022-11-18T11:00:00+00:00’, ‘wind_bearing’: 256.1, ‘temperature’: 8.5, ‘templow’: 5.4, ‘wind_speed’: 17.6, ‘precipitation’: 0.1}, {‘condition’: ‘rainy’, ‘datetime’: ‘2022-11-19T11:00:00+00:00’, ‘wind_bearing’: 269.8, ‘temperature’: 8.3, ‘templow’: 5.6, ‘wind_speed’: 15.8, ‘precipitation’: 2.5}, {‘condition’: ‘rainy’, ‘datetime’: ‘2022-11-20T11:00:00+00:00’, ‘wind_bearing’: 204.3, ‘temperature’: 5.6, ‘templow’: 4.1, ‘wind_speed’: 25.6, ‘precipitation’: 4.1}, {‘condition’: ‘rainy’, ‘datetime’: ‘2022-11-21T11:00:00+00:00’, ‘wind_bearing’: 188.9, ‘temperature’: 6.6, ‘templow’: 3.6, ‘wind_speed’: 25.6, ‘precipitation’: 7.8}, {‘condition’: ‘cloudy’, ‘datetime’: ‘2022-11-22T11:00:00+00:00’, ‘wind_bearing’: 205.5, ‘temperature’: 5.9, ‘templow’: 3.2, ‘wind_speed’: 22.0, ‘precipitation’: 0.3}]

Thanks in advanced for your help
Lynn

if only tomorrow then a simple one can do, 0 is the first group, i.e. tomorrow

{{ state_attr('weather.forecast_sharlynsland', 'forecast')[0].temperature }}
4 Likes

Thanks a lot for the help. It works :blush:

For graphs, the apexcharts (hacs) is nice too…you will see that the data_generator is required though, not 1-2-3 that simple :slight_smile:

type: custom:apexcharts-card
header:
  title: Test
  show: true
graph_span: 4d
span:
  start: day
apex_config:
  dataLabels:
    enabled: false
series:
  - entity: weather.forecast_sharlynsland
    name: Home Weather Forecast
    data_generator: |
      return entity.attributes.forecast.map((entry) => {
            return [new Date(entry.datetime), entry.temperature];
          });
2 Likes

This is also good to know. I have apex still installed so i tried it out, Thanks.
I combined it with the actual temperature.

image

where should I write this?

Create a template sensor (devices > helpers)

1 Like

Thank you. I did find where to create them now, but I need to save all hourly forecast predictions to the database. If I go to create a template sensor, I would need to create like 12 of them?

If you want to track history for each one of them, yes…]
EDIT: but why would you want this? For fc graphs I already supplies a suggestion above

I need to have data of various forecasts in the database that I could do some data analysis

Note that the forecasts are now done via a service response, so the old solution might be out of date soon:

There’s a good template sensor example near the bottom of that page.

Stil not clear what you need, guesses only… so if you want to compare forecast then you need (I have not seen another solution yet) to store it in a separate template sensor. I do this e.g. for comparing solarforecast and humidity vs. reality for solar I do this every monring, for humidity twice a day

I have seen those examples, but I just started working with Home Assistant, so I am very new and I don’t understant it 100%

Where do I need to write the code from that example template sensor to check how it works? If I try to create a template by going to settings->Devices&Services->Helpers->Create Helper, it doesn’t look like there is a field to write such code. This is why I am a bit confused. Do I need to write it in automations.yaml, configuration.yaml or any other .yaml file?

For every temperature measurement (or at least every hour) I need to have daily forecasts for at least 5 days into the future that I could analyse how forecasts change and how accurate they are. I would do data analysis using python, but for that I need to save data into database

So that’s 120 separate sensors if you want to be able to track their state over time, and that’s just for one measurement (e.g. temperature).

Do you want to be able to refer to them by absolute time (e.g. 16:00 on 7-Jan) or by time out (e.g. 53 hours in the future)?

30 sensors for one measurement, to be precise, as Norwegian Meteorological Institute provides 24 hourly forecasts and 6 daily forecasts. I was just hoping to find a solution which would have all information in one place. Like I can find all current weather information (temperature, humidity, pressure, etc.) in one place under attributes of weather.home, where state is presented by weather description (snowy, rainy, etc). I am working with Python Dataframe, so refering by time out would be the best, cause it could be the column name, but time when the forecast was received is also important (at the moment I am not sure how often do they update their forecasts)