Delay controled relay (pump control)

Good day everyone, a Node-Red expert here (and a HA dummy :smile:)
I have an environment of 20 water pumps , that i have created a node-red dashboard for:
-Settings for the output per minute per pump
-Tank size configuration
-Recipes management
-etc
And i made a function that calculates for how long a pump should be on to output the desired amount.

The pumps are connected to a relay board , and the ESP32 (nodemcu-32s) is controling the relays.

I tried this with MQTT over node-Red , but it is not reliable because MQTT messages arrive late, and sometimes its ±30 seconds(all the pumps are started at the same time).

So after thinking i decided a way to go is to somehow push the time amount integer to esp32 , and let it do the delay itself, and then reply back.

So i want to have a custom topic for every pump(not a problem) but how can i use the received payload as an delay amount? I figured out how to switch on/off after then: function.

This is what i have so fa:

esphome:
  name: pump_group_1
  platform: ESP32
  board: nodemcu-32s

wifi:
  ssid: 'XXXXXX'
  password: 'XXXXXXX'
  
  ap:
    ssid: "Test Fallback Hotspot"
    password: "hXymJXBhjiVu"

ota:
  password: 'XXXXXXXX'
  
logger:
  level: DEBUG

mqtt:
  broker: 192.168.1.103
  username: admin
  password: admin
  discovery: True
  on_message:
     
     - topic: some/topic
      
       then:
        - switch.turn_on: pump1
        - delay: !lambda 'return payload  ms;' 
        - switch.turn_off: pump1

switch:
  - platform: gpio
    name: pump1
    id: pump1
    pin: 13
    inverted: yes
    

This is not a solution, i am aware of that. but while searching the esphome docs i haven`t been able to find anything that i could benefit from.