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 weewx.com documentation for more information.

#encoding UTF-8
{
  "title":"Current Values",
  "location":"$station.location",
  "time":"$current.dateTime",
  "lat":"$station.latitude[0]° $station.latitude[1]' $station.latitude[2]",
  "lon":"$station.longitude[0]° $station.longitude[1]' $station.longitude[2]",
  "alt":"$station.altitude",
  "hardware":"$station.hardware",
  "uptime":"$station.uptime",
  "serverUptime":"$station.os_uptime",
  "weewxVersion":"$station.version",
  "stats": {
    "current": {
      "outTemp":"$current.outTemp",
      "windchill":"$current.windchill",
      "heatIndex":"$current.heatindex",
      "dewpoint":"$current.dewpoint",
      "humidity":"$current.outHumidity",
      "insideHumidity":"$current.inHumidity",
      "barometer":"$current.barometer",
      "barometerTrendDelta":"$trend.time_delta.hour.format("%.0f")",
      "barometerTrendData":"$trend.barometer",
      "windSpeed":"$current.windSpeed",
      "windDir":"$current.windDir",
      "windDirText":"$current.windDir.ordinal_compass",
      "windGust":"$current.windGust",
      "windGustDir":"$current.windGustDir",
      "rainRate":"$current.rainRate",
      #if $day.extraTemp1.has_data
      "pondTemp":"$current.extraTemp1",
      #end if
      #if $day.UV.has_data
      "UV":"$current.UV",
      #end if
      #if $day.ET.has_data and $day.ET.sum.raw > 0.0
      "ET":"$current.ET",
      #end if
      #if $day.radiation.has_data
      "solarRadiation":"$current.radiation",
      #end if
      "insideTemp":"$current.inTemp"
    },
  },
  "almanac":{
    #if $almanac.hasExtras
    "sun":{
      "startCivilTwilight":"$almanac(horizon=-6).sun(use_center=1).rise",
      "sunrise":"$almanac.sun.rise",
      "transit":"$almanac.sun.transit",
      "sunset":"$almanac.sun.set",
      "endCivilTwilight":"$almanac(horizon=-6).sun(use_center=1).set",
      "azimuth":"$("%.1f°" % $almanac.sun.az)",
      "altitude":"$("%.1f°" % $almanac.sun.alt)",
      "rightAscension":"$("%.1f°" % $almanac.sun.ra)",
      "declination":"$("%.1f°" % $almanac.sun.dec)",
      "equinox":"$almanac.next_equinox",
      "solstice":"$almanac.next_solstice"
    },
    "moon":{
      "rise":"$almanac.moon.rise",
      "transit":"$almanac.moon.transit",
      "set":"$almanac.moon.set",
      "azimuth":"$("%.1f°" % $almanac.moon.az)",
      "altitude":"$("%.1f°" % $almanac.moon.alt)",
      "rightAscension":"$("%.1f°" % $almanac.moon.ra)",
      "declination":"$("%.1f°" % $almanac.moon.dec)",
      "fullMoon":"$almanac.next_full_moon",
      "newMoon":"$almanac.next_new_moon",
      "phase":"$almanac.moon_phase",
      "fullness":"$almanac.moon_fullness%"
    }
    #else
    "sun":{
      "sunrise":"$almanac.sunrise",
      "sunset":"$almanac.sunset",
    },
    "moon":{
      "phase":"$almanac.moon_phase",
      "fullness":"$almanac.moon_fullness%"
    }
    #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 

        [[[json]]]
            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 , , , , , , , , , .