Script Blueprint: Apply action when condition is met

For the life of me I can’t figure out why an action won’t work when my condition is met. I have an action to turn a pump on, and when the condition (where tank volume >= water volume target) is met, it should turn the pump off.

I have checked with the debugging template and the condition is working

area of code I’m having issues with:

# Fill Nutrient Tank
  - action: switch.turn_on
    target:
      entity_id: '{{fill_tank}}'

  - condition:
    - condition: template
      value_template: >
          {% set waterVolume = states('input_number.water_volume') | float %}  
          {% set tankVolume = states(tank_volume) | float %} 
          {{ tankVolume >= waterVolume }}
  - action: switch.turn_off
    target:
      entity_id: '{{fill_tank}}'

Full code:

blueprint:
  name: Nutrient Tank Water Fill
  description: This blueprint allows create a dosing schedule
  domain: script
  input:
    nutrient_mixer:
      name: Select Nutrient Mixer
      description: "Select the switch entity to control the nutrient mixer"
      selector:
          entity:
            filter:
              - domain: switch
    drain_tank:
      name: Select Tank Draining Solenoid
      description: "Select the switch entity to control the tank drain solenoid"
      selector:
          entity:
            filter:
              - domain: switch
    fill_tank:
      name: Select Tank Filling Solenoid
      description: "Select the switch entity to control the tank filling solenoid"
      selector:
          entity:
            filter:
              - domain: switch
    nutrient_tank_mixer:
      name: Select Tank Mixer
      description: "Select the switch entity to control the tank filling solenoid"
      selector:
          entity:
            filter:
              - domain: switch
    manual_scale_tare_action:
      name: Select Scale Manual Tare Button
      description: "Select button that resets the scales to 0"
      selector:
          entity:
            filter:
              - domain: button
    tank_volume:
      name: Select Sensor Scale Value
      description: "Select sensor that gives you the weight of the nutrient tank"
      selector:
          entity:
            filter:
              - domain: sensor

variables:
  nutrient_mixer: !input nutrient_mixer
  drain_tank: !input drain_tank
  fill_tank: !input fill_tank
  manual_scale_tare_action: !input manual_scale_tare_action
  nutrient_tank_mixer: !input nutrient_tank_mixer
  tank_volume: !input tank_volume

sequence:
#Mixing Nutrients
  - action: switch.turn_on
    target: 
      entity_id: '{{nutrient_mixer}}'
  - delay:
      seconds: "{{ states('input_number.mixer_time') | float }}"
  - action: switch.turn_off
    target: 
      entity_id: '{{nutrient_mixer}}'

#Draining Nutrient Tank
  - action: switch.turn_on
    target: 
      entity_id: '{{drain_tank}}'
  - delay:
      seconds: "{{ (states('input_number.drain_tank_time') | float) }}"
  - action: switch.turn_off
    target: 
      entity_id: '{{drain_tank}}'
  - delay:
      seconds: 5
  - service: button.press
    target: 
      entity_id: '{{manual_scale_tare_action}}'
  - delay:
      seconds: 10

# Fill Nutrient Tank
  - action: switch.turn_on
    target:
      entity_id: '{{fill_tank}}'

  - condition:
    - condition: template
      value_template: >
          {% set waterVolume = states('input_number.water_volume') | float %}  
          {% set tankVolume = states(tank_volume) | float %} 
          {{ tankVolume >= waterVolume }}
  - action: switch.turn_off
    target:
      entity_id: '{{fill_tank}}'

mode: single
      

    
    
    
    
    
    

Conditions are not Wait actions… if the condition isn’t true the moment it is checked then the script stops at that point.

1 Like

Sometimes feel a little silly not thinking of it! Thank you very much, that solved my issue:

  - action: switch.turn_on
    target:
      entity_id: '{{fill_tank}}'

  - wait_template: >
          {% set waterVolume = states('input_number.water_volume') | float %}  
          {% set tankVolume = states(tank_volume) | float %} 
          {{ tankVolume >= waterVolume }}
  - action: switch.turn_off
    target:
      entity_id: '{{fill_tank}}'

FWIW, you can use inputs directly when they provide the type of value you need, you don’t have to use script variables. You only need to use script variables if you need to use the value in a template.

In your example snippet, you can use !input fill_tank instead of '{{fill_tank}}' to supply the entity ID’s.

  - action: switch.turn_on
    target:
      entity_id: !input fill_tank
  - wait_template: >
      {% set waterVolume = states('input_number.water_volume') | float(0) %}  
      {% set tankVolume = states(tank_volume) | float(0) %} 
      {{ tankVolume >= waterVolume }}
  - action: switch.turn_off
    target:
      entity_id: !input fill_tank
1 Like

Thanks for clarifying that. I was aware of this but for one reason or another things weren’t working and so I do the usual of tweaking things here and there without fully knowing what I’m doing. Still learning when it’s appropriate to set a variable and when it’s not needed etc, which I’m pretty sure you’ve explained in a previous post. Thanks again for all your help