Using WeeWX for Home Automation

Weather Underground is Dead to Me

I have been running a Personal Weather Station (PWS) for a number of years. Since the start, I have provided data to Weather Underground (WU) for free, with the common understanding that we PWS owners who provide the data would have API access to our data for our personal use and projects. I use this for a multitude of purposes, including driving decisions in my Hubitat home automation solution. I am not going to get into a complete rant over this here and now – but I do feel it brewing …

Well, WU announced recently that they were now going to charge PWS owners $850/month to access the very data that we freely provide them. Seriously What-In-The-Everloving-Fuck (ok slight rant). Now when IBM (Information Being Mismanaged?) purchased WU I was afraid they would pull a stunt like this, but never imagined they would go this far.

You may wonder why I sent the data to WU only to retrieve it? Simple answer, the WU API was baked into so many products, simply enter your API Key and stuff just worked. It also saved me from having to write my own API and applications to use a bespoke solution.

When this was announced, it became a topic of discussion across a number of weather and home automation forums, and I figured it was time to dig in and find a way to detangle WU from my systems before it goes dark.

Enter WeeWX Skins

WeeWX, the Weather Station software I now use has a templating system which they call “skins” that can create files every reporting period. I use a Davis Vantage Pro2 station and the WeeWX driver for that defaults to 5m reporting (“archive” in weewx speak) intervals, which is perfect for my needs.

To keep things simple (initially) I am creating a JSON file on my internal server for consumption by a Hubitat application being written by a member of the Hubitat user community who is also peeved by this situation caused by WU. To do this, I searched around for a JSON output template for WeeWX finding this skin by “initram” on GitHub. I didn’t need an entire new set of skins, so I modified his daily.json template as a starting point, and included it into my current Standard skin.

Step One: Create the daily.json.tmpl file

I am writing this assuming you are using the Standard skin provided by default as part of the WeeWX install on a RaspberryPi.  If you are using another skin or operating system, you may need to tweak some parts of this. If you have any issues, leave me a comment and I will see if I can lend a hand.

Log onto your Pi via SSH and get to your skiin directory 

cd /etc/weewx/skins/Standard

Create a new file named daily.json.tmpl and include the contents below

sudo vi daily.json.tmpl

Content for daily.json.tmpl. There are dozens of data points you can add to this, see documentation for more information.

#encoding UTF-8
  "title":"Current Values",
  "lat":"$station.latitude[0]° $station.latitude[1]' $station.latitude[2]",
  "lon":"$station.longitude[0]° $station.longitude[1]' $station.longitude[2]",
  "stats": {
    "current": {
      #if $day.extraTemp1.has_data
      #end if
      #if $day.UV.has_data
      #end if
      #if $day.ET.has_data and $day.ET.sum.raw > 0.0
      #end if
      #if $day.radiation.has_data
      #end if
    #if $almanac.hasExtras
      "azimuth":"$("%.1f°" % $",
      "altitude":"$("%.1f°" % $almanac.sun.alt)",
      "rightAscension":"$("%.1f°" % $almanac.sun.ra)",
      "declination":"$("%.1f°" % $almanac.sun.dec)",
      "azimuth":"$("%.1f°" % $",
      "altitude":"$("%.1f°" % $almanac.moon.alt)",
      "rightAscension":"$("%.1f°" % $almanac.moon.ra)",
      "declination":"$("%.1f°" % $almanac.moon.dec)",
    #end if

Step Two: Edit skin.conf file 

Now that you have created and saved your daily.json.tmpl file, we need to tell WeeWX to use it when it goes through its reporting cycle. I am not going into all the gory details about this file, if you want to dive deep into all the options available, please go take a look at the WeeWX documentation.

Open skin.conf file in your editor (e.g.: vi)

sudo vi skin.conf

search for the RSS stanza of the file (in my file it is around line 230)
insert this after the RSS template 

            template = daily.json.tmpl

Now save the file, and either wait for your next archive reporting period, or run wee_reports to force generate the file. You can now write applications to use this JSON file by pointing to http://<your raspberry’s IP>/weewx/daily.json which will get updated every archive cycle.

I am looking forward to Cobra putting together an application to use this data and untangling my Home Automation from WU entirely… 

Once the app is available and I get a chance to test it – I will post an update about it.


Share Some Love!

This entry was posted in Computing, SmartHome, Technology and tagged , , , , , , , , , .

Post a Comment

Your email is never published nor shared. Required fields are marked *