I seem to be running into a continuous loop. How do I get the automation to run though it’s sequences once without the need of turning the automation off?
Desired outcome:
- when an inpute_boolean is ON check certain conditions
- IF condition is met, run the sequence and then stop until the next time the automation is triggered
Sequence:
- IF the actual water run off is more than the desired water run off
- THEN reduce water volumne by a certain percentage
- ELSE IF the actual water run off is less than designed run off
- THEN increase water volume by a certain percentage
- ELSE Do nothing
All the calucations work fine but it just goes into a continuous loop. Thank you all in advance for taking the time to read and for any advice you might have.
# Set condition so that the 'Water Volume' only gets updated if the 'Update Water Volume' is turned ON
- condition: state
entity_id: input_boolean.update_water_volume
state: 'on'
- choose:
# Redude 'Water Volume' if the plant feed run off is too high
- conditions:
condition: template
value_template: "{{ states('sensor.actual_plant_feed_run_off') | float(0) >= states('input_number.plant_feed_run_off_high') | float(0) }}"
sequence:
- action: input_number.set_value
data_template:
entity_id: input_number.water_volume
value: >
{% set reduceWaterVolumeAmount = ((states('input_number.water_volume') | float(0)) / 100) * (states('input_number.adjust_water_volume_amount') | float(0)) %}
{% set waterVolume = states('input_number.water_volume') | float(0) %}
{{ waterVolume - reduceWaterVolumeAmount }}
- event: ''
event_data:
event_type: "{{ run_off_high }}"
# Increase 'Water Volume' if the plant feed run off is too low
- conditions:
condition: template
value_template: "{{ states('sensor.actual_plant_feed_run_off') | float(0) <= states('input_number.plant_feed_run_off_low') | float(0) }}"
sequence:
- action: input_number.set_value
data_template:
entity_id: input_number.water_volume
value: >
{% set increaseWaterVolumeAmount = ((states('input_number.water_volume') | float(0)) / 100) * (states('input_number.adjust_water_volume_amount') | float(0)) %}
{% set waterVolume = states('input_number.water_volume') | float(0) %}
{{ waterVolume + increaseWaterVolumeAmount }}
- event: ''
event_data:
event_type: "{{ run_off_low }}"
mode: single
Full code:
blueprint:
name: Drain Tank Monitor
description: ''
domain: automation
input:
# Input script for selecting the scales for the drain tank and setting the event_type to trigger this automation
drain_tank_volume:
name: Select Sensor Scale Value
description: "Select sensor that gives you the weight-volume of the nutrient tank"
selector:
entity:
filter:
- domain: sensor
tank_fill_complete_event:
name: "Plant Feed Run Off Trigger"
description: "This is the event_type that the wait trigger listens out for"
default: "fill_tank_complete"
selector:
text:
variables:
drain_tank_volume: !input drain_tank_volume
tank_fill_complete_event: !input tank_fill_complete_event
# Trigger automation when the tank fill is completed
triggers:
- trigger: event
event_type: "{{ tank_fill_complete_event }}"
# Set Condition so that the plant feed run off automation only runs during the cycle start and end date
conditions:
- condition: template
value_template: >
{% set startDate = states('input_datetime.cycle_start_date') | as_datetime | as_local %}
{% set endDate = states('sensor.cycle_end_date') | as_datetime | as_local %}
{% set today = now() %}
{{ endDate >= today >= startDate}}
actions:
# Update 'Plant Feed Run Off' with the value of the drain tank scale value
- action: input_number.set_value
data_template:
entity_id: input_number.plant_feed_run_off
value: "{{ states(drain_tank_volume) }}"
- delay:
seconds: 2
# Update 'Total Plant Feed Run Off' with the 'Plant Feed Run Off' value to get total litres contained in drain tank
- action: input_number.set_value
data_template:
entity_id: input_number.total_plant_feed_run_off
value: >
{% set totalRunOff = states('input_number.total_plant_feed_run_off') | float %}
{% set plantFeedRunOff = states('input_number.plant_feed_run_off') | float %}
{{ totalRunOff + plantFeedRunOff }}
# Set condition so that the 'Water Volume' only gets updated if the 'Update Water Volume' is turned ON
- condition: state
entity_id: input_boolean.update_water_volume
state: 'on'
- choose:
# Redude 'Water Volume' if the plant feed run off is too high
- conditions:
condition: template
value_template: "{{ states('sensor.actual_plant_feed_run_off') | float(0) >= states('input_number.plant_feed_run_off_high') | float(0) }}"
sequence:
- action: input_number.set_value
data_template:
entity_id: input_number.water_volume
value: >
{% set reduceWaterVolumeAmount = ((states('input_number.water_volume') | float(0)) / 100) * (states('input_number.adjust_water_volume_amount') | float(0)) %}
{% set waterVolume = states('input_number.water_volume') | float(0) %}
{{ waterVolume - reduceWaterVolumeAmount }}
- event: ''
event_data:
event_type: "{{ run_off_high }}"
# Increase 'Water Volume' if the plant feed run off is too low
- conditions:
condition: template
value_template: "{{ states('sensor.actual_plant_feed_run_off') | float(0) <= states('input_number.plant_feed_run_off_low') | float(0) }}"
sequence:
- action: input_number.set_value
data_template:
entity_id: input_number.water_volume
value: >
{% set increaseWaterVolumeAmount = ((states('input_number.water_volume') | float(0)) / 100) * (states('input_number.adjust_water_volume_amount') | float(0)) %}
{% set waterVolume = states('input_number.water_volume') | float(0) %}
{{ waterVolume + increaseWaterVolumeAmount }}
- event: ''
event_data:
event_type: "{{ run_off_low }}"
mode: single