How to migrate from weather integration approach to new weather.get_forecast service?

You created a Trigger-based Template Sensor. It won’t report a nominal value until it’s triggered at least once. In your example, until the state value of weather.forecast_home changes. What you did to the weather entity caused its value to change (and that served to trigger your newly created sensor).


It’s fairly common for novices to create a Trigger-based Template Sensor and then remark that, after reloading Template entities, the new sensor doesn’t immediately report a nominal value. As explained, it won’t until it’s triggered by one of its triggers.

It’s for this reason that the following Event Trigger is often added:

      - platform: event
        event_type: event_template_reloaded

It triggers whenever Template entities are reloaded. As a result, it causes the new Trigger-based Template Sensor to immediately evaluate its templates and report a value.

Anyway, at this point, there’s no need to add the Event Trigger given that your Trigger-based Template Sensor has already triggered at least once. (The only reason to include it now would be if you want to update the sensor slightly more frequently than just whenever the weather entity’s state changes.)

Solving the issue: it’s not a sensor template, it’s a template integration! One needs have/add to their configuration.yaml:

template: !include templates.yaml

How can I just get the max temperature of the current day?
I need it as attribute in a different sensor that is the templates.yaml

I’m trying to write some logic, I want to iterate the forecast values but I cannot seem to be able to use the return value.

description: ""
trigger:
  - platform: time
    at: "08:00:00"
action:
  - service: weather.get_forecasts
    data:
      type: hourly
    response_variable: hourly
    target:
      entity_id: weather.smhi_weather
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - variables:
      max_temp_time: >
        {% set forecast = hourly['weather.smhi_weather'].forecast %}
        {% set max_temp = 20 %} {% set max_temp_time = None %} {% set
        highest_temp = -1000 %} {% for entry in forecast %}
          {% if entry.temperature > max_temp %}

This line here is not working:
{% set forecast = hourly['weather.smhi_weather'].forecast %}
How do I access the forecast values?

Why do you think it’s not working?

Both the template and automation you have provided are incomplete, please post the full template and automation. It is unclear how you plan to use the variables you have set.

For the time of today’s max temperature you can use:

{% set local_days_end = (as_timestamp(today_at('23:59'))) | timestamp_utc %}
{% set forecast = hourly['weather.smhi_weather'].forecast | selectattr('datetime', 'lt', local_days_end) | list %}
{{ (forecast | sort(attribute='temperature', reverse=1) | first)['datetime'] | as_datetime | as_local }}
1 Like