Weather Station Data

gosh, thats so obvious! I didnt even think of that.

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

Seems like I’m close to getting this to work. I have the json.daily working for the weather station, but when I add a template sensor like the Outside Temperature I get the following error:

Error loading /config/configuration.yaml: ‘utf-8’ codec can’t decode byte 0xb0 in position 170: invalid start byte

Any ideas for a fix?

@eriberg, can you post that section of your configuration.yaml?

1 Like

sensor:

Weather prediction

  • platform: yr

  • platform: rest
    resource: http://192.168.0.19/weewx/daily.json
    name: Weather Station
    json_attributes:

    • current
      value_template: ‘{{ value_json.hardware }}’
  • 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’

I’ve narrowed it down to the degrees symbol before the F. When I take that out, it works. My install is on Raspbian, so maybe I need a dependency? I just copied the sensor info from above.

1 Like

So, it sounds like this same issue: Unable to read file with ° symbol if not in configuration.yaml

Got it fixed. Thanks for your work on this.

Great info…

Can you create detailed user guide for ‘dumbs’ like me…

What needed…
Code sharing… etc…

Thank you…

Hi kslb.
At a high to medium level;

On an rpi (or some other sort of server running ubuntu/debian)
install dnsmasq (apt-get install dnsmasq)
This will give you your own local DNS server, which you have full control over.
dnsmasq is a simple lightweight DNS server, which uses entries in the local hosts file. Edit the hosts file (/etc/hosts) and add in and entry like this, substituting 192.168.1.xx for the IP address of your rpi/server

192.168.1.xx rtupdate.wunderground.com

You then need to change the DNS server being sent by your router, or whatever is doing DHCP, to send the address of your rpi/server instead. Thats very router specific, and some routers, particularly if supplied by your ISP might not let you.

Install weewx as per this document:
http://www.weewx.com/docs/debian.htm

You then need to configure weewx to get the data for your exact weather station. Ive omitted this part, mostly because i cant remember it, but theres heaps of info online RE this

You then need to setup your config for weewx
in /etc/weewx/weewx.conf
if you want to still send data to Wunderground, setup the [[Wunderground]] section, adding your station ID and credentials.

for MQTT, configure the [[MQTT]] section. Below are my examples of both

[[Wunderground]]
    # This section is for configuring posts to the Weather Underground.

    # If you wish to do this, set the option 'enable' to true,
    # and specify a station (e.g., 'KORHOODR3') and password.
    enable = true
    station = <omitted>
    # To guard against parsing errors, put your password in quotes:
    password = <omitted>

    # Set the following to True to have weewx use the WU "Rapidfire"
    # protocol. Not all hardware can support it. See the User's Guide.
    rapidfire = False

[[MQTT]]
    server_url = mqtt://<omitted>:1883
    topic = weather
    unit_system = METRIC
    retain = True

Hope that helps!

I managed to use DNAT and to use data as “Observer” weather station device in weewx software in my old Raspberry Pi 3…
Currently I’m still publishing data to WUnderground via weewx because HA is still getting data from WU API service…

Now there is the latest quest how to create MQTT protocol to transfer data on-the-go when new data arives to weewx (every 16 seconds) and automaticly transfer (publish) this to MQTT to HA… Currently data is changed on weewx page every 5 minutes (it can stay this, but on HA I would like real time data because of my automation regarding UV sensor etc…)

In that step I will need help…

Which plugin if any to use in weewx for MQTT protocol?

How to make automation on weewx to transfer data or this can be handeled via HA HTTP or MQTT request?

Probably this is the correct way:

Yep – theres an mqtt plugin for weewx.

I have actually found that data getting into WU via weewx is more reliable than data getting straight from the weather station into WU. I have no idea why that is, and havent bothered looking, but WU updates every 150 seconds as set in weewx, whereas when the weather station goes direct it could be every 5 minutes, or an hour – its all over the place.

I have about 10 mqtt sensors setup with data coming in from weewx, and the only thing i pull from WU direct is the wind “String” – ie calm etc

Via json template I succesfully read the weather sensor state - but this was not my goal…
My goal was to get data via MQTT - which I set it up and HA do get somekind welcome HELO from weather station…
But I do not know how to make sensor with MQTT protocol for weather station.
Can you give me some example, like for “outTemp” or some other, then I can create other sensor with no struggle.

json template is very good to discover me, which sensor do make (produce) some data…

Theres an MQTT configuration section in weewx.
This sets the base topic.

Lets say you set it to “weather_station”
in HA, setup a mqtt sensor to “weather_station/outTemp”

OK, I received data for weather/#, but I do not receive any other data…

My configuration in HA:

  - platform: mqtt
    name: "Vremenska postaja"
    state_topic: "weather/#"

  - platform: mqtt
    name: "Temperatura"
    state_topic: "weather/outTemp"
    value_template: '{{ value_json.value }}'
    unit_of_measurement: "°C"

Should I make some other setting in weewx so that I would receive desired value like “outTemp”?

1 Like

Should be in weewx some other configuration regarding MQTT?

    [[MQTT]]
        server_url = mqtt://XXX:[email protected]:1883/
        topic = weather
        unit_system = METRIC
        retain = True

So weewx publishes 2 different sets of data
Theres the giant JSON payload, which goes to the base topic

Each of those json key value pairs also gets sent to its own topic.

So your sensor for outTemp doesnt need the value_template line, its not needed – the actual raw data gets sent to weather/outTemp

Yea… but no data is received… With or withouth json value_template…
Just don’t working… Am stuck here…

Perhaps using MQTTLens you can see if the data is coming in?

I will try it…