After a lot of trial and error, I finally figured out how to pull precipitation_probability from OpenWeatherMap, so I thought I’d share. This is the sensor I added to my configuration.yaml to get it to work after adding the OpenWeatherMap. It checks every 15 minutes, but you can adjust that.
template:
- trigger:
# Trigger every 15 minutes
- platform: time_pattern
minutes: "/15"
# Trigger on Home Assistant start for an immediate value
- platform: homeassistant
event: start
action:
# Call the weather service and store the response in a variable
- service: weather.get_forecasts
data:
type: hourly
target:
entity_id: weather.openweathermap
response_variable: hourly_forecast_data
sensor:
- name: "OpenWeatherMap Rain Probability Next Hour"
unique_id: openweathermap_rain_probability_next_hour
unit_of_measurement: "%"
state_class: measurement
icon: mdi:weather-pouring
# This state template calculates the rain probability
state: >
{% set forecast = hourly_forecast_data['weather.openweathermap'].forecast %}
{% if forecast is not none and forecast | length > 1 %}
{{ (forecast[1].precipitation_probability) | round(0) }}
{% else %}
unavailable
{% endif %}
# These attributes will be added to your sensor
attributes:
# This timestamp will update every 15 minutes, proving the sensor is working.
last_fetch: "{{ now().isoformat() }}"