Weather Station Data

I finally got the time to work on getting my weather station data from weeWX to Home Assistant. I didn’t want to mess up with MQTT so I created a json template for the skin that I am using, seasons (which is the default skin in the last release). Since my weewx is running in a Debian machine, installed using apt, I created the file: /etc/weewx/skins/Seasons/daily.json.tmpl with the following template:

#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","current": {"outTemp":"$current.outTemp.formatted","windchill":"$current.windchill.formatted","heatIndex":"$current.heatindex.formatted","dewpoint":"$current.dewpoint.formatted","humidity":"$current.outHumidity.formatted","insideHumidity":"$current.inHumidity.formatted","barometer":"$current.barometer.formatted","barometerTrendDelta":"$trend.time_delta.hour.format("%.0f")","barometerTrendData":"$trend.barometer.formatted","windSpeed":"$current.windSpeed.formatted","windDir":"$current.windDir.formatted","windDirText":"$current.windDir.ordinal_compass","windGust":"$current.windGust.formatted","windGustDir":"$current.windGustDir.formatted","rainRate":"$current.rainRate.formatted","insideTemp":"$current.inTemp.formatted"}}

Then I edited the file /etc/weewx/skins/Seasons/skin.conf. Look for the following blocks:

[CheetahGenerator]
    ....
    [[ToDate]]
        ....
        [[[RSS]]]
            template = rss.xml.tmpl

Right after that last line add:

[[[json]]]
    template = daily.json.tmpl

If you can’t wait for the next report interval, use wee_reports to force the generation of the reports. Now you can access the json file through your browser: http://IP-ADDRESS/weewx/daily.json
That data in that template is what my Station collects, if yours collects different information you will need to edit the template: http://www.weewx.com/docs/customizing.htm#customizing_templates

Now, in home assistant I create a RESTful sensor with all the values as a dictionary attribute ‘current’ like this:

- platform: rest
  resource: http://weewx.server.ip.address/weewx/daily.json
  name: Weather Station
  json_attributes:
    - current
  value_template: '{{ value_json.hardware }}'

And for each data I create a template sensor like this:

- platform: template
  sensors:
    outside_temperature:
      friendly_name: Outside Temperature
      entity_id:
        - sensor.weather_station
      value_template: "{{ states.sensor.weather_station.attributes.current['outTemp'] }}"
      unit_of_measurement: '°F'

And that should be all you need to get weeWX data into Home Assistant.

8 Likes