---
title: 'Server room temperature difference monitoring'
---
###### Author: Oscar kihmlman` `(ok222iz)
## Table of Contents
[TOC]
## Overview
This project aims to create an IoT device that monitors the temperature inside and outside of a room to calculate the temperature difference. The collected data will be displayed in Home Assistant. The estimated time required for this project is around 5-10 hours.
## Objective
The purpose of this project is to determine if additional cooling is required for my server room during the summer. To achieve accurate readings, two temperature sensors will be used to measure the temperature difference between the ambient temperature in the apartment and the temperature in the server room. By analyzing this temperature difference, I can assess the need for additional cooling and potentially add more hardware to improve the server room's conditions.
## Materials
The following materials are required for this project:
* Raspberry Pi Pico W
* 2x DHT11 sensors
* Micro USB cable
* Breadboard
* Cables
* Existing Home Assistant server
## Computer Setup
To begin, the Pico W needs to be flashed with MicroPython firmware. You can download the firmware [here](https://micropython.org/download/rp2-pico-w/). Follow these steps to flash the firmware:
1. Hold down the BOOTSEL button on the Pico.
2. Connect the Pico to your computer using a USB cable.
3. The Pico will appear as a USB drive.
4. Copy the downloaded UF2 file to the Pico.
5. Wait for the Pico to automatically disconnect and reconnect to your computer. This indicates that the firmware has been successfully installed.
To program the Pico, you will need an Integrated Development Environment (IDE) such as Visual Studio Code. Follow these steps for the setup:
1. Install Node.js from [here.](https://nodejs.org/en)
2. Download Visual Studio Code from [here](https://code.visualstudio.com/Download) and install it.
3. Open Visual Studio Code and install the Pymakr extension by clicking on "Extensions" on the left side of the IDE. Search for Pymakr and click the install button.
4. Once installed, a new Pymakr icon should appear on the left side of Visual Studio Code. Click on it and create a new project.
## Connecting sensors to Pico
Follow the diagram below to connect the sensors to the Pico:

* The left pin of the DHT11 sensors is the data pin.
* The middle pin is positive.
* The right pin is ground.
* Connect the wires accordingly: Red for positive, Black for negative, and Blue for data.
## Platform
The chosen platform for this project is Home Assistant, an open-source smart home hub. Home Assistant allows for the connection and control of various IoT devices, enabling automation and interoperability among different brands and protocols such as Wi-Fi and Zigbee. It provides customization options to tailor the user interface and layout. Home Assistant was selected as the platform due to its compatibility with existing IoT devices and self-hosted nature, which ensures data privacy and functionality even if the network connection goes down.
## Code
The code for this project can be found [here.](https://github.com/Raczoo/temperature-difference-monitoring)
* [Main.py](https://github.com/Raczoo/temperature-difference-monitoring/blob/main/main.py) contains the main code.
* [Secrets.py](https://github.com/Raczoo/temperature-difference-monitoring/blob/main/secrets.py) stores the Wi-Fi SSID and password for the Pico to connect to.
The code creates a web server that collects data from the two DHT11 sensors and hosts it as a JSON. Sensor data is updated only when a client refreshes the webpage.
The configuration for Home Assistant is done in the configuration.yaml file, where a REST sensor is set up to retrieve data from the Pico via HTML.
## Connectivity
To retrieve temperature and humidity data from the Pico and display it in Home Assistant with appropriate units and device classes for better integration and automation, the configuration.yaml file in Home Assistant needs to be configured. The code for the configuration can be found [here](https://github.com/Raczoo/temperature-difference-monitoring/blob/main/configuration.yaml)
The configuration sets up five sensors in Home Assistant. These sensors retrieve data from a REST resource via HTTP. The wireless protocol chosen for communication is Wi-Fi.
Sensor 1: "pico_w_report" is a REST sensor that fetches data from http://10.10.0.94:80. It expects JSON attributes named "hum," "temp," "hum2," and "temp2" from the REST resource. The value of the sensor is the entire JSON object received, and the data from the Pico is updated every 30 seconds.
Sensors 2 to 5: These are template sensors associated with specific attributes of the "pico_w_report" sensor. Each sensor has a friendly name, a device class, and represents temperature or humidity.
Sensor 6: This sensor calculates the temperature difference between the two temperature readings (sensor 2 and sensor 4).
## Presenting data
To present the data in Home Assistant, add an appropriate card to the Home Assistant dashboard. Follow these steps:
1. Click the three dots in the top right corner of the Home Assistant homepage.
2. Select "Customize Control Panel."
3. Click "Add Card" and choose the desired card type (e.g., Entities Card).
4. Add the desired entities to the card, and customize the display name if needed.
5. The data is automatically saved every time the REST sensor requests new data (every 30 seconds).
The Home Assistant dashboard can then display the data as configured.


### Notification
To set up a notification in Home Assistant, go to "Settings," then "Automations," and add a new automation. Configure the automation as follows:
1. In the "Event" section, add a numerical condition for the sensor that triggers the automation (e.g., the temperature sensor in the server room).
2. Optionally, you can use the temperature difference sensor as a condition.
3. Set the desired condition (e.g., temperature difference should be 9 degrees Celsius).
4. Configure the action to send a message/notification to your phone.

## Conclusion
Overall, the project went well, and the sensor performs as expected. It allows me to determine whether additional cooling is required for my server room or if I can add more hardware to my home lab. While the project could have been improved by soldering the components instead of using a breadboard and creating a 3D-printed case, it provided valuable learning experiences. If I were to do this project again, I would consider using MQTT instead of HTTP. I have gained knowledge through this project and intend to continue creating various types of sensors to make my home even smarter. Home Assistant stores the collected data indefinitely, unless removed.


