There are dozen ways of doing that. There are official apps that can do it, routines/modes combo that can do it and many community apps and then there is your own personal app. Depends on your technical skill and imagination.
Here is a part of my set up that does that and rarely fails…it takes time to set up, but once you do it it runs on its own…