gdubrg / Home-Station-with-raspberry

A Home Monitoring Station on Raspberry board. Temperature, himidity, pressure, Air Quality and Weather Forecast.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Home Monitoring Station with Raspberry

Project

This is a Home Monitoring Station based on the Raspberry Pi board designed to collect and display the following values on a portable screen:

  • Temperature (C°)
  • Humidity (%)
  • Pressure (hPa)
  • Air Quality (NO2, PM 2.5 and 10)
  • Current Weather (min, max and current temperature and humidity)
  • Weather Forecast (4 days)

Graphical User Interface

A graphical user interface is used to clearly display all values and it is designed to be displayed in touch screen monitor connected to the Raspberry board. An example of the interface is the following:

As shown, the GUI is divided into 3 different columns:

  1. Environment Data: in the first column on the left, the current temperature, humidity and pressure are reported. These data are collected by a real sensor (the BME280 produced by the Bosch company or equivalent) directly connected to the board. Min and max values are also reported and buttons called 'graphs' allow to check the temporal summary of collected data:

  1. Air Quality: values about the NO2 (Nitrogen dioxide), PM (Particulate Matter) 2.5 and 10 are reported. Data are collected through the Arpae (Agenzia regionale prevenzione, ambiente ed energia dell'Emilia-Romagna) website, and then are valid only for the aforementioned italian region. The colored rectangle on the left side of each value indicates the level of air quality (green: ok, yellow: acceptable, orange: medium, red: bad, purple: harmful)
  2. Weather and Forecast: the current weather (in terms of temperature, its min and max values and humidity) and weather forecast about the next 4 days are reported. These data are collected through the OpenWeather API (free version). Since this service is global, weather and forecast can be used worldwide.

On the top of the GUI, the current date and the current time are reported.

This GUI is designed and optimized for a 5'' 800x480 touch screen (further details are reported in the Hardware Requirements section).

Remote Visualization

Thanks to the Telegram app, you can easily get the graphs about the current temperature, humidity and pressure, just sending a message to the bot with the following texts: 'temp', 'humi' or 'pres'.

How To

If you plan to launch this script on your Raspberry board, check the following documentation both for the software and hardware requirements.

Hardware Requirements

The project is tested with the following components:

  • Raspberry Pi 4 (4 GB RAM version). However, the computational load of the Home Monitoring Station is very low (about 3% of CPU usage and less than 300MB of RAM), then I suppose you can run the script even with an older version of the board.
  • Adafruit 5'' (800x480) touch screen, PWM-able backlight. Here the link to the product. Note that you can use any screen also with different resolutions, maybe you can experience some graphical errors.
  • BME280 sensor: the sensor used to collect environmental data.

Software Requirements

Run the program with Python 3. Please, install all the packages required listed in the requirements.txt file. Remember to activate the I2C interface of the Raspberry board.

Web-related Requirements

Air quality and weather data are collected through web-based API. Then, as you can imagine, you need an internet connection to collect these data. For the weather forecast, you have to obtain the secret token from OpenWeatherMap API creating a free account. To remote control the app, you need to activate a Telegram bot. Arpae website does not need specific requirements.

Launch the script (manually)

Once cloned this repository, open a terminal in the project folder and type: python3 main.py. If you have python installed in a virtual environment, launch the script accordingly.

Launch the script (automatically at boot)

You can use the file launcher.sh to automatically launch the script every time you turn on the Raspberry Pi board. There are several ways to do that. I have used this solution:

  1. Navigate into the ~/.config/autostart directory
  2. Create a new *.desktop file with the following lines:
[Desktop Entry]
Type=Application
Terminal=true
Name=home_station
Exec=<absolute_path_to_your_script>/launcher.sh

Note that I have added a sleep function (10 seconds) to wait the WiFi card turns on.

Settings

You can adapt this program to your needs.

From the settings file you can change the following items:

  • MODULES: decide which module of the project is activated or not.

    • BME280: collection of temperature, humidity and pressure data from the BME280 sensor.
    • OPENWEATHER: get current weather and weather forecast data from the OpenWeatherMap API.
    • ARPAE: get air quality data from Arpae API.
    • TELEGRAM: telegram bot for the remote visualization of the temperature, humidity and pressure graphs.
  • RELOAD SECONDS: it is possible to set how many times (in seconds) sampling data.

    • TEMPERATURE: seconds to get data from the BME280 sensor.
    • WEATHER: seconds to get data from OpenWeatherMap API. The free account provides new data every 3 hours (10800 seconds, that is the default value).
    • ARPAE: seconds to get data from Arpae API. Here, data are updated every 1 hour (3600 seconds, that is the default value).
    • GRAPHS: seconds to create new graphs to be displayed. This value may be equal or greater than the TEMPERATURE reload seconds.
  • ARPAE: here you can change the value for the Arpae API. STATION ID: id of the air quality station that you want to use. Here you can find the list of available monitoring stations. Note that each station provides different data.

  • WEATHER: settings about the data samples from OpenWeatherMap API

    • CITY: place of the weather data.
    • TOKEN: this is the secret token for your account. You have to sign in the website to get this token.
  • TELEGRAM:

    • TOKEN: this is the secret token of your Telegram bot
    • CHAT ID: the id of your chat, in this way you can select users that are able to get data from the home station.
  • DATA COLLECTION: settings about the buffer to store the collected values.

    • HOW MANY DAYS: put how many days you would like to store data from the BME280 sensor.

Technical Details

If you do not live in Italy, and specifically in Emilia Romagna, the Arpae service is useless. You can deactivate it from the settings file. Despite this, this project can be an interesting starting point to develop your own Home Monitoring Station. Then, technical details are provided (work in progress).

Code Structure

The entry point of the code is the file main-py. The GUI is developed using the Qt Libraries.

Execution

The execution of the program is based in threads: in this way, each module can be adapted with its timing. Indeed, several threads are started and run in parallel to collect data from the sensor, the websites and so on. Threads are able to transfer data through the Qt signals and shared python lists.

The CPU usage is low (only 3%) on the quad-core Cortex-A72 (ARM v8) 64-bit SoC @1.5GHz of the Raspberry Pi 4. Also the RAM usage is low, since less than 300MB are required.

Issues

  • Telegram bot: I have noticed that the Telegram bot is not completely reliable, since the method MessageLoop sometimes gives timeout errors that cannot be handled by the try-except python operations. Then, if you want an high reliability of the system, please deactivate this module.
  • Database: you can easily note that no databases are included in the project. The use of threads and databases on Raspberry is not so reliable (many random errors with database cursors), then I implemented the project without the use of database. After all, this is just a monitoring station and not a complete weather station to collect data during a long time interval.

About

A Home Monitoring Station on Raspberry board. Temperature, himidity, pressure, Air Quality and Weather Forecast.


Languages

Language:Python 78.5%Language:HTML 21.2%Language:CSS 0.2%Language:Shell 0.1%