It has been over a year and I feel like I have a decently tested version to post. It has been a learning experience to be sure and I am already working on some changes for the official version 1 of this monstrosity. In the meantime, here is My Backyard Weather, beta 1.
While building a weather station has been a "back of the head" interest for me since I was a kid, it wasn't until a few years ago when I started thinking seriously about practical home automation that I revisited the idea. If you want to automate common tasks that are easily forgotten, tedious, or need to happen when no one is home, you need data. A weather station can give you loads of useful data about the outside environment that can drive decisions in your system like "should I water the lawn?" or "someone should shut the kitchen window, it just started raining." This project is one in a series of Home Automation projects I have in the works and this article is the first step to building a weather system for use by other systems.
As outlined in my project description, this station collects most of the basic data you would expect from a typical station and is outlined below. I decided that since "Air Quality" is a substantially different dataset, I would separate it into an independent project. I also originally thought that I would produce the calculated "feels like" (heat index, wind chill, etc. data on the station but after considering how intensive the calculations can be, I decided that the scripts that rendered the data to the user would be a better place for that work. This would reduce the compute cycles of the code on the station, reducing the likelihood of error.
There are hundreds of home brewed weather stations outlined on the Internet and dozens of well-made commercial stations available so why build one? Simply, none of them gave me control of the data in a way that I could depend on. This station reliably provides a dataset on a useful interval that is stored in a local database. I was able to choose what I wanted to measure against and while this station wasn't cheap, this system does have more options than most commercial systems of the same cost. Since this station doesn't rely on batteries, and is wired directly to my home network, I have been able to operate this station for more than 6 months uninterrupted with no errors, dropped packets or missing data.
Since the data is stored in a database, any number of scripts and applications can poke and prod the information for everything from "it's dark outside" to "based on the current conditions, the crawl vents should be closed." This data can also be used by the homeowner to find trends in energy consumption, irrigation patterns, and behavior to make decisions that can lower costs or improve the overall automation experience.
Lastly, I control the code of the station which, allows me to adapt to changes in my home automation system and add new features as needed. For example, I recently settled on an open home automation platform called Home Assistant. I'll go into more detail about HA in a separate post but for brevity, HA allows a myriad of inputs to control thousands of devices. One supported type is MQTT which is a fast publisher/subscriber system for managing messages. I added MQTT publishing of my data to the posting code of the weather station in an afternoon and had all of my weather data available to HA in minutes.
I've been working on a station now for a little less than 4 years. The first year, though was mostly spent learning about the weather and what people were doing with stations. I built several test platforms that helped me understand various communications schemes, power types, database updating methods and so on. As it turns out, there are loads of ways to make a station and not all of them are equal. Along the way I learned that solar and directly powered devices are about as equally reliable but wireless networking was not at all as reliable as wired. Some of the devices I chose were cheap and reliable and some were not. Ultimately, the design I wound up with may not be the final version but it is working very well so far.
The platform is powered by an Arduino Mega. I chose this platform for simplicity since I preferred the dedicated nature of a MCU over a single board computer like a Raspberry Pi. I didn't want to have to troubleshoot the operating system in case I had a problem.
As stated above, I found that wireless networking would regularly fail or require a restart from time to time. Plus, I wound up burning up a couple of wireless network cards for reasons I still don't understand. So, I opted for a wired approach which wasn't my preferred option. Since I had to run a cable anyway (and trying to find the "upside" of committing all of that sweat equity to burying a cable) I also opted to use power over ethernet injectors to power the device over the much more expensive solar power option.
The Mega collects data from the following devices and transmits it directly to a MySQL database as a single insert. I didn't use a real-time clock on the Mega, opting instead to allow the database insert a timestamp on update, again keeping things as simple as possible.
I opted to not custom build an enclosure as I simply didn't trust a porus 3D printed enclosure to prevent moisture problems. I bought standard outdoor enclosures as shown below. I also bought a standard solar shield that was properly tested. in the end, This build wasn't the cheapest way to go but in paying a bit more, I knew there were some things I didn't have to worry about.
|Arduino Mega 2560||1||The primary processor|
|DHT22||1||Temp and Humidity Sensor|
|SEN-08942||1||Rain Gauge / Anemometer / Wind Vane|
|RG-11||1||Optical Rain Sensor|
|MPL3115A2||1||Barometric Pressure/Altitude/Temperature Sensor|
|TSL2561||1||Luminosity Sensor (LUX) Sensor|
|E989NNJL||1||Weatherproof PVC New Work/Old Work Junction Box|
|14252||1||1-Gang Gray Metal Weatherproof Standard Electrical Box|
|US-SA-AJD-198018||1||3.2"x4.3"x1.8" ABS Universal Project Enclosure w PC Transparent Cover|
|RHRS||1||Solar Radiation Shield|
|B00NRHNPUA||1||Power Over Ethernet injection kit|
|B019Q3U72M||1||12V DC power supply|
|LM7809CV||1||12VDC to 9VDC regulator|
|1||6-port Keystone Jack wall plate|
|1||Mega Proto Shield|
|Ethernet Cable for data/power and for short runs for component connections|
With changes 1 and 2 listed above, rainfall measurements through this gauge is around 90% what is in my manual gauge. I'll take that.
I've had a lot of trouble out of the lightning detector. First it wouldn't read at all and this was due to a known manufacturer defect. Embedded Adventures, the vendor for this particular breakout board replaced it and for a while it seemed to work using a code library for the AS3935 chip. Then there was an update for the code in the Arduino IDE that broke it. I found a library that was built by Embedded Adventures and it seemed to work but once I put it back in the box, it stopped registering events. I may have a wiring issue but I just haven't made troubleshooting it a priority.
However, while it was working, I discovered that it can be very touchy and incredibly sensitive to noise. For a while I was getting a lot of false positives and after a bit of crude analysis, I determined that it was too close to the wiring of the anemometer and picked up the events it was sending. I then moved it out to a separatebox with the LUX sensor but haven't been able to see anything since...
More to come on that one.
My rain detector requires a solid 12 volts to work properly. Period.
If you've worked with wall warts at all, you have probably noticed by now that they hardly ever supply the rated voltage under load. In my case, a 12 volt supply I was using was actually supplying 8.5 volts under load. The Arduino and all of the other parts were happy with this result but my rain detector was not. It would trip and stay tripped until reset. So, I found one in my junk box that supplied 12.2volts underload reliably and used that instead. Problem solved, or so I thought - the mega would lockup - a lot.
In increasing the voltage I introduced a new problem - heat. The onboard voltage regulator on the mega was good for voltages ranging from 6-20v but at 12volts, the onboard regulator was burning off that excess energy in the form of heat - a lot of it. When combined with a sealed enclosure, the system would overheat and lockup. My solution was to get a 12v to 9v power regulator and secure it with heat transfer adhesive to the lid of an external metal enclosure. The rain detector had its 12 volts and the mega had the 9 volts that liked better. Heat problem solved.
One of the primary goals for building this station was an effort to use the data for home automation. When I started building, I had not yet settled on a home automation management system. The reason was simple; there isn't one that unites all of the devices out there although some get pretty close. I had seriously considered SmartThings and Wink but in both of those cases you must have an internet connection for those things to fully work. Plus, I'm tired of everything I do being used for marketing purposes and I didn't want to give anyone a new dataset to sell me stuff. So, I deferred.
I read up on some locally managed (as in no internet connection required) systems and found that some were really promising but didn't check off all of the boxes like Open HAB. While being a very active and mature project, it was written in java and since I am learning Python, I wanted something I can use and contribute to. A friend at work referred me to Home Assistant and this one checked off all of the boxes - active community, python based, used open standards and had API integrations for a very large device base AND, not least of all, it worked even if my internet was down.
One of the niceties here was that it has a plugin for a MQTT broker that was installed in minutes and ready to go. All I needed to do was add the publishing bits to the weather station data upload section.
Currently, I am using light level data to automatically turn on the den lights when it gets dark enough outside.
I'm going to let some of these changes bake in for a while and see how well it does in hotter weather. When dealing with an outdoor device, time seems to be the best tester but in the meantime there are some things I'm going to go ahead and change:
After that, I'll consider it finished and ready to go.