Predicting Rain with Home Assistant and Dark Sky

Knowing if it’s going to rain today is crucial for planning your day. This guide shows you how to use Dark Sky weather data in Home Assistant to predict rain and automate tasks like sprinkler control.

Dark Sky’s API provides current and future weather conditions. You can customise the forecast duration, and select specific data points like precipitation probability and intensity.

sensor:
  - platform: darksky
    api_key: YOUR_API_KEY
    forecast:
      - 0
      - 1
    hourly_forecast:
      - 0 
      - 1
    monitored_conditions:
      - precip_intensity
      - precip_type
      - precip_probability

As Dark Sky doesn’t offer historical data, an input boolean tracks yesterday’s rainfall. This boolean is set by an automation and resets each morning.

input_boolean:
  rained_yesterday:
    name: Rainfall yesterday
    icon: mdi:weather-pouring

An automation runs every hour and 15 minutes to check current precipitation intensity. If it exceeds a threshold (e.g., 0.5 mm/hr for 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

Another automation, scheduled for 5:30 AM, checks the daily forecast. If predicted rainfall exceeds the threshold, no action is taken, assuming yesterday’s rainfall status 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 resets the “rained_yesterday” boolean. If no rain yesterday and no rain predicted today, the sprinklers activate.

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 reliably predicts rain and automates tasks like sprinkler control based on the forecast, preventing unnecessary watering.

Leave A Comment

Name*
Message*