home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.15k stars 29.83k forks source link

Sensor template for weather.get_forecasts appears to return a String instead of an array #123738

Closed mcowell closed 1 month ago

mcowell commented 1 month ago

The problem

Hello,

I have the following template for use with Tileboard to fetch hourly weather from Environment Canada.

template:      
  - trigger:                                              
      - platform: time_pattern
        hours: "/4"                                               
      - platform: homeassistant
        event: start
      - platform: event
        event_type: event_template_reloaded
    action:                   
      - service: weather.get_forecasts
        data:           
          type: daily
        target:                                                                                                
          entity_id: weather.ottawa_kanata_orleans
        response_variable: daily
    sensor:
      - name: Weather Forecast Daily
        unique_id: weather_forecast_daily
        state: "{{ states('weather.ottawa_kanata_orleans') }}"
        attributes:                                           
          temperature_unit: "{{ state_attr('weather.ottawa_kanata_orleans', 'temperature_unit') }}"
          forecast: "{{ daily['weather.ottawa_kanata_orleans'] }}"

Using the following

{{state_attr('sensor.weather_forecast_daily','forecast')}}

The above used to give me an array of objects back, but now I just get a string.

{'forecast': [{'datetime': datetime.datetime(2024, 8, 12, 15, 0, tzinfo=tzutc()), 'precipitation_probability': 30, 'condition': 'lightning-rainy', 'temperature': 22.0, 'templow': 13.0}, {'datetime': datetime.datetime(2024, 8, 13, 15, 0, tzinfo=tzutc()), 'precipitation_probability': 0, 'condition': 'sunny', 'temperature': 27.0, 'templow': 15.0}, {'datetime': datetime.datetime(2024, 8, 14, 15, 0, tzinfo=tzutc()), 'precipitation_probability': 30, 'condition': 'rainy', 'temperature': 28.0, 'templow': 14.0}, {'datetime': datetime.datetime(2024, 8, 15, 15, 0, tzinfo=tzutc()), 'precipitation_probability': 0, 'condition': 'sunny', 'temperature': 28.0, 'templow': 15.0}, {'datetime': datetime.datetime(2024, 8, 16, 15, 0, tzinfo=tzutc()), 'precipitation_probability': 0, 'condition': 'partlycloudy', 'temperature': 28.0, 'templow': 18.0}, {'datetime': datetime.datetime(2024, 8, 17, 15, 0, tzinfo=tzutc()), 'precipitation_probability': 60, 'condition': 'rainy', 'temperature': 24.0, 'templow': 18.0}]}

Thus, when I try to get the [0]th element of the above I get undefined since it is not actually an array. This becomes an issue on Tileboard as I try to iterate though the first nth elements of the forecast.

Seemingly another user ran into the issue here also : https://community.home-assistant.io/t/need-help-with-recent-daily-weather-forecast-error/759166

Please let me know if I can provide any more information or do any testing for you.

Thanks!

What version of Home Assistant Core has the issue?

core-2024.8.0

What was the last working version of Home Assistant Core?

core-2024.7.4

What type of installation are you running?

Home Assistant OS

Integration causing the issue

No response

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

PeteRager commented 1 month ago

This issue has no "integration causing the issue" hence it's unlikely anyone will look at it. Refile it against whatever weather integration you are using.

mcowell commented 1 month ago

Thanks! I refiled and I will close this issue.

mib1185 commented 1 month ago

123751