Knowing if it will rain today is a crucial question for many, impacting daily plans and activities. This article outlines a method to use Dark Sky weather data within Home Assistant to determine if rain is expected and automate actions based on the forecast.
Dark Sky’s API allows for retrieving both current and future weather conditions. You can specify the number of days and hours to include in the forecast, along with the specific weather parameters you want to track, such as precipitation probability and intensity. This allows for granular control over the data received.
sensor:
- platform: darksky
api_key: YOUR_API_KEY
forecast:
- 0
- 1
hourly_forecast:
- 0
- 1
monitored_conditions:
- precip_intensity
- precip_type
- precip_probability
Since Dark Sky doesn’t provide historical data, an input boolean is used to track whether it rained the previous day. This boolean will be set by an automation and reset each morning.
input_boolean:
rained_yesterday:
name: Rainfall yesterday
icon: mdi:weather-pouring
An automation triggers every hour and 15 minutes to check the current precipitation intensity. If the intensity exceeds a predefined threshold (e.g., 0.5 mm/hr, indicating moderate rain), the “rained_yesterday” boolean is set to true.
- alias: rain_meter
trigger:
# Run every 1h 15 minutes.
platform: time_pattern
hours: "/1"
minutes: "15"
conditions:
# No need to do anything if this is already on
- condition: state
entity_id: input_boolean.rain_meter
state: 'off'
# ... other conditions for validating rain ...
action:
# It rained today. Turn this on.
service: input_boolean.turn_on
entity_id: input_boolean.rain_meter
A separate automation, scheduled for 5:30 AM, checks the forecast for the current day. If the predicted precipitation intensity is above the threshold, indicating a likelihood of rain, no action is taken. This assumes that if rain is predicted for today, the “rained_yesterday” boolean remains relevant.
- alias: Sprinkler Time
name: Turn on sprinkler if no rain.
trigger:
platform: time
at: "05:30:00"
condition:
platform: template
value_template: "{{ states('sensor.dark_sky_precip_intensity_1d') | float > 0.5 }}"
action:
service: script.turn_on_sprinklers_if_no_rain
data_template:
rain_yesterday: "{{ is_state('input_boolean.rain_meter', 'on') }}"
Finally, a script manages the sprinkler logic. It first resets the “rained_yesterday” boolean. If this boolean was false (indicating no rain yesterday), and today’s forecast doesn’t predict rain, the script activates the sprinklers.
script:
turn_on_sprinklers_if_no_rain:
sequence:
- service: input_boolean.turn_off
entity_id: input_boolean.rain_meter
- condition: template
value_template: "{{ not rain_yesterday}}"
- service: sprinkler.turn_on
entity_id: sprinklers.money_maker
This system provides a robust solution for answering the question “Will it rain today?” and automating tasks like sprinkler control based on the answer. Using predicted precipitation intensity helps to anticipate rainfall and avoid unnecessary watering.