Skip to content

Instantly share code, notes, and snippets.

@dhowland
Last active January 26, 2024 22:27
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dhowland/158c01b0cfb65e6dc09c316402930c67 to your computer and use it in GitHub Desktop.
Save dhowland/158c01b0cfb65e6dc09c316402930c67 to your computer and use it in GitHub Desktop.
Telegraf config for AmbientWeather API

This is the most straightforward config for parsing the Ambient Weather API into a time series database with Telegraf. I use InfluxDB to store the data and Grafana to view the data.

Note that this is not a complete Telegraf config. What follows is a fragment that you would add to the bottom of your telegraf.conf file. You must set up Influx yourself.

You MUST replace the xxxxxxxx strings in the urls parameter with your personal Application key and API key. See https://www.ambientweather.com/api.html for help if you don't have your keys.

The measurement name can be set to anything you want with the name_override parameter.

The devices endpoint gives data for all weather stations associated with your account, but this config simply takes the first one. This is done with the json_query = "0.lastData" line. Other devices could be selected by changing the 0 to another number. Properly handling multiple weather stations is too complex for any sane config of the http plugin for Telegraf. Hard-coding the device also means that the name tag must be manually specified in the [inputs.http.tags] section. If you don't need a tag for the measurement, you can remove the section all together. You could also add other hard-coded tags if you wish.

It is not adviseable to change the interval to be something faster. You would just fill your database with multiple scans of the same timeslice. Be kind to their servers :)

[[inputs.http]]
# 5 minutes
interval = "300s"
name_override = "weather_station"
urls = [
"https://api.ambientweather.net/v1/devices?applicationKey=xxxxxxxx&apiKey=xxxxxxxx"
]
## API can be slow sometimes, use long timeout
timeout = "30s"
data_format = "json"
tagexclude = ["url", "host"]
json_query = "0.lastData"
fielddrop = ["tz", "date"]
json_time_key = "dateutc"
json_time_format = "unix_ms"
json_timezone = "UTC"
[inputs.http.tags]
name = "My Station Name"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment