Since so many things have changed from my initial configuration post, from July 2017 Garden Irrigation I thought I’d post an update for those who want to configure their irrigation timers.
Significant changes affected:
- Front end with the intruduction of Lovelace UI
- New
input_datetime
component
- WUnderground that I updated to DarkSky
Withput much further ado here is the final look of the timer component in the standard view
and in a config view, after clicking the Config Timer
button.
clicking on Next Run
opens up a modal view of the input_datetime
component, such as this
For the UI, I’m using Lovelace yaml config.
configuration.yaml
lovelace:
mode: yaml
ui-lovelace.yaml
title: Home
views:
- type: vertical-stack
cards:
- type: entities
title: Sprinklers Front Shrubs
show_header_toggle: false
entities:
- sensor.last_run_front_shrubs
- sensor.next_run_front_shrubs
- sensor.duration_front_shrubs
- sensor.repeat_front_shrubs
- input_boolean.config_front_shrubs
- automation.activate_front_shrubs_timer
- type: conditional
conditions:
- entity: input_boolean.config_front_shrubs
state: "on"
card:
type: entities
title: Settings Front Shubs
show_header_toggle: false
entities:
- input_datetime.next_run_front_shrubs
- input_number.duration_front_shrubs
- input_number.repeat_front_shrubs
There are a few sensor
components that are not strictly needed. But I prefer to have a non-editable sensors on the day-to-day view screens, showing the next run and last run, rather than exposing their input_datetime
and input_number
components. These sensors purely mirror their editable counterparts.
and this is the config for these sensors (please note they need to be indented under a sensor
component)
configuration.yaml
- platform: template
sensors:
## Front Shrubs
next_run_front_shrubs_time:
value_template: '{{as_timestamp(states.input_datetime.next_run_front_shrubs.state) | timestamp_custom("%H:%M")}}'
friendly_name: "Time"
next_run_front_shrubs:
friendly_name: "Next Run"
value_template: '{{as_timestamp(states.input_datetime.next_run_front_shrubs.state) | timestamp_custom("%A, %d %h %H:%M")}}'
last_run_front_shrubs:
friendly_name: "Next Run"
value_template: '{{as_timestamp(states.input_datetime.last_run_front_shrubs.state) | timestamp_custom("%A, %d %h %H:%M")}}'
time_delta_front_shrubs:
friendly_name: "Front Shrubs Timedelta"
value_template: '{{states.input_number.repeat_front_shrubs.state|int * 3600}}'
duration_front_shrubs:
value_template: '{{states.input_number.duration_front_shrubs.state | int}}mins'
friendly_name: "Duration"
repeat_front_shrubs:
value_template: '{{ "{:02d}".format(states.input_number.repeat_front_shrubs.state|int)}}hrs'
friendly_name: "Repeat in"
For completeness here are input_number
components that I keep in
input_numbers/front_shrubs.yaml
duration_front_shrubs:
name: "Set Duration"
initial: 3
min: 0
max: 15
step: 1
icon: mdi:camera-timer
repeat_front_shrubs:
name: "Set Repeat"
initial: 48
min: 0
max: 48
icon: mdi:repeat
And the new input_datetime
components.
input_datetime/front_shrubs.yaml
next_run_front_shrubs:
name: Next Run
has_date: true
has_time: true
last_run_front_shrubs:
name: Last Run
has_date: true
has_time: true
There’s one more sensor that I use to modify wet or dry condition that will show later in automation. It takes rain probability and rain intensity from DarkSky and allows me to override it. Setting hard values has not worked for me, as sun intensity after a brief shower dried up the ground quickly, yet my sensor was still in “too wet” condition. So I can manually tweak it, so on the next scheduled irrigation, that can be on the same day the irrigation does kick in.
The view is:
UI code in ui-lovelace.yaml
- type: entities
title: Rainfall Sensitivity
show_header_toggle: false
entities:
- sensor.rain_sensor
- input_number.dark_sky_precip_probability_sensitivity
- input_number.dark_sky_precip_intensity_sensitivity
The code for the logic (I’m not showing the darksky
component)
input_number:
dark_sky_precip_intensity_sensitivity:
name: "Rainfall mm Sensitivity"
initial: 0.1
min: 0
max: 5
step: 0.1
icon: mdi:contrast
dark_sky_precip_probability_sensitivity:
name: "Rainfall Probability Sensitivity"
initial: 40
min: 0
max: 100
step: 10
icon: mdi:contrast
sensor:
- platform: template
sensors:
rain_sensor:
friendly_name: "Rainfall Threshold Sensitivity"
value_template: >-
{% if (states.sensor.dark_sky_precip_probability.state | float) <= (states.input_number.dark_sky_precip_probability_sensitivity.state | float) and (states.sensor.dark_sky_precip_intensity_0.state | float) <= (states.input_number.dark_sky_precip_intensity_sensitivity.state | float) %}
dry
{% else %}
too wet
{% endif %}
Automations and scripts.
In automation we are converting all values to timestamps, so we can calculate future, past or equality conditions. This part is quite tricky, as there’s very strict requirement for the values to be in a particular format. Please see https://www.home-assistant.io/components/input_datetime/ for details. Also very good article that covers datetime calculations is at The EPIC Time Conversion and Manipulation Thread!
automation:
- alias: "Activate Front Shrubs Timer"
trigger:
- platform: time_pattern
minutes: '/1'
condition:
condition: and
conditions:
- condition: template
value_template: '{{as_timestamp(now().strftime("%Y-%m-%d %H:%M")) == as_timestamp(states.input_datetime.next_run_front_shrubs.state)}}'
- condition: state
entity_id: sensor.rain_sensor
state: 'dry'
action:
- service: script.turn_on
entity_id: script.activate_irrigation_front_shrubs
- alias: "Extend Front Shrubs Timer When Wet"
trigger:
- platform: time_pattern
minutes: '/1'
condition:
condition: or
conditions:
- condition: template
value_template: '{{as_timestamp(now().strftime("%Y-%m-%d %H:%M")) > as_timestamp(states.input_datetime.next_run_front_shrubs.state)}}'
- condition: and
conditions:
- condition: template
value_template: '{{as_timestamp(now().strftime("%Y-%m-%d %H:%M")) == as_timestamp(states.input_datetime.next_run_front_shrubs.state)}}'
- condition: state
entity_id: sensor.rain_sensor
state: 'too wet'
action:
- service: script.turn_on
entity_id: script.update_front_shrubs_next_run_timer
And lastly my script part.
script:
activate_irrigation_front_shrubs:
alias: "Activate Irrigation Front Shrubs"
sequence:
- service: script.turn_on
entity_id: script.update_front_shrubs_next_run_timer
- service: script.turn_on
entity_id: script.update_front_shrubs_last_run_timer
- service: switch.turn_on
entity_id: switch.front_shrubs_switch
- delay:
minutes: "{{ (states.input_number.duration_front_shrubs.state | int) }}"
- service: switch.turn_off
entity_id: switch.front_shrubs_switch
update_front_shrubs_next_run_timer:
alias: "Update Front Shrubs Next Run Timer"
sequence:
- service: input_datetime.set_datetime
entity_id: input_datetime.next_run_front_shrubs
data_template:
date: >
{{(as_timestamp(now())+(states.sensor.time_delta_front_shrubs.state)|int) | timestamp_custom("%Y-%m-%d", true)}}
time: >
{{(as_timestamp(now())+(states.sensor.time_delta_front_shrubs.state)|int) | timestamp_custom("%H:%M:%S", true)}}
update_front_shrubs_last_run_timer:
alias: "Update Front Shrubs Last Run Timer"
sequence:
- service: input_datetime.set_datetime
entity_id: input_datetime.last_run_front_shrubs
data_template:
date: >
{{(as_timestamp(now())) | timestamp_custom("%Y-%m-%d", true)}}
time: >
{{(as_timestamp(now())) | timestamp_custom("%H:%M:%S", true)}}
That should be about all that’s to it. As it stands it should work for you.
I’m still hoping to work on the scripts to pass variables programatically, as I have about eight irrigation timers and don’t wish to have eight copies of near duplicate code.
If you copy and paste, please make sure you have your indentations right depending how you keep your components separated or not. Indentations tend to be the most common problem when the logs are full of errors.
Any questions, please ask.