I've used shelly products to do this before. They handle most of the hardware stuff if you are coming from a more software experienced side of things. It's basically an ESP chip that controls a relay. They have terminals set up to read switch or button pressed too. The project I had was to replace a garage door opener and have a switch set up to tell if the door was open or closed.<p><a href="https://www.shelly.com/en-us/products/shop/shelly-button" rel="nofollow">https://www.shelly.com/en-us/products/shop/shelly-button</a>