I have a Sony Xperia.
I comes with a nifty program called Xperia assist that lets you set automatic actions like.
If the time is X and Y program is running, do Z.
I have it set to turn ringer off if WhatsApp is open. (only open, running in background and the ringer is back to normal

)
I'm sure there are other programs like this but I think Xperia Assist runs on any Android as it's part of the Assist tools they use to take all your date from say a Samsung over to Sony.
Dan
P.S. This program is also great for running satnav when you get in the car as it also allows actions like If time is X and I'm plugged in, do Y.