Archives

All posts for the month June, 2022

I recently purchased a Weatherflow weatherstation (Tempest) and set it up in the back yard. What I like about this company is that they are very open source friendly and allow access to their API for getting access to the data from your weather station. This data is value for many purposes, including home automation, or weather alerting. My first exercise was to learn how to use the API for making data calls and then doing something with the data. The Tempest device tracks the following weather conditions:

  • Air Temperature
  • Barometric Pressure
  • Relative Humidity
  • Precipitation & accumulation
  • Wind Average and Gust
  • Wind Direction
  • Solar Radiation
  • UV Index
  • Brightness (expressed in lux)
  • Lightning Strike (count, distance, by time)
  • “Feels Like” temperature
  • Heat Index
  • Wind Chill
  • Dew Point
  • Pressure Trend
  • Wet Bulb Temperature

The API provides access to a JSON formatted feed which allows you to write a programmatic method to access, store, and consume the data for just about anything. Here’s what the returned JSON string looks like:

[{'timestamp': 1654725915, 'air_temperature': 28.0, 'barometric_pressure': 1001.2, 'station_pressure': 1001.2, 'sea_level_pressure': 1014.8, 'relative_humidity': 78, 'precip': 0.0, 'precip_accum_last_1hr': 0.0, 'precip_accum_local_day': 0.0, 'precip_accum_local_day_final': 0.0, 'precip_accum_local_yesterday': 0.0, 'precip_accum_local_yesterday_final': 0.0, 'precip_minutes_local_day': 0, 'precip_minutes_local_yesterday': 0, 'precip_minutes_local_yesterday_final': 0, 'precip_analysis_type_yesterday': 0, 'wind_avg': 0.5, 'wind_direction': 359, 'wind_gust': 1.2, 'wind_lull': 0.0, 'solar_radiation': 486, 'uv': 6.04, 'brightness': 58367, 'lightning_strike_last_epoch': 1654217568, 'lightning_strike_last_distance': 39, 'lightning_strike_count': 0, 'lightning_strike_count_last_1hr': 0, 'lightning_strike_count_last_3hr': 0, 'feels_like': 31.8, 'heat_index': 31.8, 'wind_chill': 28.0, 'dew_point': 23.8, 'wet_bulb_temperature': 24.9, 'wet_bulb_globe_temperature': 28.7, 'delta_t': 3.1, 'air_density': 1.15816, 'pressure_trend': 'steady'}]
The Tempest weather station by Weatherflow

Once you setup access to the API, you can then make use the data in real time. I wrote a simple Python script to access the JSON feed and create a text string to be pushed to my LED scrolling weathertube. Here’s the code below:

import urllib, json, requests
from requests.structures import CaseInsensitiveDict

url = "https://swd.weatherflow.com/swd/rest/observations/station/YOURSTATIONID"

headers = CaseInsensitiveDict()
headers["Accept"] = "application/json"
headers["Authorization"] = "Bearer YOUR-API-KEY"

def convertTemp(c):
    f = (c * 1.8) + 32
    return f

resp = requests.get(url, headers=headers)

wx = resp.json()
wxobs = wx["obs"]
tempf = convertTemp(wxobs[0]["air_temperature"])
dewpoint = convertTemp(wxobs[0]["dew_point"])

output = "     Current Conditions:   UV Index: " + str(round(wxobs[0]["uv"], 1)) + "       Temperature: " + str(round(tempf, 1)) + "F""       Dewpoint: " + str(round(dewpoint, 1)) + "F"
output += "     Humidity: " + str(wxobs[0]["relative_humidity"]) + "%""         Pressure: " + str(wxobs[0]["pressure_trend"]) + "      Wind Gust: " + str(wxobs[0]["wind_gust"]) + "MPH" + ""
output += "     Lighting Strikes Last Hour: " + str(wxobs[0]["lightning_strike_count_last_1hr"]) + "      Lighting Last Distance: " + str(wxobs[0]["lightning_strike_last_distance"]) + "Miles"

# WRITEOUT CONDITIONS TO BE PUSHED TO LED MARQUIS TUBE
file_object = open('/scripts/wx/conditions', 'w')
file_object.write(output)

The above Python script is called from a bash script that is executed from cron every 5 minutes:

#!/bin/bash
# RUN FROM CRON EVERY 5 MINUTES OR AS DESIRED.

python3 /scripts/fetchwx.py
msg=`/bin/cat /scripts/wx/conditions`

curl -X POST -F "msg=$msg" -s http://10.50.150.10/msg > /dev/null

In the above example, the host 10.50.150.10 is the IP address of the weather tube which accepts curl POST input to update the display.