As Chris said, the key is to separate the protocol from the hardware. But that doesn't mean you have to implement your own firmware! You can choose a switch that supports a common and readily available home automation protocol, such as Z-Wave or Insteon. These are closed protocols, but there is a wide variety of manufacturers that create interoperable components with them. Then, you can use a home automation controller that integrates the home automation protocols with IP.
I use a Vera Edge home automation controller which offers a web API; and there are other choices as well. I chose Vera because the entire system runs locally without requiring access to a hosted cloud interface; there is no monthly service charge, and the device and rules are completely under my control. I can choose to hide the API behind my firewall, expose the API externally myself, or I can leverage Vera's free cloud services to expose the API for me. (As a plus, Vera has a very active community who is constantly adding support for new home automation devices.) Vera does offer a free app for iPhone and Android, but you are not bound to their app. Several independent developers have created their own apps which leverage Vera's API (Grasshopper, VeraMate, and ImperiHome are three such products) to provide alternative GUIs.
If you are opposed to a commercial gateway product, and are willing to put in a lot of work, there are also Open Source solutions for implementing your own home automation gateway that offer a web API. Domoticz and OpenHAB are two projects that spring to mind. However, these packages are both still far less mature than the commercial solutions, and both require a substantial amount of work to implement. (And you indicated you didn't want to hack together a solution.)
The only drawback I see to the gateway-based approach is that your question is asking about "a light switch", implying a quantity of one device. A Z-wave switch can cost anywhere from $10 to $40 (or more), and a commercial gateway can cost $100-$400 (or more.) For a single switch, the price tag likely isn't worth it. If you are automating an entire building, though, the cost of the hub can be spread out among dozens of devices.