Powerbuttomnapp

Hey
My power button stopped working. I want to programate a app wich turn my smatrphone off with a button. The problem is that i don’t know how i do this.
Thank you for your awnseres .