Skip to content

Python GUI Application for Raspberry Pi made to display weather data from AEMET, as well as temperature, humidity and pressure measurements.

License

Notifications You must be signed in to change notification settings

riosnav/Pi-Weather-Hub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pi Weather Hub

Pi Weather Hub is a Python GUI Application made to display weather data from Spain's State Meteorological Agency AEMET, as well as temperature, humidity and pressure measurements from a special Google spreadsheet and a SHT31-D sensor.

This app is designed for a Raspberry Pi 3 Model B+ connected to a 1024x600 touchscreen, although you can probably run most of it (see Features) on any device with similar or higher specs and Python 3.7 or later.

Legal notice

This is NOT an official app from AEMET. AEMET, as owner of the reused information, does NOT participate, sponsor or support the reuse that is carried out with this app or the app itself. The forecast data displayed by this app is supossed to always be the latest available.

Features

Demo

This app is divided into three different tabs:

  • Forecast (Tiempo): It presents the weather forecast for the next few days at the upper half, while at the lower half the hourly forecast is displayed. It is possible to scroll through the hourly forecast using the buttons at the sides. The information displayed within this tab it's fetched from AEMET's API and the location by default is Málaga.
  • Radar: It displays national and regional radar pictures and their approximate timestamp. Radar pictures from the last 2 hours can be displayed in a loop using the Animation button.
  • Measurements (Medición): This tab presents measured temperature, relative humidity and pressure data. The latest value is displayed, as well as maximum and minimum values from the last 24 hours and plots with data from the last 7 days. These values come from two different sources:
    • Interior: An Adafruit Sensirion SHT31-D sensor attached to the Raspberry Pi.
    • Exterior: A Google spreadsheet where data is posted periodically by a weather station I made some time ago.

As the measurements functions are probably not especially useful to most people, they can be easily disabled (see Installation).

Prerequisites

Forecast functionality (required)

First, we need to install PyQt5. In my experience, the easiest way to do so on a RPi is:

sudo apt-get install python3-pyqt5

Then use the package manager pip to install the following packages:

pip3 install numpy matplotlib
pip3 install requests

To install system-wide (this may be required in some cases) add sudo to previous commands.

You will need an API Key for AEMET's API. To obtain it, visit AEMET OpenData's website, select Solicitar on Obtención de API Key an enter your email.

Measurements functionality (optional)

Google Sheets integration

The Sheets module expects a spreadsheet with the following format:

Timestamp Temperature (°C) Humidity (%) Pressure (Pa)
4/29/2020 12:16:28 22.6 40.5 101666.34
4/29/2020 12:01:27 22.5 41.7 101668.81
... ... ... ...

In order to use Google's API to fetch data from it, first you will need to enable the API in your Google account and download a credentials.json file. To do so, follow these steps.

Then run the following command to install the library using pip:

pip3 install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib

SHT31-D sensor integration

Carefully follow Adafruit's tutorial on how to install the sensor and the necessary libraries.

Installation

Clone the repository with git (or click the Download ZIP button on this page and unpack it):

git clone https://github.com/frios94/Pi-Weather-Hub.git

If you want a forecast only installation, edit the following line on main.py:

MEASUREMENTS_INTEGRATION_ACTIVATED = True

Changing its value to False. Otherwise leave it as is.

Forecast functionality (required)

Create a Python file inside pi_weather_hub/forecast_worker named _aemet_api_key.py. Open it, add this line with the appropriate value and save it:

AEMET_API_KEY = "YOUR_API_KEY_GOES_HERE"

Additionally, unless you live at Málaga, you probably want to change theses values in aemet_updater.py:

MUNICIPIO_ID = "29067"
RADAR_ID = "ml"

You can find more information about them in AEMET OpenData's documentation.

Finally, if your screen has a bigger resolution than 1024x600, the GUI will scalate very poorly, so I would recommend disabling full-screen. To do that, replace this line of interface.py:

        self.showFullScreen()

with:

        self.show()

Measurements functionality (optional)

Create a directory called measurements_resources in pi_weather_hub/measurements_workers and paste your credentials.json files inside.

Next, create a Python file inside pi_weather_hub/measurements_workers named _spreadsheet_id.py. Open it, add these lines with the appropriate values and save it:

SPREADSHEET_ID = "YOUR_GOOGLE_SPREADSHEET_ID_GOES_HERE"
RANGE_NAME = "EXAMPLE!A2:D"

The first time you run this program, it will open a tab in your web browser so you can log in into your Google account and authorize access to the API.

Usage

To run this app execute the main.py script using Python3:

python3 main.py

To close it quickly tap the Forecast tab 5 times.

If you want this app to run automatically at startup create the following crontab file:

@reboot XAUTHORITY=/home/USERNAME/.Xauthority DISPLAY=:0 /usr/bin/python3 /home/USERNAME/Pi-Weather-Hub/pi_weather_hub/main.py >> /home/USERNAME/Pi-Weather-Hub/console_output.log 2>&1

Contributing

This is a quite specific and personal project and I don't think there are many people out there in need of this app as is, but I'm distributing it in the hope that it will be useful to someone.

Nevertheless, pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

About the GUI

The original QT5 .ui file and resources are included at pi_weather_hub/gui/gui_resources, so it should be relatively easy to adapt the GUI to suit your needs. Just make sure to use a compatible version of the QT5 tools for the current version of Raspbian and don't forget to generate the file interface_rc.py if you change the images, using:

pyrcc5 interface.qrc -o interface_rc.py

Credits

The numbered icons which can be found inside pi_weather_hub/gui/gui_resources/images have been made using Alexey Onufriev's 'Free Weather Icons' as the base.

License

Pi Weather Hub is released under the GNU LGPLv3 or (at your option) any later version.

This software includes source code derived from Google LLC's original work quickstart.py (google_sheets_api_request.py). As such, this file remains licensed under Apache License, Version 2.0.

About

Python GUI Application for Raspberry Pi made to display weather data from AEMET, as well as temperature, humidity and pressure measurements.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages