I don’t know about FOSS, but Tasker is probably the best bet for phone automations.
Edit: Found this LibreTasks
A place to discuss anything related to Android or Android adjacent.
INFO:
No attacking others based on their phone preferences. Criticizing OEMs/devices is allowed. Attacking users because a different brand/device works for them isn't.
Obvious spam will be removed.
Anything directly or indirectly related to Android is allowed.
Check Out Our Partner Communities:
I don’t know about FOSS, but Tasker is probably the best bet for phone automations.
Edit: Found this LibreTasks
Sadly seems abandoned since 5 years...