forecast takes a list of days you want to track. Each day you add here will be a new sensor with all of the monitored conditions. Same with hourly.
So if you add precip_probability and precip_intensitiy, you’ll get 2 sensors for each forecast day (or hourly) you added.
Getting future predictions is easy, it’s built into the sensor! But, I don’t think they have the time machine part integrated. https://darksky.net/dev/docs#time-machine-request I think that would be pretty useful to have (allow users to put in negative days for the forecast to get X days ago reports).
Because of no past history, I’d create an input_boolean which turns on if it rains. This boolean will turn off at the 5am automation that checks if the sprinkler should turn on.
sensor:
- platform: darksky
api_key: YOUR_API_KEY
forecast:
- 0
- 1
hourly_forecast:
- 0
- 1
monitored_conditions:
- precip_intensity
- precip_type
- precip_probability
Feel free to add more days/hours and monitored conditions for other things.
precip_intensity is the current precipitation in mm/hr. We will check this periodically to turn on the input_boolean if it is raining.
input_boolean:
rained_yesterday:
name: Rainfall yesterday
icon: mdi:weather-pouring
Now create an automation that turns that on the boolean if it rains.
- 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'
# If there was no accumulation, nothing to do.
- condition: template
value_template: "{{ not is_state('sensor.dark_sky_precip_accumulation_0h', 'unknown') }}"
# Only care about rain...not snow
# This may be redundant with the above...but shouldn't hurt, right?
# Valid values are 'snow', 'rain', 'sleet'.
- condition: template
value_template: "{{ is_state('sensor.dark_sky_precip_0h', 'rain') }}"
- condition: numeric_state
entity_id: 'sensor.dark_sky_precip_intensity_0h'
# Check https://water.usgs.gov/edu/activity-howmuchrain-metric.html to see how much rain
# we consider enough to call it 'raining'.
# Anything above 0.5mm/hr is 'moderate rain'.
above: 0.5
action:
# It rained today. Turn this on.
service: input_boolean.turn_on
entity_id: input_boolean.rain_meter
OK, now that boolean should turn on if it rains more than 0.5mm/hr any given hour. You can tweak this algorithm to turn on in any method. It is decoupled from the next part so that you can upgrade the weather sensor or algorithms and still leave the next automation the same. (Though, I say that and realize the next automation will be checking the future weather for rain…)
- alias: Sprinkler Time
name: Turn on sprinkler if no rain.
trigger:
platform: time
# Check at 530 am
at: "05:30:00"
condition:
# If it's going to rain today, there's nothing to do. Just leave the
# input_boolean.rain_meter on since today already counts as rain.
platform: template
# Check the 1d for the current day's forecast. The prcip_intensity uses
# should use the current day's precip_probability to determine a value...
# but I'm not exactly sure. Might just have to use the precip_probability...
# Basically, if today's forecast says there will be moderate rain, don't do anything.
# Definately tweak this condition and test it out. Check this state in developer tools on
# a day when it's supposed to rain and see what this value reports.
value_template: "{{ states('sensor.dark_sky_precip_intensity_1d') | float > 0.5 }}"
action:
# It's easier to let a script do the sequence for us since we can pass in a variable that
# will have it's scope valid for the entire script.
# If we'd have to try to get fancy with service_templates and conditions.
service: script.turn_on_sprinklers_if_no_rain
data_template:
# Pass in True or False if it rained yesterday.
rain_yesterday: "{{ is_state('input_boolean.rain_meter', 'on') }}"
script:
turn_on_sprinklers_if_no_rain:
sequence:
# In ALL conditions, turn off this boolean. Even if it's off, doesn't matter.
# The state of it is preserved in {{ rain_yesterday }} data field.
- service: input_boolean.turn_off
entity_id: input_boolean.rain_meter
- condition: template
# If this condition evaluates to false, this script will exit.
# So if there was no rain yesterday, we want to continue.
value_template: "{{ not rain_yesterday}}"
# If we made it here, it didn't rain yesterday. This script doesn't check the
# current day weather, we leave that up to the automation.
# But you could just as easily add it here instead.
# TODO: Update this service call to actually turn on your sprinkerls.
- service: sprinkler.turn_on
entity_id: sprinklers.money_maker
Future Enhancements:
-
You could set another input boolean for if it’s going to rain today. This would decouple your entire automation from the weather sensor and have it tied to these 2 input booleans. I like doing this so that I can update/enhance just the weather part while leaving the sprinkler automation/script alone. But it’s not too important.
-
Could find a better way to get past weather. There might be one that gives previous day’s weather. In this case, you could remove the input booleans and simply query the one sensor for yesterday and today’s weather.