In my last post (HERE), I showed how to grab data from RFLink but also determined that because of issues I had with arrays (and with some exceptions that shouldn’t have happened), I wouldn’t include RFLink in the final version of Project Mercury.
What that final version DOES do is use the X10 SDK to capture data from sensors, post that data to an MQTT broker, and save both the X10 data and the MQTT messages to tables in a SQL server (not that you’d want to capture both, just shows you how to save the data that you want).
I’ve included the solution (HERE) rather than walking you through all of the code. I commented all of the major parts and will touch on the different steps you’ll need to get this working.
Before I started coding, I needed to set up my sensors. I’ve had a box full of M16A X10 sensors in a box since 2008 and never got around to using them. While putting in the batteries and setting the “House Codes,” I accidentally broke one of the nine sensors, so I ended up with 8 around the perimeter of my house.
Each sensor runs off two AAA batteries. The battery panel has a rubber gasket to weatherproof the device (batteries load through a door on the front, so you are not required to remove the sensor to replace the battery. You WILL have to reset the House/Unit codes when you swap them.
At the top of the sensor, there’s an adjustment for sensitivity. These are PIR sensors, which detect the difference in temperature in front of them when a person passes.
I used double sided tape to mount the sensors – 3M 5952, which is a magical adhesive. It holds forever but won’t rip the paint off your wall when you peel it back.
I have stucco walls, so I needed to take extra care to find a flat area to mount them. ALSO – because these detect differences in temperature, you don’t want to use one near the compressor for an HVAC system or a pool heater!
Now to start the actual coding, you’ll want to create your tables:
Next, create a new Visual Studio project and set up a basic form – a text box and two buttons. The buttons really don’t matter – one clears the contents of the text box, the other exits the app.
You’ll need to add a reference to the ActiveHome SDK. If you don’t have it installed, you can get it HERE. My example assumes that you’re using the CM15A interface, but the SDK should work with other adapters, as well.
At this point, you should review the code in the solution available HERE. You can also review previous entries on the X10 SDK, MQTT, and SQL in this series if you would like a little more detail. If you check the bottom of this post, you can find all the related articles by clicking “MERCURY”
Assuming your sensors are set up correctly, you should see this sort of data in your form’s text box:
You’ll save data to your tables, as so:
And you’re publishing your messages to MQTT for use by other elements of your home automation system!
None of the individual parts of this project are complicated at all, though the overall goal may seem intimidating before you break it down. I’ve done nothing here that any of you can’t do (assuming you have the sensors, a CM15A, and a computer to run the apps – which are all free!).
In addition to these sensors, I have a crate full of X10 security sensors for doors/windows and motion detectors, which I can also use with the special receiver in my garage – though they’re also available through the CM15a. some of those will likely end up in interesting places really soon.
My next step, however, will be to explore using Python to perform a similar integration for my RFLink Gateways, so its time to learn a new language! For now, though, Project mercury has come to a close. Thank you for following along.
SmarterHome.club is the website for our Facebook community, The Smarter Home Club – which is an umbrella for all kinds of smart home technologies – home automation, security, custom electronics, weather stations, alternative energy, you name it. DIY focused.
If you’re interested in joining the Smarter Home Club’s Facebook group, please follow this link: