glitch452 / MMM-LocalTemperature

A MagicMirror² module that reads temperature and humidity information from a DHT sensor connected to a Raspberry Pi.
MIT License
22 stars 13 forks source link

MMM-LocalTemperature

This is a module for the MagicMirror² smart mirror project.

This module reads and displays temperature and humidity information from a sensor connected to a Raspberry Pi GPIO pin.

Status Version Date Maintained? Minimum MagicMirror² Version
Working 1.4.0 2021-09-19 Yes 2.2.1

Example

Example of MMM-LocalTemperature

Notable Features

  1. Get data from a DHT11, DHT22, or AM2302 sensor
  2. Display the temperature and/or humidity from this module and/or,
  3. Send the temperature to the built in 'weather' module via module notifications

Dependencies

  1. A local 'c' program, used to read the data from the sensor (included)
  2. The WiringPi library (Free to install and use)

Installation

To install the module, use your terminal to:

  1. Navigate to your MagicMirror's modules folder. If you are using the default installation directory, use the command:
    cd ~/MagicMirror/modules
  2. Copy the module to your computer by executing the following command:
    git clone https://github.com/glitch452/MMM-LocalTemperature.git
  3. Install the WiringPi library by executing the following command:
    sudo apt-get -y update && sudo apt-get -y upgrade && sudo apt-get -y install build-essential wiringpi Note: If running on Raspberry Pi 4, use the following process to update wiringpi
    http://wiringpi.com/wiringpi-updated-to-2-52-for-the-raspberry-pi-4b
  4. Make sure the DHT program that reads the sensor data is executable by executing the following command:
    cd MMM-LocalTemperature && chmod +x DHT

Using the module

MagicMirror² Configuration

To use this module, add the following configuration block to the modules array in the config/config.js file:

var config = {
    modules: [
        ...
        {
            module: "MMM-LocalTemperature",
            position: "top_left", // Only add a position if you want this module to display the data
            header: "Room Temperature",
            config: {
                sensorPin: 22, // For GPIO 22
                ...
                // See below for more Configuration Options
            }
        },
        ...
    ]
}

Configuration Options

Option Details
sensorPin REQUIRED - The GPIO Pin number that is connected to the data pin on the sensor. The default pin scheme is the standard Raspberry Pi (BCM) GPIO numbering system for Rev 2 Pi's. See the pinScheme option for other numbering systems.
Type: number
pinScheme Optional - The pin numbering system to use for the sensorPin option. See this interactive pinout diagram for more details on pin usage for the Raspberry Pi.
Note: Ultimately the sensorPin value will be converted to the WiringPi system, becuase that is the library used by the DHT program to interact with the pin. However, any of these numbering systems can be used, since this module will convert the sensorPin value automatically based on the selected scheme.
Type: string
Default: "BCMv2"
Options:
- "BCMv2" The standard Raspberry Pi GPIO numbering system on current (Rev 2) boards
- "BCMv1" The standard Raspberry Pi GPIO numbering system on older (Rev 1) boards
- "BOARD" The physical pin numbering on the GPIO header
- "WPI" The WiringPi numbering system
useSudo Optional - Whether or not to use sudo when calling the script to get the sensor data. A value of true uses sudo, false does not use sudo. (Added in v1.4.0)
Type: boolean
Default: false
units Optional - The unit system to use for the temperature value. ("metric" = Celcius, "imperial" = Fahrenheit, "default" = Kelvin)
Type: string
Default: config.units
Options: "metric", "imperial", "default"
sendTemperature Optional - When true, an "INDOOR_TEMPERATURE" notification is sent to the other modules when the data is received from the sensor. This can be used to display the indoor temperature within the built-in 'currentweather' module. The 'currentweather' module's showIndoorTemperature option must be set to true for it to display the data sent from this module.
Type: boolean
Default: true
sendHumidity Optional - When true, an "INDOOR_HUMIDITY" notification is sent to the other modules when the data is received from the sensor. This can be used to display the indoor humidity within the built-in 'currentweather' module. The 'currentweather' module's showIndoorHumidity option must be set to true for it to display the data sent from this module.
Type: boolean
Default: true
showTemperature Optional - When true, the module will display the temperature on screen.
Type: boolean
Default: false
showHumidity Optional - When true, the module will display the humidity on screen.
Type: boolean
Default: false
temperatureOffset Optional - A value to add to the temperature value from the sensor (in the selected units). It can be positive or negative. This can be used to adjust for a sesor that is consistently off by a specific amount.
Type: number
Default: 0
humidityOffset Optional - A value to add to the humidity value from the sensor. It can be positive or negative. This can be used to adjust for a sesor that is consistently off by a specific amount.
Type: number
Default: 0
iconView Optional - When true, a view which uses icons and the data will be shown instead of the standard temperature and humidity text. The data shown depends on the showTemperature and showHumidity options.
Type: boolean
Default: true
temperatureText Optional - The text template to be used when displaying the temperature data. The stings "{temperature}" and "{humidity}" will be replaced with the temperature and humidity values respectively. For icons, "{icon-<fa_name>}" will be replaced with the html tag for the corresponding FontAwesome icon (this uses the solid style). Use "{icon-regular-<fa_name>}", "{icon-solid-<fa_name>}", "{icon-brand-<fa_name>}" to specify the solid / regular type or when using a brand icon. Ex: use "{icon-solid-thermometer-half}" for the fa-thermometer-half icon.
Type: string
Default: "Temperature: {temperature}°C/°F/K"
humidityText Optional - The text template to be used when displaying the humidity data. The stings "{temperature}" and "{humidity}" will be replaced with the temperature and humidity values respectively. For icons, "{icon-<fa_name>}" will be replaced with the html tag for the corresponding FontAwesome icon (this uses the solid style). Use "{icon-regular-<fa_name>}", "{icon-solid-<fa_name>}", "{icon-brand-<fa_name>}" to specify the solid / regular type or when using a brand icon. Ex: use "{icon-solid-thermometer-half}" for the fa-thermometer-half icon.
Type: string
Default: "Humidity: {humidity}%"
fontSize Optional - The main font size to use for the module text.
Type: string
Default: 'medium'
Options: 'x-small', 'small', 'medium', 'large', 'x-large'
decimalSymbol Optional - The character to use as the decimal symbol.
Type: string
Default: "."
roundTemperature Optional - When true, the temperature value will be rounded to the nearest integer.
Type: boolean
Default: false
roundHumidity Optional - When true, the humidity value will be rounded to the nearest integer.
Type: boolean
Default: false
scriptPath Optional - The location of the DHT program. This is the fully qualified path including the program file name.
Type: string
Default: <module_folder_path>\DHT
updateInterval Optional - The number of minutes to wait before requesting an update of the data from the sensor. The minimum value is 0.5.
Type: number
Default: 5
retryDelay Optional - The number of seconds to wait before trying to request the sensor data after a sensor read failure. The minimum value is 10. Since the reading of the data from the sensor is time sensitive, and can be interrupted by context switching, the DHT program is told to try up to 3 times. This option is the amount of time for this module to wait before the next 3 tries.
Type: number
Default: 10
initialLoadDelay Optional - The number of seconds to wait before starting to run this module. The minimum value is 0.
Type: number
Default: 0
animationSpeed Optional - The number of milliseconds to use for the animation when updating the on-screen display of this module. The minimum value is 0.
Type: number
Default: 0

Connecting the Sensor to the Raspberry Pi

Here are some diagrams that you may find useful when connecting your sensor. See the guide from adafruit.com for more wiring and programming information.

DHT11 sensor

Example of a DHT11 sensor with a Raspberry Pi

DHT22 / AM2302 sensor

Example of a DHT22 / AM2302 sensor with a Raspberry Pi

AM2302 sensor with wires

Example of a AM2302 sensor with a Raspberry Pi

Customizing the DHT Program

The DHT program is a c coded program used to read the sensor data. A c program is required to read the sensor data because the data is transmitted by extremely short pulses of signal and the c code executes much faster than python.

The included DHT program is something I pieced together based on code from dht22 by nebulx29 and the Python DHT Sensor Library by Adafruit.

If you would like to customize the DHT program, you can edit the file DHT.c with your favorite editor, then re-compile it using the following command: cc -Wall DHT.c -o DHT -lwiringPi

Updates

To update the module to the latest version, use your terminal to:

  1. Navigate to your MMM-LocalTemperature folder. If you are using the default installation directory, use the command:
    cd ~/MagicMirror/modules/MMM-LocalTemperature
  2. Update the module by executing the following command:
    git pull

If you have changed the module on your own, the update will fail.
To force an update (WARNING! your changes will be lost), reset the module and then update with the following commands:

git reset --hard
git pull

Manually Choose a Version

To use an older version of this module, use your terminal to:

  1. Navigate to your MMM-LocalTemperature folder. If you are using the default installation directory, use the command:
    cd ~/MagicMirror/modules/MMM-LocalTemperature
  2. Fetch all the available tags
    git fetch
  3. Show all the available tags
    git tag
  4. Checkout one of the available tags
    git checkout {tag_name}
    Example: git checkout v1.0.0

To switch back to the latest version, use your terminal to:

  1. Navigate to your MMM-LocalTemperature folder. If you are using the default installation directory, use the command:
    cd ~/MagicMirror/modules/MMM-LocalTemperature
  2. Checkout the master branch
    git checkout master

License

The MIT License (MIT)

Copyright © 2018 David Dearden

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

The software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.