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!