These are just two simple potion blocks from my blood mage / helwalker script.
You can use a conditional like "heatlh: self - health below 50%" if you want, which makes sense for healing potions, but for other potions I usually just use "always true" which is the default and it's always processed when the script reaches the block. I just put one potion of the type to be consumed in the quick slot so the script doesn't consume a whole stack of potions of final stand.
If you don't have wall of draining or salvation of time and want to keep up a potion buff you could put a stack and then in the cooldown put the duration (it's alchemy dependent, usually like 60 to 120). Or if it's a healing potion just something like health: self - health below 25%, action potion of miraculous healing, cooldown 0.
So the first screenshot just has me casting wall of draining with cooldown 23, then I cast spirit shield or arcane veil if I don't have concentration to ensure the potion of final stand isn't wasted, then I drink the potion.
The second screenshot is less important potions or other consumables I may sometimes use, if I intend to use it during a combat I just place one in the quick slots. This block is much lower in the script because in between I have some more complicated blocks that proc brilliant, blade cascade, then various wizard buffs and clarity of agony. There's also a 3 second delay between drinking potions in case I have more than one which makes it less likely I'm interrupted, because the script will drink one potion, then go on to the other blocks, then come back after 3 seconds to the second potion on the list, etc. Just put what you want in the quick slots and script it under action -> consumables
If you want the full script you can download it here (I hope I'm allowed to link to files), it's sort of complex and specific for blood mage / monk but I label everything so it isn't completely inscrutable, it may be instructive, just move it to C:\Users\<username>\Saved Games\Pillars of Eternity II\CustomAIBehaviors
-----edit- some of the blocks may seem bizarre, like block 7, which I have turned off but can be used to clear hostile afflictions by rapidly swapping weapons with outworn buckler (and scordeo's edge) in slot 1. Also in some of the targeting blocks at the bottom I have it set not to target spirits, this is so I can proc the fire blight and use it proc brilliant while wall of draining it without killing it
Also scripts are processed top down, so emergency actions like healing potions / spells (or potions of final stand) should go near the top, in the middle I have buffs I try to sustain, then I have longer casts (summoned weapons, llengrath's safeguard), then finally attack abilities (stunning surge, skyward kick) and a standard attack block at the very bottom.-----
https://filebin.net/2zrxk2d596ftjtyl