You can use virtual switches and an app of your choice to link them to routines. There is an app in Marketplace. I prefer this one: