Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop add jeedom update #26

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions MMM-LocalTemperature.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -119,13 +122,18 @@ 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; }
if (!axis.isBoolean(self.config.roundHumidity)) { self.config.roundHumidity = self.defaults.roundHumidity; }
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 });
Expand Down Expand Up @@ -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"
});
},
Expand Down Expand Up @@ -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); }
Expand Down Expand Up @@ -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");
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ 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")

### 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)
Expand All @@ -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:<br />`cd ~/MagicMirror/modules`
2. Copy the module to your computer by executing the following command:<br />`git clone https://github.com/glitch452/MMM-LocalTemperature.git`
3. Install the WiringPi library by executing the following command:<br />`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:<br />`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:<br />`cd MMM-LocalTemperature && chmod +x DHT`

## Using the module
Expand Down Expand Up @@ -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.<br />**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. <br />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. <br />**Type:** `string`<br />**Default:** `"BCMv2"`<br />**Options:**<br />- `"BCMv2"` The standard Raspberry Pi GPIO numbering system on current (Rev 2) boards<br />- `"BCMv1"` The standard Raspberry Pi GPIO numbering system on older (Rev 1) boards<br />- `"BOARD"` The physical pin numbering on the GPIO header<br />- `"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)<br />**Type:** `boolean`<br />**Default:** `false`
| `units` | *Optional* - The unit system to use for the temperature value. (`"metric"` = Celcius, `"imperial"` = Fahrenheit, `"default"` = Kelvin)<br />**Type:** `string`<br />**Default:** `config.units`<br />**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.<br />**Type:** `boolean`<br />**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.<br />**Type:** `boolean`<br />**Default:** `true`
| `showTemperature` | *Optional* - When `true`, the module will display the temperature on screen.<br />**Type:** `boolean`<br />**Default:** `false`
| `showHumidity` | *Optional* - When `true`, the module will display the humidity on screen.<br />**Type:** `boolean`<br />**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.<br />**Type:** `number`<br />**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.<br />**Type:** `number`<br />**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. <br />**Type:** `boolean`<br />**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](https://fontawesome.com/icons?d=gallery&m=free) 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. <br />**Type:** `string`<br />**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](https://fontawesome.com/icons?d=gallery&m=free) 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. <br />**Type:** `string`<br />**Default:** `"Humidity: {humidity}%"`
Expand Down
5 changes: 3 additions & 2 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) };
Expand Down
2 changes: 1 addition & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"SHOW_TEMP_KELVIN": "Temperature: {temperature_var} K",
"SHOW_TEMP_FAHRENHEIT": "Temperature: {temperature_var}&deg;F",
"SHOW_HUMIDITY": "Humidity: {humidity_var}%"
}
}
17 changes: 17 additions & 0 deletions translations/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"INVALID_PIN": "El número de pin proporcionado ({pinValue}) es incorrecto. ",
"SUSPENDED": "Suspendido",
"RESUMED": "Reanudado",
"LOADING": "Cargando &hellip;",
"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}&deg;C",
"SHOW_TEMP_KELVIN": "Temperatura: {temperature_var} K",
"SHOW_TEMP_FAHRENHEIT": "Temperatura: {temperature_var}&deg;F",
"SHOW_HUMIDITY": "Humedad: {humidity_var}%"
}
2 changes: 1 addition & 1 deletion translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"SHOW_TEMP_KELVIN": "Température: {temperature_var} K",
"SHOW_TEMP_FAHRENHEIT": "Température: {temperature_var}&deg;F",
"SHOW_HUMIDITY": "Humidité: {humidity_var}%"
}
}