OT - it was a basic example for the OP to work from as he didn’t provide any code himself. That code would work fine in isolation and caters for exactly what the OP asked for…
Saying “always use two separate automations” is utter garbage. One automation with a templated action is the way to do this correctly with ‘error handling’.
But before the OP gets that far, he needs to understand what he’s doing, hence the basic-ness of my original reply. An easy way to tell if my replies are ‘this is as basic as it gets’ is when I just dump some code in with no explanations.