From d17850d11a81d6e4d7b71463e214d631b96fa099 Mon Sep 17 00:00:00 2001 From: glitch452 <894128+glitch452@users.noreply.github.com> Date: Sun, 19 Sep 2021 14:44:46 -0400 Subject: [PATCH] v1.4.0 * fix: Don't try to build the DOM elements if there is no sensor data * new: Option to use sudo or not when calling the sensor script * new: Added the spanish translation * Updated changelog and readme * new: Added temp and humidity offset options --- CHANGELOG.md | 10 ++++++++++ MMM-LocalTemperature.js | 15 +++++++++++++-- README.md | 11 ++++++++--- node_helper.js | 5 +++-- translations/en.json | 2 +- translations/es.json | 17 +++++++++++++++++ translations/fr.json | 2 +- 7 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 translations/es.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a59bef..4ebea82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [1.4.0] - 2021-09-19 + +### Added +- An option to decide whether or not to use `sudo` when calling the sensor script +- Spanish Translation (thanks to [rafagale](https://github.com/rafagale)) +- The ability to set a temperature and humidity offset + +### Fixed +- The DOM may try to load when there is no sensor data + ## [1.3.0] - 2019-11-13 ### Added diff --git a/MMM-LocalTemperature.js b/MMM-LocalTemperature.js index 0aa31ed..8927aa9 100644 --- a/MMM-LocalTemperature.js +++ b/MMM-LocalTemperature.js @@ -22,10 +22,13 @@ Module.register("MMM-LocalTemperature", { sensorPin: null, pinScheme: "BCMv2", units: config.units, + useSudo: false, sendTemperature: true, sendHumidity: true, showTemperature: false, showHumidity: false, + temperatureOffset: 0, + humidityOffset: 0, iconView: true, temperatureText: null, // Set in self.start() becuase access to self.translate is needed humidityText: null, // Set in self.start() becuase access to self.translate is needed @@ -119,6 +122,7 @@ Module.register("MMM-LocalTemperature", { if (!axis.isString(self.config.humidityText) || self.config.humidityText.length < 1 ) { self.config.humidityText = self.defaults.humidityText; } if (!self.validPinSchemes.includes(self.config.pinScheme)) { self.config.pinScheme = self.defaults.pinScheme; } if (!axis.isNumber(self.config.sensorPin) || isNaN(self.config.sensorPin)) { self.config.sensorPin = self.defaults.sensorPin; } + if (!axis.isBoolean(self.config.useSudo)) { self.config.useSudo = self.defaults.useSudo; } if (!axis.isBoolean(self.config.sendTemperature)) { self.config.sendTemperature = self.defaults.sendTemperature; } if (!axis.isBoolean(self.config.sendHumidity)) { self.config.sendHumidity = self.defaults.sendHumidity; } if (!axis.isBoolean(self.config.roundTemperature)) { self.config.roundTemperature = self.defaults.roundTemperature; } @@ -126,6 +130,10 @@ Module.register("MMM-LocalTemperature", { if (!axis.isBoolean(self.config.iconView)) { self.config.iconView = self.defaults.iconView; } if (!axis.isString(self.config.decimalSymbol)) { self.config.decimalSymbol = self.defaults.decimalSymbol; } if (!self.validFontSizes.includes(self.config.fontSize)) { self.config.fontSize = self.defaults.fontSize; } + if (axis.isNumber(self.config.temperatureOffset) && !isNaN(self.config.temperatureOffset)) { self.config.temperatureOffset = self.config.temperatureOffset; } + else { self.config.temperatureOffset = self.defaults.temperatureOffset; } + if (axis.isNumber(self.config.humidityOffset) && !isNaN(self.config.humidityOffset)) { self.config.humidityOffset = self.config.humidityOffset; } + else { self.config.humidityOffset = self.defaults.humidityOffset; } // Validate the provided sensorPin var pinObj = pinMapping.find(function(val) { return val[this.scheme] === this.pin; }, { scheme: self.config.pinScheme, pin: self.config.sensorPin }); @@ -198,7 +206,8 @@ Module.register("MMM-LocalTemperature", { instanceID: self.instanceID, scriptPath: self.config.scriptPath, sensorPin: self.config.sensorPin, - attemptNum: attemptNum, + attemptNum, + useSudo: self.config.useSudo, notification: "DATA_RECEIVED" }); }, @@ -237,6 +246,8 @@ Module.register("MMM-LocalTemperature", { self.log(self.translate("DATA_SUCCESS", { "numberOfAttempts": payload.original.attemptNum })); self.log(("Sensor Data: " + JSON.stringify(payload.data)), "dev"); self.sensorData = payload.data; + self.sensorData[self.tempUnit] += self.config.temperatureOffset; + self.sensorData.humidity += self.config.humidityOffset; self.sendDataNotifications(); self.loaded = true; if (self.data.position) { self.updateDom(self.config.animationSpeed); } @@ -304,7 +315,7 @@ Module.register("MMM-LocalTemperature", { if (self.config.showTemperature || self.config.showHumidity) { - if (!self.loaded) { + if (!self.loaded || !self.sensorData) { wrapper.classList.add("loading"); wrapper.classList.add("small"); wrapper.innerHTML += self.translate("LOADING"); diff --git a/README.md b/README.md index c7d99af..bd1f437 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This module reads and displays temperature and humidity information from a senso | Status | Version | Date | Maintained? | Minimum MagicMirror² Version | |:------- |:------- |:---------- |:----------- |:---------------------------- | -| Working | `1.3.0` | 2019-11-13 | Yes |`2.2.1` | +| Working | `1.4.0` | 2021-09-19 | Yes |`2.2.1` | ### Example ![Example of MMM-LocalTemperature](images/sample.png?raw=true "Example screenshot") @@ -14,7 +14,7 @@ This module reads and displays temperature and humidity information from a senso ### 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 'currentweather' module via module notifications +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) @@ -24,7 +24,9 @@ This module reads and displays temperature and humidity information from a senso 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 update && sudo apt-get upgrade && sudo apt-get install build-essential wiringpi` +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](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 @@ -57,11 +59,14 @@ var config = { |:----------------------- |:------------- | `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](https://pinout.xyz) 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-}"` will be replaced with the html tag for the corresponding [FontAwesome](https://fontawesome.com/icons?d=gallery&m=free) icon (this uses the solid style). Use `"{icon-regular-}"`, `"{icon-solid-}"`, `"{icon-brand-}"` 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-}"` will be replaced with the html tag for the corresponding [FontAwesome](https://fontawesome.com/icons?d=gallery&m=free) icon (this uses the solid style). Use `"{icon-regular-}"`, `"{icon-solid-}"`, `"{icon-brand-}"` 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}%"` diff --git a/node_helper.js b/node_helper.js index c21af75..9931f6c 100644 --- a/node_helper.js +++ b/node_helper.js @@ -54,8 +54,9 @@ module.exports = NodeHelper.create({ * @param payload (object) Contains the data required for querying the sensor */ getSensorData: function(payload) { - var self = this; - exec("sudo " + payload.scriptPath + " " + payload.sensorPin + " -m j -a 3", {}, function(error, stdout, stderr){ + const self = this; + const sudo = payload.useSudo ? "sudo " : ''; + exec(sudo + payload.scriptPath + " " + payload.sensorPin + " -m j -a 3", {}, function(error, stdout, stderr){ var result; if (!error) { result = { original: payload, isSuccessful: true, data: JSON.parse(stdout) }; diff --git a/translations/en.json b/translations/en.json index bf3de00..ffce50a 100644 --- a/translations/en.json +++ b/translations/en.json @@ -14,4 +14,4 @@ "SHOW_TEMP_KELVIN": "Temperature: {temperature_var} K", "SHOW_TEMP_FAHRENHEIT": "Temperature: {temperature_var}°F", "SHOW_HUMIDITY": "Humidity: {humidity_var}%" -} \ No newline at end of file +} diff --git a/translations/es.json b/translations/es.json new file mode 100644 index 0000000..049adb5 --- /dev/null +++ b/translations/es.json @@ -0,0 +1,17 @@ +{ + "INVALID_PIN": "El número de pin proporcionado ({pinValue}) es incorrecto. ", + "SUSPENDED": "Suspendido", + "RESUMED": "Reanudado", + "LOADING": "Cargando …", + "DATA_REQUESTED": "Solicitud enviada para obtener los datos del sensor. ", + "DATA_SUCCESS": "Sensor leído correctamente, datos recibidos del sensor después de {numberOfAttempts} intento(s). ", + "DATA_FAILURE_RETRY": "Error de lectura del sensor, reintentando en {retryTimeInSeconds} segundos. ", + "DATA_FAILURE": "Error de lectura del sensor, no se pueden leer los datos del sensor. ", + "UPDATE_SCHEDULED": "Actualización programada para ejecutarse automáticamente cada {minutes} minuto(s). ", + "INITIAL_DELAY": "Delay inicial seteado. Empezando en {seconds} segundo(s). ", + "DECIMAL_SYMBOL": ".", + "SHOW_TEMP_CELCIUS": "Temperatura: {temperature_var}°C", + "SHOW_TEMP_KELVIN": "Temperatura: {temperature_var} K", + "SHOW_TEMP_FAHRENHEIT": "Temperatura: {temperature_var}°F", + "SHOW_HUMIDITY": "Humedad: {humidity_var}%" +} diff --git a/translations/fr.json b/translations/fr.json index 9cef91c..6e0f364 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -14,4 +14,4 @@ "SHOW_TEMP_KELVIN": "Température: {temperature_var} K", "SHOW_TEMP_FAHRENHEIT": "Température: {temperature_var}°F", "SHOW_HUMIDITY": "Humidité: {humidity_var}%" -} \ No newline at end of file +}