-
Notifications
You must be signed in to change notification settings - Fork 56
Part 1. A Dark Sky Dashboard
Now for the fun part. We are ready to start using the Dark Sky API to create a weather dashboard and capture the weather history for wherever we choose. To do this, we are going to use the Python script: https://github.com/initialstate/wunderground-sensehat/blob/master/darksky.py. This script simply calls the Dark Sky API using your API key and retrieves the weather information on a specified time interval. It also streams that data to your Initial State account, which will allow you to create a Dark Sky weather dashboard.
You can either copy this script to your Pi, or access it through the Github repository that we cloned earlier. You can do this by changing into your wunderground-sensehat directory by typing:
$ cd wunderground-sensehat
From here, you'll be able to access the python file that we'll run to create our weather dashboard.
Before you run it, you need to set your desired parameters and insert your keys. Nano into the darksky.py file by typing:
$ nano darksky.py
Then edit the section near the top of the script:
# --------- User Settings ---------
CITY = "Franklin"
GPS_COORDS = "35.9260096,-86.868537"
DARKSKY_API_KEY = "PLACE YOUR DARK SKY API KEY HERE"
BUCKET_NAME = ":partly_sunny: " + CITY + " Weather"
BUCKET_KEY = "ds1"
ACCESS_KEY = "PLACE YOUR INITIAL STATE ACCESS KEY HERE"
MINUTES_BETWEEN_READS = 15
METRIC_UNITS = False
# ---------------------------------
You need to set the desired GPS coordinates and city name. You also have to insert your Dark Sky API key and your Initial State account access key or your data isn't going to go anywhere. The MINUTES_BETWEEN_READS parameter will set how often your script will poll the Dark Sky API for weather information. 15 minutes provides a nice interval long-term. For the sake of short-term testing, you can set this to 0.5 minutes. The METRIC_UNITS option allows you to choose between Fahrenheit/Celsius, MPH/KPH, etc.
Once you have your parameters set, you are ready to run your script:
$ python darksky.py
If you are ssh'ing into your Pi and want to leave this script running uninterrupted for a long time, you can use the nohup command (no hang-up) as follows:
$ nohup python darksky.py &
This script is going to do a bit more than just read the weather data and send it to Initial State. This script is going to take advantage of the emoji support built into Initial State's tools to make the dashboard a bit more sexy. You can see the logic used to take the weather status from the currently -> icon and convert it to an emoji token in the weather_icon function. Something similar happens for the moon phase in the moon_icon function and wind direction in the wind_dir_icon function.
Go to your Initial State account and look at your data. The screenshot of the dashboard above was taken after 9 days of data collection running at 15 minute intervals. You can edit your dashboard by changing chart types with the cog icon in the top right corner of each tile and by right-clicking on a tile to resize/move it around.
If you want to use the dashboard layout above as your dashboard, you can import this layout into your data bucket by following the instructions at https://init.st/gp9dt8h .
The public share URL for this dashboard is https://go.init.st/0hw08py .
The next step in this project is to start collecting weather data from our own sensors.