Yes, notice how you have a lot of redundancy in that?
i simple coded
- 3 timers (i used as trigger also)
- monday-sunday
- sprinkler duration time
and built-in lot of pre-checks cause of the rainbird-limitations in webhooks and cause of our parallel usage of the rainbird app on mobile when homeassistant is not working as it should and co
for me it works now great and all trigger can be managed by lovelace now
fyi, i also integrated a cleaning and filter system cause here in poland we fight against immens Mangan, Iron in the Groundwater and other stuff which i had to filter out, but this is handled in another independent automation, cause their i had to measure also some analog informations, cause i try cause of possible -35° any kind of external sensors and working outside with mechanical sensors i can simple replace
sorry, have to run, but this is the general idea
alias: Garden - Sprinkler
description: ""
trigger:
- platform: template
value_template: >-
{% set time_now = now().strftime('%H:%M') %}
{% set time_timer = states('input_datetime.garden_sprinkler_timer_1')[:5]
%}
{{ time_now == time_timer }}
- platform: template
value_template: >-
{% set time_now = now().strftime('%H:%M') %}
{% set time_timer = states('input_datetime.garden_sprinkler_timer_2')[:5]
%}
{{ time_now == time_timer }}
- platform: template
value_template: >-
{% set time_now = now().strftime('%H:%M') %}
{% set time_timer = states('input_datetime.garden_sprinkler_timer_3')[:5]
%}
{{ time_now == time_timer }}
variables:
order: "{{ states('input_text.garden_sprinkler_order').strip() | list | reject('eq', ' ') | list }}"
condition:
- condition: template
value_template: >-
{% set today = now().strftime('%a') %}
{% set time_now = now().strftime('%H:%M') %}
{% set timer_mon = states('input_boolean.garden_sprinkler_timer_mon') %}
{% set timer_tue = states('input_boolean.garden_sprinkler_timer_tue') %}
{% set timer_wed = states('input_boolean.garden_sprinkler_timer_wed') %}
{% set timer_thu = states('input_boolean.garden_sprinkler_timer_thu') %}
{% set timer_fri = states('input_boolean.garden_sprinkler_timer_fri') %}
{% set timer_sat = states('input_boolean.garden_sprinkler_timer_sat') %}
{% set timer_sun = states('input_boolean.garden_sprinkler_timer_sun') %}
{% set today_timer = states('input_boolean.garden_sprinkler_timer_'
~today.lower()) %}
{% set time_timer03 =
states('input_datetime.garden_sprinkler_timer_3')[:5] %}
{% set time_timer02 =
states('input_datetime.garden_sprinkler_timer_2')[:5] %}
{% set time_timer01 =
states('input_datetime.garden_sprinkler_timer_1')[:5] %}
{{
today_timer == "on"
and
time_now != "00:00:00"
and (
time_now == time_timer01
or
time_now == time_timer02
or
time_now == time_timer03
)
}}
action:
- repeat:
foreach: "{{ order }}"
sequence:
- variables:
zone: "{{ repeat.item }}"
active: switch.rain_bird_sprinkler_{{ zone }}
- if:
- condition: template
value_template: >
{{ is_state(active, ['on', 'off']) }}
then:
- service: rainbird.start_irrigation
data:
duration: "{{ states('input_datetime.garden_sprinkler_duration').split(':')[1] }}"
target:
entity_id: "{{ active }}"
- wait_template: "{{ states(active) == \"on\" }}"
continue_on_timeout: false
- wait_template: "{{ states(active) == \"off\" }}"
continue_on_timeout: false
understand your intention, but i made not so good exp with foreach in homeassistant, thats why i keep this codeline as is
This is what I mean
alias: Garden - Sprinkler
description: ""
trigger:
- platform: time_pattern
minutes: "/1"
variables:
order: "{{ states('input_text.garden_sprinkler_order').strip() | list }}"
day: "{{ now().strftime('%a') | lower }}"
time: "{{ now().strftime('%H:%M') }}"
times: >
{%- set ns = namespace(items=[]) %}
{%- for i in range(1,4) %}
{% set ns.items = ns.items + [ states('input_datetime.garden_sprinkler_timer_' ~ i)|[:5] ] %},
{%- endfor %}
duration: "{{ states('input_datetime.garden_sprinkler_duration').split(':')[1] }}"
condition:
- condition: template
value_template: >-
{{ is_state('input_boolean.garden_sprinkler_timer_' ~ day, 'on') and time in times }}
action:
- repeat:
foreach: "{{ order | reject('eq', ' ') | list }}"
sequence:
- variables:
active: switch.rain_bird_sprinkler_{{ repeat.item }}
- if:
- condition: template
value_template: >
{{ is_state(active, ['on', 'off']) }}
then:
- service: rainbird.start_irrigation
data:
duration: "{{ duration }}"
target:
entity_id: "{{ active }}"
- wait_template: "{{ is_states(active, 'on') }}"
continue_on_timeout: false
- wait_template: "{{ is_states(active, 'off') }}"
continue_on_timeout: false
much easier to manage, all variables in the main trace shown on the trigger. Also this automation is functionally the same.