Meteorologisk institutt (Met.no) forecast data template

Hi,
want to read out the low temp of next day. Found some template, which fails, cause there is no data array.

{{ state_attr(‘weather.forecast_home_2’, ‘forecast’)[0].temperature }}

I checked the provided docu, but there is only information about installing the integration.

Where can I find a detailed description of this integeration, or how did the correct templete look like?

With best regards

Gerhard

Hi Gerhard, do you have an entity weather.forecast_home_2?
Are you using the Developer tools → template ?

Open your Home Assistant instance and show your template developer tools.

This can be very helpful to troubleshoot/create.

Hi Nick,
yes, the name of my entity is correct.
I used the dev tools (template) to test the template I got from some conversation and adopt it, but doesn’t work.
I see 5 day forecast in my UI, but can’t get this values out via template. The sample uses indices to extract the element 0 of an array, but there is no array, the dev tools told me …
With best regards
Gerhard

This is the temperature from my weather integration for tomorrow:

{{ state_attr('weather.home', 'forecast')[1].temperature }}

and does work.

But: it doesn’t work just like that since you have to retrieve the weather first.

Hi Nick,
ok, I thought it is already done:

I have this element in my UI …
If there is extra work to do, please give my a pointer how and where (I am still a newbee).
Thanks a lot.
With best regards
Gerhard

You will need to use the weather.get_forecasts action.

Refer to the first example in the documentation for the Weather integration.

It shows how to create a Trigger-based Template Sensor that reports today’s hourly temperature and automatically updates every hour.

I have modified the example to meet your requirements (get tomorrow’s daily temperature, updated every hour and whenever Template Entities are reloaded).

template:
  - trigger:
      - trigger: time_pattern
        hours: /1
      - trigger: event
        event_type: event_template_reloaded
    action:
      - action: weather.get_forecasts
        data:
          type: daily
        target:
          entity_id: weather.forecast_home_2
        response_variable: daily
    sensor:
      - name: Temperature forecast tomorrow
        unique_id: temperature_forecast_tomorrow
        state: "{{ daily['weather.forecast_home_2'].forecast[1].temperature }}"
        unit_of_measurement: '°C'
        device_class: temperature

If you want to see another example of using weather.get_forecasts


EDIT

Modification. Changed platform to trigger to avoid complaint by Config Helper in VS Code.

Thanks.

But my biggest problem with HA:
How can I find out in which file things have to go?

I put this in configuration.yaml, but it fails.

For a newbee it is not that easy to find out, where to put this sample code … sorry.

With best regards

Gerhard

Is there a related error message in Settings → Logs?

You said you put it in the configuration.yaml file. Does that file already contain a template: key?

Because if you copy-pasted my example into the file, the first line of the example is a template: key so if there’s already a template: key in the file you will have duplicated it (it should never be duplicated).


NOTE

If your configuration.yaml file contains something that looks like this:

template: !include templates.yaml

It means the configuration for Template entities are located in a separate file named templates.yaml.

Examine your configuration.yaml file and let me know if it already contains a template: key and if it has an !include or not.

If it does contain a template: key (but no !include), paste my example directly under it and ensure there’s only one instance of the template: key.

If this is the very first Template entity you have ever created, restart Home Assistant in order to load it. If you already have other Template entities, you can simply use Developer Tools → YAML → Reload Template Entities.

Ok, not that easy. I have to learn lot about this ‘yaml’ …

Ok, to get things structured I created a templates.yaml file.
I included it.
And I learned, that the key ‘template:’ is in configuration.yaml and the content is in templates.yaml. Otherwise I get some message that the line ‘template:’ isn’t allowed.

Ok, now I have the same problem as I get when I copied the code directly into configuration.yaml before which does’n contain a ‘template’ key before:

It looks like, that something was changed in HA and this syntax isn’t valid any longer.

This error was maybe misinterpreted by me, I first thought, that this code is not for configuration.yaml.

With best regards

Gerhard

PS: By the way, is it usual that syntax is broken with updated very often? My working eMail notification service is also in error and the message is more or less the same.

Note that the syntax parsing/error codes in vscode is not maintained by the Home Assistant project, and is occasionally incorrect or out of date.

So when you see errors in vscode take it with a grain of salt. You can try ignoring it and check your configuration with the official config check tool in Developer Tools.

That’s entirely optional. As explained, it can be placed within configuration.yaml as long as it’s done correctly.

It’s different, not the same. As explained by karwosts, that message isn’t produced by Home Assistant. It’s produced by the VS Code editor, specifically by a plug-in used by VS Code called Home Assistant Config Helper.

It’s still valid.

Recently, Home Assistant renamed several keys used in automations (and Trigger-based Template entities) such as platform and service (to trigger and action, respectively). The old names still work but Config Helper identifies them anyways.

To make Config Helper’s message go away, replace the word platform with trigger. Refer to my original example posted above which I have already updated.


NOTE

If you wish, you can remove the second trigger. It’s there merely as a convenience for you.

It’s sole purpose is to ensure that the Trigger-based Template Sensor produces a value the moment you execute Reload Template Entities. You get an initial result immediately

Without that second trigger, the Sensor’s initial value will be unknown and will remain that way until the Time Pattern Trigger fires (on the hour, every hour). You have to wait for the initial result.