How to handle deprecation of the weather forecast attribute for Plotly card?

Hello!

I am posting regarding the deprecation of the weather “forecast” attribute.

I created a Plotly graph to display the forecast from several different weather integrations. I based it off of this example:

The Plotly configuration uses the “forecast” attribute to obtain the forecast info as shown in the following example:

- entity: weather.my_weather
    unit_of_measurement: °F
    filters:
      - fn: |-
          ({ meta, vars }) => ({
            xs: [...meta.forecast.map(({ datetime }) => new Date(datetime))],
            ys: [...meta.forecast.map(({ temperature }) => temperature)],
          })

How can I do this once the “forecast” attribute is no more and I must use the weather.get_forecast service?

Thanks!

I donot know how to use the get_forecast in plotly, might be working but not sure… I just created a forecast sensor and use that…

After some digging, I found the solution. I can use a template sensor:

template:
  - trigger:
      - platform: time_pattern
        hours: /1
    action:
      - service: weather.get_forecast
        data:
          type: hourly
        target:
          entity_id: weather.home
        response_variable: hourly
    sensor:
      - name: Weather Forecast Hourly
        unique_id: weather_forecast_hourly
        state: "{{ now().isoformat() }}"
        attributes:
          forecast: "{{ hourly.forecast }}"

Thanks!

1 Like

cool… thank you!
same issue here… Now , I’ve created the new sensor that includes the forecast info. it has all the data

But how do you replace the code you mentioned at the beginning with “new version” to keep Plotly working as before?
filters:
- fn: |-
({ meta, vars }) => ({
xs: […meta.forecast.map(({ datetime }) => new Date(datetime))],
ys: […meta.forecast.map(({ temperature }) => temperature)],
})

thanks!

Here’s what I’ve done

In configuration.yaml

template:
  - trigger:
      - platform: state
        entity_id:
          - weather.weather_channel
    action:
      - service: weather.get_forecasts
        data:
          type: hourly
        target:
          entity_id: weather.weather_channel
        response_variable: hourly
    sensor:
      - name: Weather Channel Forecast Hourly
        unique_id: weather_channel_forecast_hourly
        state: "{{ now() }}"
        attributes:
          forecast: "{{ hourly['weather.weather_channel'].forecast }}"

(note that since the get_forecasts service places the forecast under hourly > ‘weather.weather_channel’ which itself contains a period, I have to use square bracket indexing [ … ] instead of the dot (.) operator to access the forecast list. “hourly.weather.weather_channel.forecast” will not work)

In the chart card

- entity: sensor.weather_channel_forecast_hourly
    unit_of_measurement: °F
    filters:
      - fn: |-
          ({ meta, vars }) => ({
            xs: [...meta.forecast.map(({ datetime }) => new Date(datetime))],
            ys: [...meta.forecast.map(({ temperature }) => temperature)],
          })
3 Likes

thank you so much!! working again!

Hi there,

I’m quite new to HA and I’m fighting with basic things. I can’t place the yaml code in the configuration.yaml because I have automations.yaml and templates.yaml. How could I split this code in both files?

Thank you in advance

Can you show us the part of your configuration.yaml that incorporates the other 2 .yaml files?

I’m not sure what you mean. I have nothing in the configuration.yaml. I just copied the code from Weather forecast plot (`meta` and nested attributes) · dbuezas/lovelace-plotly-graph-card · Discussion #213 · GitHub in a new card and I’m getting an error when trying to add the template sensor in the configuration.yaml, I suppose because I have automations in the automations.yaml file and templates in the template.yaml file.

I would like to place this code in the templates.yaml file:


# in your configuration.yaml

# from https://community.home-assistant.io/t/how-to-handle-deprecation-of-the-weather-forecast-attribute-for-plotly-card/626002/5?u=fillr
# by Arrow1024
template:
  - trigger:
      - platform: state
        entity_id:
          - weather.weather_channel
    action:
      - service: weather.get_forecasts
        data:
          type: hourly
        target:
          entity_id: weather.weather_channel
        response_variable: hourly
    sensor:
      - name: Weather Channel Forecast Hourly
        unique_id: weather_channel_forecast_hourly
        state: "{{ now() }}"
        attributes:
          forecast: "{{ hourly['weather.weather_channel'].forecast }}"

Finally I was able to add the code to templates.yaml. but I´m getting this error:

Error: at [entities.1.filters.0]: Error in filter: TypeError: Cannot read properties of undefined (reading ‘map’)
Error: at [entities.3.filters.0]: Error in filter: TypeError: Cannot read properties of undefined (reading ‘map’)