I second the Insteon vote. I used a selection of Insteon devices plus the ISY994i (https://www.universal-devices.com/residential/isy994i-series/) to do much of what the OP asked about. In addition to all the typical benefits of home automation like one-touch lighting scenes and the like (most of which is doable with bare Insteon), the ISY-994i is both programmable itself (through a simple event-based GUI language) and offers a REST (and SOAP) API for remote control through your language of choice. If the Insteon controls and sensors are not enough for you, the ISY can also communicate over Z-Wave or Zigbee. The convenience and security applications are limited only by your imagination (and budget).