Parsing Forecast and Current Weather Data From Weatherflow

Hi All.

I have a Weatherflow personal weather station. I am able to retrieve all the metrics from the station, including forecast weather via their api. I am able to pull the data into influxDB, however I am having trouble with parsing the raw metrics. My end goal is to plot the forecast data against the actual readings. However, I am not able to retrieve the forecast data and associate it against the respective future timestamp. If I select “json” as the data format, everything appears as a single data point which gets overwritten and then leads to an enormous mess. I changed to “json_v2”, but I am having some difficulty configuring the telegraf.conf file to get the data in a usable format and associated with the correct timestamp. Below is an example of the data which I am retrieving. I must mention that “hourly” is a sub-section of “forecast”. I have shortened the text below to prevent unnecessary reading.

{
  "latitude": -26.08365,
  "longitude": 27.92197,
  "timezone": "Africa/Johannesburg",
  "timezone_offset_minutes": 120,
  "location_name": "Home",
  "current_conditions": {
    "time": 1672431810,
    "conditions": "Partly Cloudy",
    "icon": "partly-cloudy-night",
    "air_temperature": 15,
    "sea_level_pressure": 1025.8,
    "station_pressure": 847.5,
    "pressure_trend": "steady",
    "relative_humidity": 92,
    "wind_avg": 5,
    "wind_direction": 278,
    "wind_direction_cardinal": "W",
    "wind_gust": 8,
    "solar_radiation": 0,
    "uv": 0,
    "brightness": 0,
    "feels_like": 15,
    "dew_point": 13,
    "wet_bulb_temperature": 14,
    "wet_bulb_globe_temperature": 17,
    "delta_t": 1,
    "air_density": 1.03,
    "lightning_strike_count_last_1hr": 0,
    "lightning_strike_count_last_3hr": 0,
    "lightning_strike_last_distance": 10,
    "lightning_strike_last_distance_msg": "8 - 12 km",
    "lightning_strike_last_epoch": 1672412915,
    "precip_accum_local_day": 20.79,
    "precip_accum_local_yesterday": 7.46,
    "precip_minutes_local_day": 414,
    "precip_minutes_local_yesterday": 132,
    "is_precip_local_day_rain_check": false,
    "is_precip_local_yesterday_rain_check": false
  },
  "forecast": {
...
"hourly": [
      {
        "time": 1672434000,
        "conditions": "Partly Cloudy",
        "icon": "partly-cloudy-night",
        "air_temperature": 15,
        "sea_level_pressure": 1021.8,
        "relative_humidity": 90,
        "precip": 0,
        "precip_probability": 10,
        "precip_type": "rain",
        "precip_icon": "chance-rain",
        "wind_avg": 7,
        "wind_direction": 98,
        "wind_direction_cardinal": "E",
        "wind_gust": 8,
        "uv": 0,
        "feels_like": 14,
        "local_hour": 23,
        "local_day": 30
      },
      {
        "time": 1672437600,
        "conditions": "Partly Cloudy",
        "icon": "partly-cloudy-night",
        "air_temperature": 14,
        "sea_level_pressure": 1021.8,
        "relative_humidity": 90,
        "precip": 0,
        "precip_probability": 5,
        "precip_type": "rain",
        "precip_icon": "chance-rain",
        "wind_avg": 7,
        "wind_direction": 94,
        "wind_direction_cardinal": "E",
        "wind_gust": 8,
        "uv": 0,
        "feels_like": 14,
        "local_hour": 0,
        "local_day": 31
      },
      {
        "time": 1672441200,
        "conditions": "Partly Cloudy",
        "icon": "partly-cloudy-night",
        "air_temperature": 14,
        "sea_level_pressure": 1021.6,
        "relative_humidity": 90,
        "precip": 0,
        "precip_probability": 5,
        "precip_type": "rain",
        "precip_icon": "chance-rain",
        "wind_avg": 7,
        "wind_direction": 89,
        "wind_direction_cardinal": "E",
        "wind_gust": 8,
        "uv": 0,
        "feels_like": 14,
        "local_hour": 1,
        "local_day": 31
      },

Below is also an example of my telegraf.conf file. I have tried multiple formats but I am probably not understanding it sufficiently.

# Configuration for telegraf agent
[[agent]]
  
  interval = "10s"
  
  round_interval = true 
  metric_batch_size = 1000 
  metric_buffer_limit = 1000
  collection_jitter = "0s" 
  flush_interval = "10s"
  flush_jitter = "0s" 
  precision = "" 
  hostname = ""
  omit_hostname = false 

[[outputs.influxdb_v2]]
 
  urls = ["http://192.168.2.88:8086"]
  token = "***********"
  organization = "Home"
  bucket = "mqtt-victron" 

[[inputs.mqtt_consumer]]
 
  servers = ["tcp://192.168.2.22:1883"] 
  topics = [ 
	"telegraf/host01/cpu", 
	"telegraf/+/mem", 
	"sensors/#",
	"N/d4124390e83b/+/+/#", 
	] 
#        [[inputs.mqtt_consumer.topic_parsing]] 
#		topic = "_/_/_/_/_/+"  
#		tags = "N/portal_id/service_type/device_instance/dbus_path/_/_"
#		fields = "_/_/_/_/_/_/_"

  data_format = "json"

[[inputs.system]]

[[inputs.http]] 
    urls = [
    "https://swd.weatherflow.com/swd/rest/better_forecast?station_id=82464&units_temp=c&units_wind=kph&units_precip=mm&units_distance=km&token=[api_token]" 
    ]
    tagexclude = ["url", "host"] 
    data_format = "json_v2" 
    [[inputs.http.json_v2]]
        measurement_name = "Weatherflow"
        [[inputs.http.json_v2.object]] 
            path = "forecast" 
            timestamp_key = "hourly_time" 
            timestamp_format = "unix"
            tags = ["hourly_time"]

Despite reading the documents and some forum posts, I am not able to define the telegraf.conf file in a manner which allows me to plot the forecast data. If someone could please assist with where I am going wrong I would greatly appreciate it.

Thank you so much.

Steven

Can you share what you want the line protocol or output to look like? That might aid in determining what the JSON v2 config should look like.

Just briefly looking at the JSON, it looks like each forecast object has a time, so you could parse each of those.

Hi There

Thanks so much for the reply. I think I have it sorted now.

The config file was correctly formatted. However, my stupidity forgot to change the time range to a future time to see the forecasted values!

1 Like

Thanks to both of you.