Need a little guidance getting my weather working again-- getting unavailable

Hello all,

I’m hoping the screenshots/ code post below will help someone help me get this rewritten to where my sensor will start working again. I think this has something to do with the weather changes that were made to home assistant months ago but I’m not completely sure.

Thank you all for your help.

In my weather package:

 - platform: template
    sensors:
      current_forecast:
        friendly_name: Current Forecast
        # #unit_of_measurement: ""
        icon_template: mdi:weather-sunny
        value_template: >-
          {% set forecast = state_attr('weather.home_accuweather','forecast')[0] %}
          {{ forecast.condition }}
        attribute_templates:
          high_temp: >-
            {% set forecast = state_attr('weather.home_accuweather','forecast')[0] %}
            {{ forecast.temperature }}
          overnight_low: >-
            {% set forecast = state_attr('weather.home_accuweather','forecast')[1] %}
            {{ forecast.templow }}
          wind_bearing: >-
            {% set forecast = state_attr('weather.home_accuweather','forecast')[0] %}
            {{ forecast.wind_bearing }}
          wind_speed: >-
            {% set forecast = state_attr('weather.home_accuweather','forecast')[0] %}
            {{ forecast.wind_speed }}
          precipitation: >-
            {% set forecast = state_attr('weather.home_accuweather','forecast')[0] %}
            {{ forecast.precipitation }}

If possible, I would like to stick with the same way of calling things out instead of switching to going straight to individual entities (second screenshot)

Thank you all again for any guidance you can give!

Yes, it is 100% to do with the changes made quite some time ago but forced in 2024.5, there is no longer a forecasts attribute on weather entities. You have to fetch the forecast with get_forecasts instead. It actually makes it tricky because you can’t test it in Developer for a script, you have to noodle it out.

What I did is just replicate the old method by creating a sensor that fetches the forecast and then populates attributes that I then use in other scripts and sensors:

trigger:
  - platform: time_pattern
    minutes: /5
  - platform: homeassistant
    event: start

action:
  - service: weather.get_forecasts
    data:
      type: daily
    target:
      entity_id: weather.openweathermap
    response_variable: owm_daily

sensor:
  - name: Forecasts
    state: "{{ now().isoformat() }}"

    attributes:
      forecast: >-
        {{ owm_hourly['weather.openweathermap'].forecast }}

I’m sorry that I don’t know what I’m doing :frowning: Is the below correct or not at all?

  - platform template:
  - trigger:
      - platform: time_pattern
        hours: /1
    action:
      - service: weather.get_forecasts
        data:
          type: twice_daily
        target:
          entity_id: weather.home_accuweather
        response_variable: x
    sensor:
      - name: Current Forecast
        state: "{{ now().isoformat() }}"
        attributes:
          forecast: >-
            {{ x['weather.home_accuweather'].forecast }}
          temperature: >-
            {{ x['weather.home_accuweather'].forecast.temperature }}
          templow: >-
            {{ x['weather.home_accuweather'].forecast.templow }}
          wind_bearing: >-
            {{ x['weather.home_accuweather'].forecast.wind_bearing }}
          wind_speed: >-
            {{ x['weather.home_accuweather'].forecast.wind_speed }}
          precipitation: >-
            {{ x['weather.home_accuweather'].forecast.precipitation }}  

Below is how developer tools responds when I do “get forecast” for accuweather:

forecast:
  - datetime: "2024-06-06T11:00:00+00:00"
    cloud_coverage: 56
    precipitation_probability: 70
    uv_index: 8
    wind_bearing: 236
    condition: lightning-rainy
    temperature: 81
    apparent_temperature: 87
    templow: 61
    wind_gust_speed: 17.27
    wind_speed: 8.08
    precipitation: 0.17
  - datetime: "2024-06-07T11:00:00+00:00"
    cloud_coverage: 26
    precipitation_probability: 4
    uv_index: 11
    wind_bearing: 291
    condition: partlycloudy
    temperature: 78
    apparent_temperature: 83
    templow: 55
    wind_gust_speed: 27.59
    wind_speed: 11.5
    precipitation: 0

That is mostly correct, just your formatting is off:

template:
  sensor:
    - trigger:

You can find an example of a trigger template sensor in the docs too if you are still confused:

So I don’t have to use this idea:

            {{ x['weather.home_accuweather'].forecast[0] }}

the bracket thing.

Yeah, I will have to look at the docs too probably. I am just not very good with this stuff at all. Most of what I have built was through copy pasting from others sadly. So when it breaks, I’m screwed.

the bracket idea? That wasn’t in my original post

Sorry, you need that if you are getting the FIRST forecast. Or you loop them. Forecast is the attribute and [0] is the first record on the list, so if you want to know what todays forecast is then it’s 0, tomorrow is 1, etc. If hourly then 0 is generally the next hour, then 1 the hour after, etc.

I’m following you now. See if the below makes since to you for “current forecast”:

  - template:
      sensor:
      - name: Current Forecast
        state: "{{ now().isoformat() }}"
        attributes:
          forecast: >-
            {{ x['weather.home_accuweather'].forecast[0] }}
          temperature: >-
            {{ x['weather.home_accuweather'].forecast[0].temperature }}
          templow: >-
            {{ x['weather.home_accuweather'].forecast[0].templow }}
          wind_bearing: >-
            {{ x['weather.home_accuweather'].forecast[0].wind_bearing }}
          wind_speed: >-
            {{ x['weather.home_accuweather'].forecast[0].wind_speed }}
          precipitation: >-
            {{ x['weather.home_accuweather'].forecast[0].precipitation }}  
            - trigger:
                - platform: time_pattern
                  hours: /1
              action:
                - service: weather.get_forecasts
                  data:
                    type: twice_daily
                  target:
                    entity_id: weather.home_accuweather
                  response_variable: x
Configuration warnings

Invalid config for 'sensor' at packages/weather.yaml, line 97: required key 'platform' not provided

I am getting the above when trying to check config.

Here is a screenshot of my studio code server:

Thank you again for helping me with this. This has been messed up for a while and I’m just now getting to trying to fix it.

Got this now:

Sorry I’m doing this in a package

  - platform: template
    sensor:
    - name: Current Forecast
      state: "{{ now().isoformat() }}"
      attributes:
        forecast: >-
          {{ x['weather.home_accuweather'].forecast[0] }}
        temperature: >-
          {{ x['weather.home_accuweather'].forecast[0].temperature }}
        templow: >-
          {{ x['weather.home_accuweather'].forecast[0].templow }}
        wind_bearing: >-
          {{ x['weather.home_accuweather'].forecast[0].wind_bearing }}
        wind_speed: >-
          {{ x['weather.home_accuweather'].forecast[0].wind_speed }}
        precipitation: >-
          {{ x['weather.home_accuweather'].forecast[0].preipitation }}  
          - trigger:
              - platform: time_pattern
                hours: /1
            action:
              - service: weather.get_forecasts
                data:
                  type: twice_daily
                target:
                  entity_id: weather.home_accuweather
                response_variable: x

That trigger is indented too far, please look at the doc link I posted and you’ll see the indention. If you are getting errors about the platform then you are using the legacy method:

sensor:
  - platform: template
    sensors:
      weather_day_one:
        ...your code

The method in the docs is the current way.

And, if you are doing in a package it’s a little different too. Just reformat things to be like they were before but using the new trigger and references to the variable the get_forecasts returns and you’ll be on track.

Yeah, this is cluster for sure.

I will look at the docs you linked and see if I can’t figure it out. I def feel like I’m trying to find a left handed baseball at the moment.

You can still use the legacy system (for now) so just replace your code with the new code and you should be OK. As always, back up before you do big changes. Although I am not 100% positive that the trigger works with the old way…