Automating based on openweathermap forecast temperature

With Openweathermap, how do I find the “6 hours from now” temperature?

Openweathermap testing

I have a card (see “Other details” below) that displays multiple future temperatures. However I’m not sure how to retrieve exactly one of these future temperatures.

Credits to another post with a comment that is close to what I want.

Test query

{{states.weather.openweathermap.attributes}}

{{state_attr('weather.openweathermap','supported_features')}}

Test output

{'temperature': 60, 'apparent_temperature': 58, 'temperature_unit': <UnitOfTemperature.FAHRENHEIT: '°F'>, 'humidity': 68, 'cloud_coverage': 8, 'pressure': 29.83, 'pressure_unit': <UnitOfPressure.INHG: 'inHg'>, 'wind_bearing': 210, 'wind_gust_speed': 5.99, 'wind_speed': 1.99, 'wind_speed_unit': <UnitOfSpeed.MILES_PER_HOUR: 'mph'>, 'visibility_unit': <UnitOfLength.MILES: 'mi'>, 'precipitation_unit': <UnitOfPrecipitationDepth.INCHES: 'in'>, 'attribution': 'Data provided by OpenWeatherMap', 'friendly_name': 'OpenWeatherMap', 'supported_features': <WeatherEntityFeature.FORECAST_HOURLY: 2>}

2

Test next

How do I query beyond that “2”?

Other details

Openweathermap card source

 - show_current: false
    show_forecast: true
    type: weather-forecast
    entity: weather.openweathermap
    forecast_type: hourly

Openweathermap rendered card

Use case

I see there’s a climate entity. Once I figure out how to query the future temperature, presumably I’ll control the HVAC with that.

Here’s an example automation rule I am planning to set up:

  • If current thermostat mode is “heat”
    • If weather forecast for “6 hours from now” exceeds 70 degrees F
      • If current indoor temperature exceeds 70 degrees F
        • Set thermostat to “off”

The post you linked to is no longer a valid method by itself. The forecast attribute was deprecated more than 7 months ago because of issues it was causing with database bloat.

You will need to use the weather.get_forecasts service. Templating will be required to get the forecast value 6 hours in the future. If you search the forum for “weather.get_forecasts” you will find a bunch of examples of how to use the service and examples of templating to get specific data points.

If you share the automation or script you are planning to use we can help you figure out how to incorporate the service call and templates.

1 Like

Do you mind linking to one of these examples? The search hits I looked at left me even more confused.

Is there a template variable that I can use to get started? Is that approach even possible/advisable? I tried these:

{{ weather.get_forecasts }}
gives error
UndefinedError: 'weather' is undefined

{{ states.weather.get_forecasts }}
renders as
None

Or if you prefer video tutorials: https://www.youtube.com/watch?v=zrWqDjaRBf0

HA Docs: weather.get_forecasts service

HA Docs: Trigger-based Template Sensors

HA Docs: Using templates to handle response data

1 Like