Home automation using a common platform such as the Philip’s Hue bulbs or the Wemo switchable plugs and bulbs is reasonably straight forawrd. I’ve got a mix of Limitless LED light bulbs and Wemo switches, which makes it more complicated, but can be achieved using some custom software.
My goal was simple. My outdoor light, main hallway light and kitchen light are all Limitless bulbs. The lights in my lounge and behind my main computer are on Wemo switches. I wanted a solution whereas all these lights would switch on based on sunset, and then switch off again at a specific time. The reason for the switch off, is if I’m away on holiday, the lights need to turn off on their own; if they are already off, the system would just exit. Since it’s rare for me to be out really late, I picked 2am as the switch off time.
I like this solution because I’m often home after dark, plus if the wife and I are out at a function, we don’t have to fumble around in the dark looking for our house keys. The added benefit is the security of it looking as though someone is home.
The solution I came up with was all reasonable straight forward, but did take a lot of trial and error.
Firstly, I needed a machine that was always on at my place. My newly installed HTPC running Windows 10 would be the perfect candidate. I could’ve easily achieved this with a low powered PC such as a Raspberry Pi, but I needed a programming language (.net) and platform I was already familiar with.
To ease deployment and maintenance, I opted for a console application. If I was going after always on and super reliable, it would’ve been a Windows service.
The process works simply, as follows:
- At 4pm everyday, using Windows Scheduler, my console app boots up and queries the Sunrise-Sunset API. This takes a lat/lng parameter, giving me the exact sunset time at my place. There’s lots of extra info it provides (such as sunrise) but these aren’t required for my application.
The reason I like this is it will automatically change the time in summer and winter, meaning no configuring at different times of the year.
- The console app sleeps until it’s time to run. When it wakes up, it fires off a UDP packet which the light bridge is listening for to turn the lights on. For the Wemo switches, it connects to each one and fires a SOAP request to switch them on.
- I was using the library from Barnacules which uses UPNP to find the Wemo switches, but for some reason, it just doesn’t work on Windows 10. Since I only have the two switches, I set them to reserved IPs in DHCP, so I always know where to send the on/off commands.
- Once the lights have been switched on, the console app goes to sleep until 2am, where it fires off commands to switch the lights and Wemos off.
- I log everything to a basic txt file for diagnostic reasons. If I was being super diligent I’d store this to database.
Happy to share the source code with anyone who wants it, just fire me an email, nate at 3bit dot com.
Other related posts:
How one database query can fix HOP cards
Review: Navman MiVUE680
App Review: WorldRemit
comments powered by Disqus