Help with nested weather attribute condition

I would like to use the new 0.105 conditions on entity attributes feature. I have the AccuWeather integration installed, and would like to use today’s high as a condition. However, the integration gives highs for multiple days, all nested under Forecast (see screen shot). How would I access today’s high in a condition?

@Bieniu It looks like you might be the dev who created the AccuWeather integration. Thanks for your hard work! Any chance you can help with my question regarding using attributes as a condition?

Hi. To access temperature value for first day you have to use forecast[0].temperature, for second day forecast[1].temperature, etc. But I don’t know that there is possibility to use that as a trigger/condition.

You can always use template trigger/condition with these templates {{ states.weather.accuweather.attributes.forecast[0].temperature }} or {{ state_attr('weather.accuweather', 'forecast')[0].temperature }}.

Awesome! Thanks for your help @Bieniu! I created a new sensor:

  - platform: template
    sensors:
      todays_high_temperature:
        friendly_name: "Today's High Temperature"
        entity_id: weather.home
        value_template: >-
          {{ state_attr('weather.accuweather', 'forecast')[0].temperature }}

@Bieniu Any idea why I am receiving this error?

Log Details (ERROR)

Logger: homeassistant.components.accuweather
Source: helpers/update_coordinator.py:165
Integration: AccuWeather (documentation, issues)
First occurred: 7:41:29 AM (9 occurrences)
Last logged: 7:48:09 AM

Error fetching accuweather data: The allowed number of requests has been exceeded

Because you have exceeded the allowed number of requests. 50 requests per day are allowed. Integration consumes 45 queries a day, but each restart of HA is an additional request.

Hmmm… Is there any way to customize/configure the integration to have fewer requests per day?

No, integrations configured by config flow cannot have the option to change the update interval.

OK, thanks.

Just a thought… Can the integration count the number of requests it has made in a day, and then stop requesting when it approaches the max? That would make it a little more stable and prevent failures. I would think it would be better to be stuck with a slightly outdated forecast than no forecast at all. Not sure if that is possible, but just throwing the idea out there!

We know how many requeats are left. You can check this as you enable the debug log for AccuWeather. The problem is that AccuWeather counts the day in a strange way. The number of remaining requeats is not reset at midnight but 24 hours after the first request. Therefore, there is no way to calculate the dynamic update interval. It’s not possible to stop updating once the amount of requests is over.

Well that’s frustrating that they would do it that way! What if you configure the integration with a try/catch and fall back to the last successful forecast on failure?

It’s not allowed in HA. If the service doesn’t provide new data, the entities should become unavailable.

I really want to use this integration. I love all of the sensors/attributes it has. But if it can fail at any time due to a bunch of HA restarts, it is going to be unreliable. I’m sure you know yaml much better than I do… Do you have any suggestions for ways of handling this on my end? I’m thinking something along the lines of (pseudo code here):

If AccuWeather has a value
  Use AccuWeather sensor
Else
  Use some other sensor

You can use:

{% if not is_state('weather.accuwearher', 'unknown') and not is_state('weather.accuwearher', 'unavailable')%}
use value from accuweather
{% else %}
use another value
{% endif %}
1 Like

Works perfectly. Thanks for all of your help @Bieniu !

Hi @Bieniu! Quick question for you. It was raining here, so I decided to check out the AccuWeather integration to see how accurate it was. I noticed that the state of weather.accuweather was cloudy, but the forecast condition for the current day was rainy. Just curious why they are different? Does the forecast condition of “rainy” mean that rain is expected sometime today, while the state of “cloudy” is supposed to be the current condition (even though it happened to be wrong at the time)?

rainy is a forecast for the whole day, cloudy is the current condition.

1 Like