Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer see 'forecast' in attributes of PirateWeather weather. entities #157

Closed
7 tasks done
pbohannon opened this issue Dec 4, 2023 · 22 comments
Closed
7 tasks done
Labels
documentation Improvements or additions to documentation

Comments

@pbohannon
Copy link

Describe the issue

Hi there - I'm reluctant to post this because I'm sure I'm missing something obvious, but I'm stuck. :) Since the recent update through HACS, and a recent upgrade to HA (versions input below), I can no longer access the forecast dict from within the weather entities. Typically I would use state_attrs('weather.pirateweather', 'forecast')[0] etc., but forecast simply doesn't appear as an attribute anymore. I did see a note in the HACS upgrade about a breaking change, but I can't seem to find that note anywhere as it probably contains the key. I've tried to read through the code itself as well as track down the "new way of doing things in HA" but still can't find anything obvious. Any ideas? Thanks very much!

FWIW, here are the attributes shown via Developer Tools:
friendly_name: pirateweather_templow_5d
weather.pirateweather
PirateWeather
cloudy temperature: 50
temperature_unit: °F
humidity: 94
ozone: 312.32
pressure: 29.65
pressure_unit: inHg
wind_bearing: 134
wind_speed: 8.99
wind_speed_unit: mph
visibility: 7.58
visibility_unit: mi
precipitation_unit: in
attribution: Powered by Pirate Weather
friendly_name: PirateWeather
supported_features: 3

Home Assistant version

2023.12.0b2

Integration version

1.3.4

Troubleshooting steps

  • I have updated my Home Assistant installation to the latest version.
  • I have updated the Pirate Weather Integration to the latest version.
  • I have gone through the documentation, parameter documentation and sensor documentation before opening this issue.
  • I have searched this repository and Pirate Weather Repository to see if the issue has already been reported.
  • I have restarted my Home Assistant installation.
  • I have checked to see if the issue is not an API issue.
  • I have written an informative title.
@cloneofghosts cloneofghosts added the documentation Improvements or additions to documentation label Dec 4, 2023
@Ameglialuna
Copy link

same here

@alexander0042
Copy link
Collaborator

Thanks for using this integration and opening an issue! I was worried this would be a problem, but it's a change in HA and I'm not sure how to work around it without causing a ton of warnings. Two solutions here:

  1. Create a template from a service following this tutorial: https://github.com/hg1337/homeassistant-dwd/blob/f47840bfade5ed21781843542674f7ccb6be0ba3/questions_and_answers.md#how-can-i-access-forecast-data-from-templates
  2. Create individual sensors for the parameters you want. This clutters up the entities page, but otherwise just creates simple numeric sensors that return the forecast data

@Ameglialuna
Copy link

Ameglialuna commented Dec 5, 2023

For me solution 2, creating a sensor, would be fine but I didn't understand how to get the forecast data.
In developer tools I only see the following data, just like @pbohannon:

State:

clear-night

Attributes:

temperature: 1.1
temperature_unit: °C
humidity: 91
ozone: 306.07
pressure: 969.38
pressure_unit: hPa
wind_bearing: 355
wind_speed: 9.18
wind_speed_unit: km/h
visibility: 16.09
visibility_unit: km
precipitation_unit: mm
attribution: Powered by Pirate Weather
friendly_name: PirateWeather
supported_features: 3

@pbohannon
Copy link
Author

pbohannon commented Dec 5, 2023 via email

@martini1992
Copy link

I'm still confused as to what to do. I was using this YAML to draw a 48hr precip_probability graph (helps when hanging washing outside to dry) but of course it now doesn't work. Apex-charts can't call services, how would i use a template sensor to package up that data to display in the graph?

type: custom:apexcharts-card
graph_span: 50h
apex_config:
  chart:
    height: 150px
  xaxis:
    labels:
      format: hht
span:
  start: hour
  offset: '-2h'
now:
  show: true
  label: Now
header:
  show: true
  title: Rain Probability
yaxis:
  - max: 100
    decimals: 0
    apex_config:
      tickAmount: 5
cache: false
series:
  - entity: weather.pirateweather_home_hourly
    stroke_width: 3
    type: line
    color: '#9fc5e8'
    data_generator: |
      return entity.attributes.forecast.map((record, index) => {
              return [record.datetime, record.precipitation_probability];
            });

@pbohannon
Copy link
Author

pbohannon commented Dec 7, 2023 via email

@cloneofghosts
Copy link
Collaborator

cloneofghosts commented Dec 7, 2023

I'm also interested in something like this as the weather card that I use is not updated to use the new get_forecast service. I followed the steps in the first link that @alexander0042 shared but it doesn't seem to work for my card. I'll share what I have setup in case it's useful to anyone.

The code goes in a templates.yaml file and you need to include template: !include templates.yaml in configuration.yaml.

- trigger:
    - platform: time_pattern
      minutes: "/30"
  action:
    - service: weather.get_forecast
      target:
        entity_id: weather.pirateweather
      data:
        type: hourly
      response_variable: hourly_forecast
    - service: weather.get_forecast
      target:
        entity_id: weather.pirateweather
      data:
        type: daily
      response_variable: daily_forecast
  sensor:
    - name: "Pirate Weather Hourly"
      unique_id: pirateweather_hourly
      state: "{{ states('weather.pirateweather') }}"
      attributes:
        temperature: "{{ state_attr('weather.pirateweather', 'temperature') }}"
        temperature_unit: "{{ state_attr('weather.pirateweather', 'temperature_unit') }}"
        humidity: "{{ state_attr('weather.pirateweather', 'humidity') }}"
        pressure: "{{ state_attr('weather.pirateweather', 'pressure') }}"
        pressure_unit: "{{ state_attr('weather.pirateweather', 'pressure_unit') }}"
        wind_bearing: "{{ state_attr('weather.pirateweather', 'wind_bearing') }}"
        wind_speed: "{{ state_attr('weather.pirateweather', 'wind_speed') }}"
        wind_speed_unit: "{{ state_attr('weather.pirateweather', 'wind_speed_unit') }}"
        visibility: "{{ state_attr('weather.pirateweather', 'visibility') }}"
        visibility_unit: "{{ state_attr('weather.pirateweather', 'visibility_unit') }}"
        forecast: "{{ hourly_forecast.forecast[:24] }}"
    - name: "Pirate Weather Daily"
      unique_id: pirateweather_daily
      state: "{{ states('weather.pirateweather') }}"
      attributes:
        temperature: "{{ state_attr('weather.pirateweather', 'temperature') }}"
        temperature_unit: "{{ state_attr('weather.pirateweather', 'temperature_unit') }}"
        humidity: "{{ state_attr('weather.pirateweather', 'humidity') }}"
        pressure: "{{ state_attr('weather.pirateweather', 'pressure') }}"
        pressure_unit: "{{ state_attr('weather.pirateweather', 'pressure_unit') }}"
        wind_bearing: "{{ state_attr('weather.pirateweather', 'wind_bearing') }}"
        wind_speed: "{{ state_attr('weather.pirateweather', 'wind_speed') }}"
        wind_speed_unit: "{{ state_attr('weather.pirateweather', 'wind_speed_unit') }}"
        visibility: "{{ state_attr('weather.pirateweather', 'visibility') }}"
        visibility_unit: "{{ state_attr('weather.pirateweather', 'visibility_unit') }}"
        forecast: "{{ daily_forecast.forecast[:7] }}"

@DaveDixon
Copy link

What @Ameglialuna said - forecast is no longer available in the dropdown in the integration. Right now, for whatever reason, the PirateWeather integration is not working at all. I could use the forecast from Norwegian (complicated to parse) or National Weather Service (even more complicated to parse). What's the issue with HA? Something I can do to help?

@alexander0042
Copy link
Collaborator

@cloneofghosts, what card are you trying to display this in? I tried it with a couple options and your syntax seems to be correct, since I'm seeing everything populate correctly. Only thing I haven't tested is the updating, but I should know if that's working in a couple hours

@cloneofghosts
Copy link
Collaborator

@alexander0042 I'm using this card https://github.com/Makin-Things/platinum-weather-card. I don't have the error message handy at the moment but it was something along the lines of things needing to be a number. It's probably something to do with the card I'm using and nothing to do with the template.

@pbohannon
Copy link
Author

pbohannon commented Dec 11, 2023 via email

@alexander0042
Copy link
Collaborator

@cloneofghosts Looked into platinum weather card and it seems to be a larger issue with it: Makin-Things/platinum-weather-card#90. It's doing some sort of funky manual attribute name parsing instead of indexing, and that's what's creating the issue here.

@pbohannon, did you try using the template+service setup? That creates a new sensor with attributes that match the old one, and should work more or less the same. When I tested it I got a list that looked like the old one, so curious if that works for you?

@pbohannon
Copy link
Author

pbohannon commented Dec 11, 2023 via email

@cloneofghosts
Copy link
Collaborator

@cloneofghosts Looked into platinum weather card and it seems to be a larger issue with it: Makin-Things/platinum-weather-card#90. It's doing some sort of funky manual attribute name parsing instead of indexing, and that's what's creating the issue here.

Figured it was likely something with the card and nothing to do with the template. The dev doesn't seem to be particularly active anymore so I might have to switch to a new card.

@pbohannon I've created a template which you can modify to suit your needs here #157 (comment). If you don't need the current data you can remove everything but the forecast attribute.

@luberk8
Copy link

luberk8 commented Dec 17, 2023

@cloneofghosts Looked into platinum weather card and it seems to be a larger issue with it: Makin-Things/platinum-weather-card#90. It's doing some sort of funky manual attribute name parsing instead of indexing, and that's what's creating the issue here.

Figured it was likely something with the card and nothing to do with the template. The dev doesn't seem to be particularly active anymore so I might have to switch to a new card.

@pbohannon I've created a template which you can modify to suit your needs here #157 (comment). If you don't need the current data you can remove everything but the forecast attribute.

I'm trying to use your template and am getting a hourly_forecast is undefined error. Any ideas why?

@cloneofghosts
Copy link
Collaborator

@luberk8 I have the same template setup in my install and it's working for me without any issues. If you look at the template entity attributes does it show anything under forecast? The template is setup to refresh every 30 minutes so it could be that the data wasn't initialized when you tried to use it.

@luberk8
Copy link

luberk8 commented Dec 18, 2023

Yeah, definitely something is wrong on my setup. I was just wondering if you had any ideas.
Found this in the logs
Error rendering state template for sensor.pirate_weather_hourly: UndefinedError: 'dict object' has no attribute 'forecast'

The only attribute the sensor entity has is a "friendly name". Also changed the time interval to 1 min and waited 30

@iamjoshk
Copy link

HA changed the service call to weather.get_forecasts in 2023.12, so template sensors need to be updated.

Here is a template I am using now in my configuration.yaml:

template:
  - trigger:
      - platform: time_pattern
        hours: /1
    action:
      - service: weather.get_forecasts
        data:
          type: daily
        target:
          entity_id: weather.pirateweather
        response_variable: daily
    sensor:
      - name: Daily Weather Forecast
        unique_id: daily_weather_forecast
        state: "{{ as_timestamp(daily['weather.pirateweather'].forecast[0].datetime)|timestamp_custom('%m-%d-%Y') }}"
        attributes:
          high_temp: >
            {{ daily['weather.pirateweather'].forecast[0].temperature }}
          low_temp: >
            {{ daily['weather.pirateweather'].forecast[0].templow }}
          condition: >
            {{ (daily['weather.pirateweather'].forecast[0].condition|title) }}
          precip_prob: >
            {{ (daily['weather.pirateweather'].forecast[0].precipitation_probability|string)[:-2] }}
          humidity: >
            {{ daily['weather.pirateweather'].forecast[0].humidity }}
          tomorrow_temp: >
            {{ daily['weather.pirateweather'].forecast[1].temperature }}
          tomorrow_low: >
            {{ daily['weather.pirateweather'].forecast[1].templow }}
          tomorrow_precip: >
            {{ (daily['weather.pirateweather'].forecast[1].precipitation_probability|string)[:-2] }}
          tomorrow_condition: >
            {{ (daily['weather.pirateweather'].forecast[1].condition|title) }}
          tomorrow_humidity: >
            {{ daily['weather.pirateweather'].forecast[1].humidity }}
          tomorrow_date: >
            {{ as_timestamp(daily['weather.pirateweather'].forecast[1].datetime)|timestamp_custom('%m-%d-%Y') }}

This results in a state with today's date formatted MM-DD-YYYY and the following attributes for today and tomorrow:

high_temp: 53
low_temp: 33
condition: Rainy
precip_prob: 80
humidity: 81
tomorrow_temp: 37
tomorrow_low: 31
tomorrow_precip: 1
tomorrow_condition: Partlycloudy
tomorrow_humidity: 79
tomorrow_date: 12-19-2023

@alexander0042
Copy link
Collaborator

Ugh, good catch here. At least it should be an easy change, but still irritating to have to test everything again.

I'll update my dev instance over to 2023.12 shortly and double check, then add a note to update the docs with this tempting stuff!

@cloneofghosts
Copy link
Collaborator

I updated my templates to the following to get the daily/hourly forecast sensors using weather.get_forecasts

- trigger:
    - platform: time_pattern
      minutes: "/30"
  action:
    - service: weather.get_forecasts
      data:
        type: daily
      target:
        entity_id: weather.pirateweather
      response_variable: daily
  sensor:
    - name: Pirate Weather Daily
      unique_id: pirateweather_daily
      state: "{{ daily['weather.pirateweather'].forecast[0].condition }}"
      attributes:
        forecast: "{{ daily['weather.pirateweather'].forecast }}"
- trigger:
    - platform: time_pattern
      minutes: "/30"
  action:
    - service: weather.get_forecasts
      data:
        type: hourly
      target:
        entity_id: weather.pirateweather
      response_variable: hourly
  sensor:
    - name: Pirate Weather Hourly
      unique_id: pirateweather_hourly
      state: "{{ hourly['weather.pirateweather'].forecast[0].condition }}"
      attributes:
        forecast: "{{ hourly['weather.pirateweather'].forecast[:24] }}"

I found this thread on the HA forums useful in getting this setup https://community.home-assistant.io/t/new-weather-forecast-template/622642/

@johnpez
Copy link

johnpez commented Dec 30, 2023

Thank you for the fix @cloneofghosts and everyone else! Worked like a charm.

@cloneofghosts
Copy link
Collaborator

I've went ahead and updated the HA documentation page with the template and some information regarding the change.

I'm going to close this for now but if you're still having issues feel free to create a new issue.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
Development

No branches or pull requests

9 participants