I was about to answer; but then I saw this post:
https://itch.io/t/142150/steambot-loop-example
Which goes into further detail.
Basically the main part you're after is the Until X Storage full > Wait. (Myself I add a move command, just cuz it's cool to have your workers standing in nice spots :D).
Check his post out; lmk if he covers it. The concept is to basically word your conditions backwards and put them inside your main loops. (This is pretty common practice when programming)