This ideal world exists, and it is glorious. I somewhat recently set up a Raspberry Pi 2 with https://home-assistant.io and a cheap z-wave USB stick. The interface is through a webpage (not an app), and I access it remotely using a OpenVPN server on my router.
It's interfacing with door sensors, motion sensors, wall switches, cameras, my stereo, HUE lights, etc. It can email me or send me SMS for notifications. When I wake up and walk past a motion sensor, the lights come on in a dim scene. When I come home and open the door, the lights turn on. I have tons of rules and it's super fun. Totally self-hosted, and the main server is completely open-source (written in Python3).
I haven't set it up with a thermostat but lots of other people have.