Looking for help with If statement

Hi all.

Just playing around with some code to carry out an automation. Normally I use node-red but I am using a esp32 and need it to run even if HA is offline.

I have the first part working. When the temp of the sensor gets above 30 it turns on the pump. Well I had it working but since I changed it to a script I havent tested it. In the script I turn a global variable to true then turn on an output. 30 seconds later I turn off that variable.

So I have an ADC measuring current. The pump it turns on and off when first turned on draws say 2 amps untill it builds pressure then it draws 3 amps. It takes around 20 seconds to do this.

So I want check the current every 10 seconds and if the current is below say 2.8 turn off the pump. BUT during the time the global variable is set to true, simply ignore it. So my second script is where I am lost. Not sure how to do the if part if someone could offer some help


esphome:
  name: bathroomgrey
  platform: ESP32
  board: esp-wrover-kit
  
globals:
   - id: pump_current_ignore
     type: bool
     restore_value: no
     initial_value: "false"  

esphome:
  name: bathroomgrey
  platform: ESP32
  board: esp-wrover-kit
  
globals:
   - id: pump_current_ignore
     type: bool
     restore_value: no
     initial_value: "false"  

wifi:
  ssid: "ssid"
  password: "pass"
dallas:
  - pin: GPIO23
# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
script:
  - id: start_pump
    then:
      - globals.set:
          id: pump_current_ignore
          value: 'true'
      - switch.turn_on: BGP  
        
      - delay: 30s
      - globals.set:
          id: pump_current_ignore
          value: 'false'


  - id: stop_pump
    then:
        - if:
            condition:




sensor:
# - platform: uptime
#   name: Uptime Sensor
- platform: dallas
  address: 0xA0011454FEF2AA28
  name: "Bath Shower Sensor"
  on_value_range:
  - above: 30.0
    then:
    - script.execute: start_pump
  
  
  
- platform: adc
  pin: A0
  name: "Bath Current"
  update_interval: 10s
  filters:
    - multiply: 10
  on_value_range:
  - below: 3.0
    then:
    - script.execute: stop_pump  
    
    
    
    
switch:
- platform: gpio
  pin: 2
  name: "Bath GW Pump"
  id: BGP
  icon: "mdi:fountain"

Probably easier to just do the whole thing as a lambda like this

  - id: stop_pump
    then:
      lambda: |-
        if (id(pump_current_ignore)) return;
        else id(BGP).turn_off();

Also probably even more clear just to place this code in the on_value_range: directly in which case you don’t need a ‘return’ at all.

    then:
      lambda: 'if (!id(pump_current_ignore)) id(BGP).turn_off();'

Many thanks. I happened to fry the only unit I had here so when I get the replacement in the mail next week I will give it a go.

As I needed a way of controlling a pump and as I freid the esp32, I ended up doing it on a Arduino Mega. I am wondering whats the easiest way to share some data to the esp32 to show up in HA? Have the Arduino reading the current of the pump and would like to display this in the front end?

P