Closed jeroenterheerdt closed 9 months ago
@jeroenterheerdt I'm making some progress with the blueprints for esphome. I think I'll be done with it in a day or two.
Here is the blueprint for esphome. There is minimum one bug at the end, where the number of days since last irrigation is reset to zero. In a script it works without any flaw but not in the automation. I don't have any clue why?
blueprint:
name: ESPHome Irrigation
description: This automation allows you to control the irrigation of different zones with one ESP. The number and order of valves and zones must correspond.
domain: automation
input:
esphome_valve:
name: ESPHome valve
description: ESPHome valve to open and close
selector:
entity:
multiple: true
filter:
- domain: switch
integration: esphome
irrigation_zone:
name: Irrigation Zone
description: Smart Irrigation zone to irrigate
selector:
entity:
multiple: true
filter:
- device_class: duration
integration: smart_irrigation
alias: ESPHome Irrigation
description: "ESPHome Irrigation"
variables:
esphome_valve: !input esphome_valve
irrigation_zone: !input irrigation_zone
esphome_count: "{{ expand(esphome_valve) | list | count }}"
irrigation_count: "{{ expand(irrigation_zone) | list | count }}"
trigger:
platform: event
event_type: smart_irrigation_start_irrigation_all_zones
action:
- choose:
- conditions:
- condition: template
value_template: "{{esphome_count != irrigation_count}}"
sequence:
- service: persistent_notification.create
data:
message: >-
Error: You must choose the same number of valves and zones!
- conditions:
- condition: state
entity_id: input_boolean.irrigation_enabled
state: "off"
sequence:
- service: persistent_notification.create
data:
message: >-
Irrigation is not enabled
- conditions:
condition: template
value_template: >-
{{states('input_number.number_of_days_since_last_irrigation') < states('input_number.irrigate_every')}}
sequence:
- service: input_number.increment
data: {}
target:
entity_id: input_number.number_of_days_since_last_irrigation
default:
- repeat:
for_each: !input irrigation_zone
sequence:
- if:
- condition: template
value_template: >-
{{states(repeat.item)=='disabled' or
states(repeat.item)|int()==0}}
then:
- service: switch.turn_off
target:
entity_id: >-
{{esphome_valve[repeat.index - 1]}}
data: {}
else:
- service: switch.turn_on
target:
entity_id: >-
{{esphome_valve[repeat.index - 1]}}
data: {}
- service: esphome.sprinklercontroller_set_valve_run_duration
data:
duration: "{{states(repeat.item)}}"
valve: "{{repeat.item|int(0)}}"
# - service: persistent_notification.create
# data:
# message: >-
# {{states(repeat.item)}}
# {{repeat.index - 1}}
# {{esphome_valve[repeat.index - 1]}}
- service: esphome.sprinklercontroller_start_full_cycle
data: {}
- service: smart_irrigation.reset_all_buckets
data: {}
- service: input_number.set_value
data:
value: 0
target:
entity_id: input_number.number_of_days_since_last_irrigation
mode: single
hey @gatonero thanks for the blueprint - I discovered another logical error in my automation. Here's hopefully my final automation. Can you update the blueprint?
alias: Smart Irrigation
trigger:
- platform: event
event_type: smart_irrigation_start_irrigation_all_zones
- platform: sun
event: sunrise
offset: "01:00:00"
- platform: time
at: "00:00:00"
id: midnight
condition:
- condition: state
entity_id: input_boolean.irrigation_enabled
state: "on"
action:
- if:
- condition: trigger
id:
- midnight
then:
- service: input_boolean.turn_off
data: {}
target:
entity_id: input_boolean.irrigation_automation_ran_today
else:
- if:
- condition: state
entity_id: input_boolean.irrigation_automation_ran_today
state: "off"
then:
- if:
- condition: template
value_template: >-
{{states('input_number.number_of_days_since_last_irrigation')<states('input_number.irrigate_every')}}
then:
- service: input_number.increment
data: {}
target:
entity_id: input_number.number_of_days_since_last_irrigation
else:
- service: input_number.set_value
target:
entity_id: input_number.smart_irrigation_number_of_zones_enabled
data:
value: 0
- repeat:
for_each:
- sensor: sensor.smart_irrigation_lawn_main_deck_owm
vid: 0
zid: 1
- sensor: sensor.smart_irrigation_lawn_tree
vid: 1
zid: 2
- sensor: sensor.smart_irrigation_lawn_office
vid: 2
zid: 3
- sensor: sensor.smart_irrigation_herbs
vid: 3
zid: 4
- sensor: sensor.smart_irrigation_greenhouse
vid: 4
zid: 5
- sensor: sensor.smart_irrigation_side_house
vid: 5
zid: 6
sequence:
- if:
- condition: template
value_template: >-
{{state_attr(repeat.item.sensor,'State')=='disabled'
or states(repeat.item.sensor)|int(default=0)==0}}
then:
- service: switch.turn_off
target:
entity_id: >-
{{'switch.sprinklercontroller_enable_zone_'+repeat.item.zid|string()}}
data: {}
else:
- service: switch.turn_on
target:
entity_id: >-
{{'switch.sprinklercontroller_enable_zone_'+repeat.item.zid|string()}}
data: {}
- service: input_number.increment
target:
entity_id: >-
input_number.smart_irrigation_number_of_zones_enabled
data: {}
- service: esphome.sprinklercontroller_set_valve_run_duration
data:
duration: "{{states(repeat.item.sensor)|int(default=0)}}"
valve: "{{repeat.item.vid}}"
- if:
- condition: template
value_template: >-
{{states('input_number.smart_irrigation_number_of_zones_enabled')|int(default=0)>0}}
then:
- service: esphome.sprinklercontroller_start_full_cycle
data: {}
enabled: true
- service: smart_irrigation.reset_all_buckets
data: {}
- service: input_number.set_value
data:
value: 0
target:
entity_id: input_number.number_of_days_since_last_irrigation
- service: input_boolean.turn_on
data: {}
target:
entity_id: input_boolean.irrigation_automation_ran_today
mode: single
I will have a look tomorrow.
@jeroenterheerdt could you please tell me where and what you changed. I changed a lot to get a template from your automation. Because it has been some days ago I made the template it's difficult for me to locate the changes.
@gatonero here you go: https://www.diffchecker.com/ennJee7h/.
In summary:
irrigation_automation_ran_today
) to make sure we don't run it more than onceStale issue message
ship blueprints in-box: