diff --git a/.prettierignore b/.prettierignore index 18d6a9d..149769d 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,4 @@ +package.json package-lock.json *.js *.mjs \ No newline at end of file diff --git a/.prettierrc.json b/.prettierrc.json deleted file mode 100644 index 1518304..0000000 --- a/.prettierrc.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "trailingComma": "none" -} diff --git a/.stylelintrc.json b/.stylelintrc.json deleted file mode 100644 index d450c73..0000000 --- a/.stylelintrc.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": ["stylelint-prettier/recommended"], - "plugins": ["stylelint-prettier"], - "rules": { - "prettier/prettier": true - } -} diff --git a/MMM-CommandToNotification.js b/MMM-CommandToNotification.js index 00a329a..0c307a3 100644 --- a/MMM-CommandToNotification.js +++ b/MMM-CommandToNotification.js @@ -1,5 +1,5 @@ /* MagicMirror² - * Module: CommandToNotification + * Module: MMM-CommandToNotification * * By Tom Hirschberger * MIT Licensed. diff --git a/README.md b/README.md index 0d04bee..85d8b08 100644 --- a/README.md +++ b/README.md @@ -2,52 +2,62 @@ MagicMirror² module which periodically calls configured scripts and sends the output as value of configurable notifications. The values can be displayed in modules like [MMM-ValuesByNotification](https://github.com/Tom-Hirschberger/MMM-ValuesByNotification). -Example scripts to read the temperature values of DHT11, DHT22, DS18B20, HTU21, SHT31d, SHTC3 or BME280 connected to the raspbarry or Miflora sensors in reach of bluetooth are included in the scripts directory. There is a documentation in the [scripts directory](./scripts/README.md), too. +Example scripts to read the temperature values of DHT11, DHT22, DS18B20, HTU21, SHT31d, SHTC3 or BME280 connected to the raspbarry or Miflora sensors in reach of bluetooth are included in the scripts directory. There is a documentation in the [scripts directory](./scripts/README.md), too. -## Basic installation +## Installation ```bash cd ~/MagicMirror/modules git clone https://github.com/Tom-Hirschberger/MMM-CommandToNotification -cd MMM-CommandToNotification -npm install +``` + +## Update + +Just enter the module's directory, pull the update: + +```bash +cd ~/MagicMirror/modules/MMM-CommandToNotification +git pull ``` ## Basic configuration Add the following code to your ~/MagicMirror/config/config.js: -```json5 +```js { - module: "MMM-CommandToNotification", - disabled: false, - config: { - commands: [ - ] - }, + module: "MMM-CommandToNotification", + config: { + commands: [ + ] + }, }, ``` ### General + | Option | Description | Type | Default | -| ------- | --- | --- | --- | +| ------- | ----------- | ---- | ------- | | updateInterval | How often should the scripts be iterated (in seconds) | Integer | 30 | | commands | A array containing the command definition objects | Array | [] | | sync | Should the commands called one by one (true) or should all be started as fast as possible (false). Can be overriden for each command in the command configuration | Boolean | true | | debug | This flag controls if debug messages should be output on the console | Boolean | false | + ### Commands + | Option | Description | Mandatory | Type | Default | -| ------- | --- | --- | --- | --- | +| ------- | ----------- | --------- | ---- | ------- | | script | Either a absolute path or the realtive path of a script starting at the "scripts" directory. | true | String | null | | args | Arguments which should be passed to the script | false | String | "" | | timeout | Should the script be killed if it does not return within a specific amount of milliseconds? | false | Integer | infinity | | notifications | A array containing names of the notifications to send if script returns output. If not present the script gets called but no notification will be send. If you want to override the payload instead of using the output please look at the notification section. | false | Array | [] | -| sync | Should the command by run synchronous (next command will be called after this one, true) or asynchronous (directly proceed with the next one and process output when the command finishes, false) | Boolean | true | -| delayNext | Wait some amount of time (milliseconds) before the next command will be processed after this one has called. Make sure to set to updateInterval of the module to a value that is enough time to call and process all commands with all delays summed up! | Integer | 0 | +| sync | Should the command by run synchronous (next command will be called after this one, true) or asynchronous (directly proceed with the next one and process output when the command finishes, false) | Boolean | false | true | +| delayNext | Wait some amount of time (milliseconds) before the next command will be processed after this one has called. Make sure to set to updateInterval of the module to a value that is enough time to call and process all commands with all delays summed up! | false | Integer | 0 | | conditions | A map containing conditions that need to match to send the notifications | false | Map | null | + ### Notifications @@ -55,7 +65,7 @@ The notifications array contains all notifications that should be send if a comm There may be situations where you want send a notification with a specific payload instead of the output of the script. You can do so if you specify a array instead of the string identifiying the notification. Lets see the following example: -```json +```js notifications: [ ["TEST1","MY_NEW_PAYLOAD"], "TEST2", @@ -68,57 +78,58 @@ In this example the notification "TEST1" will have "MY_NEW_PAYLOAD" as output wh **All conditions specified need to match to send notifications!** -| Option | Description | Type | Default | -| ------- | --- | --- | --- | + +| Option | Description | Type | Default | +| -------| ----------- | -----| ------- | | returnCode | Specify either a single return code or a array of return codes that need to match. If a array is specified one of the values need to match (or condition). | Integer or Array of Integer | null | -| outputContains | Specify either a single string or a array of possible strings which of one need to be present in the output (or condition). | null | +| outputContains | Specify either a single string or a array of possible strings which of one need to be present in the output (or condition). | Integer or Array of Integer | null | + ### Example Add the following example to produce the following result: -* the scripts will be iterated every 10 seconds -* the script "scripts/randomInteger.js" gets called every iteration - * a random number between -10 and 10 is produced - * the timeout of the script is 5 seconds. If the script does not produce any output within 5 seconds the call will be aborted and no notifications will be send - * if the script produces output the output will be send as payload of the notifications TEST1 and TEST2 -* the script "scripts/randomNumberJson.js" will be called every fourth iteration because a three skips are configured - * the script calculates a random number between -50 and 20 and produces a json object containing two values ("integer" and "float"). The float value is the random number the integer value the random number rounded as integer. - * the timeout of the script is set to 10 seconds - * the result of the script (JSON object as string) will be send as payload of notification TEST3 while TEST4 will be send with payload "true" - * As the condition `returnCode` is set to `[0,1,2]` the notifications `TEST3` and `TEST4` only will be send if the script `./randomNumberJson.js` only will be send if the script exits with code 0, 1 or 2 - -```json5 +- the scripts will be iterated every 10 seconds +- the script "scripts/randomInteger.js" gets called every iteration + - a random number between -10 and 10 is produced + - the timeout of the script is 1000 milliseconds. If the script does not produce any output within 1000 milliseconds the call will be aborted and no notifications will be send + - if the script produces output the output will be send as payload of the notifications TEST1 and TEST2 +- the script "scripts/randomNumberJson.js" will be called every fourth iteration because a three skips are configured + - the script calculates a random number between -50 and 20 and produces a json object containing two values ("integer" and "float"). The float value is the random number the integer value the random number rounded as integer. + - the timeout of the script is set to 2000 milliseconds + - the result of the script (JSON object as string) will be send as payload of notification TEST3 while TEST4 will be send with payload "true" + - As the condition `returnCode` is set to `[0,1,2]` the notifications `TEST3` and `TEST4` only will be send if the script `./randomNumberJson.js` only will be send if the script exits with code 0, 1 or 2 + +```js { - module: "MMM-CommandToNotification", - disabled: false, - config: { - updateInterval: 10, - commands: [ - { - script: "./randomInteger.js", - args: "-10 10", - timeout: 5, - notifications: [ - "TEST1", - "TEST2", - ], - }, - { - script: "./randomNumberJson.js", - args: "-50 20", - skips: 3, - timeout: 10, - conditions: { - returnCode: [0,1,2] - } - notifications: [ - "TEST3", - ["TEST4", true] - ], - } - ] - }, + module: "MMM-CommandToNotification", + config: { + updateInterval: 10, + commands: [ + { + script: "./randomInteger.js", + args: "-10 10", + timeout: 1000, + notifications: [ + "TEST1", + "TEST2", + ], + }, + { + script: "./randomNumberJson.js", + args: "-50 20", + skips: 3, + timeout: 2000, + conditions: { + returnCode: [0,1,2] + }, + notifications: [ + "TEST3", + ["TEST4", true] + ], + } + ] + }, }, ``` @@ -128,6 +139,6 @@ Add the following example to produce the following result: ## Developer commands -* `npm install` - Install devDependencies like ESLint. -* `npm run lint` - Run linting and formatter checks. -* `npm run lint:fix` - Fix linting and formatter issues. \ No newline at end of file +- `npm install` - Install devDependencies like ESLint. +- `npm run lint` - Run linting and formatter checks. +- `npm run lint:fix` - Fix linting and formatter issues. diff --git a/eslint.config.mjs b/eslint.config.mjs index 5de6b9e..d9f991c 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -4,12 +4,7 @@ import globals from "globals" const config = [ { - files: ["**/*.js", "**/*.mjs"], - }, - { - ignores: ["**/doc/configs/webcam-config.js"], - }, - { + files: ["**/*.js"], languageOptions: { globals: { ...globals.browser, @@ -17,6 +12,7 @@ const config = [ Log: "readonly", Module: "readonly", }, + sourceType: "commonjs" }, plugins: { ...eslintPluginStylistic.configs["recommended-flat"].plugins, @@ -24,24 +20,26 @@ const config = [ rules: { ...eslintPluginJs.configs.all.rules, ...eslintPluginStylistic.configs["recommended-flat"].rules, - "@stylistic/brace-style": ["error", "1tbs", { allowSingleLine: true }], + "@stylistic/brace-style": ["error", "1tbs", {allowSingleLine: true}], "@stylistic/comma-dangle": ["error", "only-multiline"], "@stylistic/indent": ["error", "tab"], - "@stylistic/max-statements-per-line": ["error", { max: 2 }], + "@stylistic/max-statements-per-line": ["error", {max: 2}], "@stylistic/no-tabs": "off", "@stylistic/quotes": ["error", "double"], "capitalized-comments": "off", - "complexity": "off", + complexity: "off", "consistent-this": "off", - "eqeqeq": "warn", + eqeqeq: "warn", "init-declarations": "off", "max-depth": "off", "max-lines": "off", "max-lines-per-function": "off", "max-params": "off", - "max-statements": ["error", { max: 80 }], + "max-statements": ["error", {max: 80}], "no-else-return": "off", "no-eq-null": "warn", + "no-await-in-loop": "warn", + "no-compare-neg-zero": "warn", "no-inline-comments": "off", "no-magic-numbers": "off", "no-negated-condition": "off", @@ -51,7 +49,34 @@ const config = [ "one-var": "off", "prefer-destructuring": "off", "sort-keys": "off", + strict: "off", + } + }, + { + files: ["**/*.mjs"], + languageOptions: { + globals: { + ...globals.node + }, + sourceType: "module" + }, + plugins: { + ...eslintPluginStylistic.configs["all-flat"].plugins }, + rules: { + ...eslintPluginStylistic.configs["all-flat"].rules, + "@stylistic/array-element-newline": "off", + "@stylistic/comma-dangle": ["error", "only-multiline"], + "@stylistic/indent": ["error", "tab"], + "@stylistic/object-property-newline": "off", + "@stylistic/padded-blocks": ["error", "never"], + "@stylistic/quote-props": ["error", "as-needed"], + "@stylistic/semi": ["error", "never"], + "func-style": "off", + "max-lines-per-function": ["error", 100], + "no-magic-numbers": "off", + "one-var": "off" + } } ] diff --git a/node_helper.js b/node_helper.js index 33dfec3..7e59844 100644 --- a/node_helper.js +++ b/node_helper.js @@ -7,10 +7,10 @@ const Log = require("logger") const NodeHelper = require("node_helper") -const spawnSync = require("child_process").spawnSync -const spawn = require("child_process").spawn -const fs = require("fs") -const path = require("path") +const spawnSync = require("node:child_process").spawnSync +const spawn = require("node:child_process").spawn +const fs = require("node:fs") +const path = require("node:path") const scriptsDir = path.join(__dirname, "/scripts") module.exports = NodeHelper.create({ @@ -24,8 +24,7 @@ module.exports = NodeHelper.create({ }, sleep(milliseconds) { - // eslint-disable-next-line no-promise-executor-return - return new Promise(resolve => setTimeout(resolve, milliseconds)) + return new Promise((resolve) => { setTimeout(resolve, milliseconds) }) }, // https://stackoverflow.com/questions/14332721/node-js-spawn-child-process-and-get-terminal-output-live @@ -237,7 +236,6 @@ module.exports = NodeHelper.create({ if (self.config.debug) { Log.log(`${self.name}: Delaying next: ${curCmdConfig.delayNext}`) } - // eslint-disable-next-line no-await-in-loop await self.sleep(curCmdConfig.delayNext) } } else { diff --git a/package.json b/package.json index 4f16422..2fd8d63 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,14 @@ { - "name": "MMM-CommandToNotification", - "version": "0.0.8", + "name": "mmm-commandtonotification", + "version": "0.0.9", "description": "A MagicMirror² module which calls system-commands or scripts periodically and sends the output as notifications.", - "main": "MMM-CommandToNotification", - "dependencies": {}, + "main": "MMM-CommandToNotification.js", "repository": { "type": "git", "url": "git@github.com:Tom-Hirschberger/MMM-CommandToNotification.git" }, "keywords": [ "MagicMirror", - "MM", "scripts", "commands", "notifications", @@ -27,14 +25,15 @@ }, "homepage": "https://github.com/Tom-Hirschberger/MMM-CommandToNotification/#readme", "devDependencies": { - "@eslint/js": "^9.10.0", - "@stylistic/eslint-plugin": "^2.8.0", - "eslint": "^9.10.0", - "globals": "^15.9.0" + "@eslint/js": "^9.13.0", + "@stylistic/eslint-plugin": "^2.9.0", + "eslint": "^9.13.0", + "globals": "^15.11.0", + "prettier": "^3.3.3" }, "scripts": { - "lint": "eslint .", - "lint:fix": "eslint . --fix", + "lint": "eslint . && prettier . --check", + "lint:fix": "eslint . --fix && prettier . --write", "test": "npm run lint" } } diff --git a/prettier.config.mjs b/prettier.config.mjs new file mode 100644 index 0000000..0d637d4 --- /dev/null +++ b/prettier.config.mjs @@ -0,0 +1,5 @@ +const config = { + trailingComma: "none" +} + +export default config diff --git a/scripts/README.md b/scripts/README.md index e7d0a5c..9a88c59 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -17,7 +17,7 @@ The output contains a error flag which will be set to "true" if the sensor could ### Requirements -* Make sure to enable the I2C bus of the system by running this commands in the shell and reboot the system: +- Make sure to enable the I2C bus of the system by running this commands in the shell and reboot the system: ```bash if [ `grep -c "i2c-dev" /etc/modules` -lt 1 ]; then echo "i2c-dev" | sudo tee -a /etc/modules; echo "Added"; else echo "Skipped"; fi @@ -27,27 +27,27 @@ if [ `grep -c "i2c-dev" /etc/modules` -lt 1 ]; then echo "i2c-dev" | sudo tee -a sudo reboot ``` -* Install the Python Virtual Environment System Package: +- Install the Python Virtual Environment System Package: ```bash sudo apt -y update && sudo apt -y install python3-venv ``` -* Use the wrapper script to create the virtual environment: +- Use the wrapper script to create the virtual environment: ```bash cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts ./venvWrapper.py --verbose --venv-name py-venv --create ``` -* Use the wrapper script to install the dependencies in the virtual environment: +- Use the wrapper script to install the dependencies in the virtual environment: ```bash cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts ./venvWrapper.py --venv-name py-venv --install-libs smbus ``` -* Use the wrapper script to run the python script: +- Use the wrapper script to run the python script: ```bash cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts @@ -56,36 +56,35 @@ cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts ### Options -| Option | Description | Type | Default | -| ------- | --- | --- | --- | -| First argument | The I2C address of the sensor | String | 0x76 | +| Option | Description | Type | Default | +| -------------- | ----------------------------- | ------ | ------- | +| First argument | The I2C address of the sensor | String | 0x76 | ### Example output Real: ```json -{"temperature_c": 22.0, "humidity": 62.1, "pressure": 512.0, "temperature_f": 71.6, "error": false} +{ "temperature_c": 22.0, "humidity": 62.1, "pressure": 512.0, "temperature_f": 71.6, "error": false } ``` Pritty Print: ```json { - "temperature_c": 22.0, - "humidity": 62.1, - "pressure": 512.0, - "temperature_f": 71.6, - "error": false + "temperature_c": 22.0, + "humidity": 62.1, + "pressure": 512.0, + "temperature_f": 71.6, + "error": false } ``` ### Example config -```json5 +```js { module: "MMM-CommandToNotification", - disabled: false, config: { updateInterval: 30, commands: [ @@ -104,10 +103,10 @@ Pritty Print: This config results in: -* the BME280 sensor has the address 0x76 -* if the script does not return a value within 1000ms it will be killed -* the script will be called by the wrapper every 30 seconds -* the values will be published with the notification `TEMPERATURE` +- the BME280 sensor has the address 0x76 +- if the script does not return a value within 1000ms it will be killed +- the script will be called by the wrapper every 30 seconds +- the values will be published with the notification `TEMPERATURE` ## temperature/dht11 @@ -117,27 +116,27 @@ The output contains a error flag which will be set to "true" if the sensor could ### Requirements -* Install the Python Virtual Environment and `libgpiod2` System Package: +- Install the Python Virtual Environment and `libgpiod2` System Package: ```bash sudo apt -y update && sudo apt -y install python3-venv libgpiod2 ``` -* Use the wrapper script to create the virtual environment: +- Use the wrapper script to create the virtual environment: ```bash cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts ./venvWrapper.py --verbose --venv-name py-venv --create ``` -* Use the wrapper script to install the dependencies in the virtual environment: +- Use the wrapper script to install the dependencies in the virtual environment: ```bash cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts ./venvWrapper.py --venv-name py-venv --install-libs adafruit-circuitpython-dht ``` -* Use the wrapper script to run the python script: +- Use the wrapper script to run the python script: ```bash cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts @@ -146,35 +145,34 @@ cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts ### Options -| Option | Description | Type | Default | -| ------- | --- | --- | --- | -| First argument | The number of the GPIO the sensor is connected to | Integer | 4 | +| Option | Description | Type | Default | +| -------------- | ------------------------------------------------- | ------- | ------- | +| First argument | The number of the GPIO the sensor is connected to | Integer | 4 | ### Example output Real: ```json -{"temperature_c": 22.0, "humidity": 62.1, "temperature_f": 71.6, "error": false} +{ "temperature_c": 22.0, "humidity": 62.1, "temperature_f": 71.6, "error": false } ``` Pritty Print: ```json { - "temperature_c": 22.0, - "humidity": 62.1, - "temperature_f": 71.6, - "error": false + "temperature_c": 22.0, + "humidity": 62.1, + "temperature_f": 71.6, + "error": false } ``` ### Example config -```json5 +```js { module: "MMM-CommandToNotification", - disabled: false, config: { updateInterval: 30, commands: [ @@ -193,10 +191,10 @@ Pritty Print: This config results in: -* the DHT11 sensor is connected to GPIO 4 -* if the script does not return a value within 2000ms it will be killed -* the script will be called by the wrapper every 30 seconds -* the values will be published with the notification `TEMPERATURE` +- the DHT11 sensor is connected to GPIO 4 +- if the script does not return a value within 2000ms it will be killed +- the script will be called by the wrapper every 30 seconds +- the values will be published with the notification `TEMPERATURE` ## temperature/dht22 @@ -206,27 +204,27 @@ The output contains a error flag which will be set to "true" if the sensor could ### Requirements -* Install the Python Virtual Environment and `libgpiod2` System Package: +- Install the Python Virtual Environment and `libgpiod2` System Package: ```bash sudo apt -y update && sudo apt -y install python3-venv libgpiod2 ``` -* Use the wrapper script to create the virtual environment: +- Use the wrapper script to create the virtual environment: ```bash cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts ./venvWrapper.py --verbose --venv-name py-venv --create ``` -* Use the wrapper script to install the dependencies in the virtual environment: +- Use the wrapper script to install the dependencies in the virtual environment: ```bash cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts ./venvWrapper.py --venv-name py-venv --install-libs adafruit-circuitpython-dht ``` -* Use the wrapper script to run the python script: +- Use the wrapper script to run the python script: ```bash cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts @@ -235,35 +233,34 @@ cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts ### Options -| Option | Description | Type | Default | -| ------- | --- | --- | --- | -| First argument | The number of the GPIO the sensor is connected to | Integer | 4 | +| Option | Description | Type | Default | +| -------------- | ------------------------------------------------- | ------- | ------- | +| First argument | The number of the GPIO the sensor is connected to | Integer | 4 | ### Example output Real: ```json -{"temperature_c": 22.0, "humidity": 62.1, "temperature_f": 71.6, "error": false} +{ "temperature_c": 22.0, "humidity": 62.1, "temperature_f": 71.6, "error": false } ``` Pritty Print: ```json { - "temperature_c": 22.0, - "humidity": 62.1, - "temperature_f": 71.6, - "error": false + "temperature_c": 22.0, + "humidity": 62.1, + "temperature_f": 71.6, + "error": false } ``` ### Example config -```json5 +```js { module: "MMM-CommandToNotification", - disabled: false, config: { updateInterval: 30, commands: [ @@ -282,10 +279,10 @@ Pritty Print: This config results in: -* the DHT22 sensor is connected to GPIO 4 -* if the script does not return a value within 2000ms it will be killed -* the script will be called by the wrapper every 30 seconds -* the values will be published with the notification `TEMPERATURE` +- the DHT22 sensor is connected to GPIO 4 +- if the script does not return a value within 2000ms it will be killed +- the script will be called by the wrapper every 30 seconds +- the values will be published with the notification `TEMPERATURE` ## temperature/htu21 @@ -295,7 +292,7 @@ The output contains a error flag which will be set to "true" if the sensor could ### Requirements -* Make sure to enable the I2C bus of the system by running this commands in the shell and reboot the system: +- Make sure to enable the I2C bus of the system by running this commands in the shell and reboot the system: ```bash if [ `grep -c "i2c-dev" /etc/modules` -lt 1 ]; then echo "i2c-dev" | sudo tee -a /etc/modules; echo "Added"; else echo "Skipped"; fi @@ -305,27 +302,27 @@ if [ `grep -c "i2c-dev" /etc/modules` -lt 1 ]; then echo "i2c-dev" | sudo tee -a sudo reboot ``` -* Install the Python Virtual Environment System Package: +- Install the Python Virtual Environment System Package: ```bash sudo apt -y update && sudo apt -y install python3-venv ``` -* Use the wrapper script to create the virtual environment: +- Use the wrapper script to create the virtual environment: ```bash cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts ./venvWrapper.py --verbose --venv-name py-venv --create ``` -* Use the wrapper script to install the dependencies in the virtual environment: +- Use the wrapper script to install the dependencies in the virtual environment: ```bash cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts ./venvWrapper.py --venv-name py-venv --install-libs adafruit-circuitpython-htu21d ``` -* Use the wrapper script to run the python script: +- Use the wrapper script to run the python script: ```bash cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts @@ -337,26 +334,25 @@ cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts Real: ```json -{"temperature_c": 22.0, "humidity": 62.1, "temperature_f": 71.6, "error": false} +{ "temperature_c": 22.0, "humidity": 62.1, "temperature_f": 71.6, "error": false } ``` Pritty Print: ```json { - "temperature_c": 22.0, - "humidity": 62.1, - "temperature_f": 71.6, - "error": false + "temperature_c": 22.0, + "humidity": 62.1, + "temperature_f": 71.6, + "error": false } ``` ### Example config -```json5 +```js { module: "MMM-CommandToNotification", - disabled: false, config: { updateInterval: 30, commands: [ @@ -375,9 +371,9 @@ Pritty Print: This config results in: -* if the script does not return a value within 2000ms it will be killed -* the script will be called by the wrapper every 30 seconds -* the values will be published with the notification `TEMPERATURE` +- if the script does not return a value within 2000ms it will be killed +- the script will be called by the wrapper every 30 seconds +- the values will be published with the notification `TEMPERATURE` ## temperature/sht31d @@ -387,7 +383,7 @@ The output contains a error flag which will be set to "true" if the sensor could ### Requirements -* Make sure to enable the I2C bus of the system by running this commands in the shell and reboot the system: +- Make sure to enable the I2C bus of the system by running this commands in the shell and reboot the system: ```bash if [ `grep -c "i2c-dev" /etc/modules` -lt 1 ]; then echo "i2c-dev" | sudo tee -a /etc/modules; echo "Added"; else echo "Skipped"; fi @@ -397,27 +393,27 @@ if [ `grep -c "i2c-dev" /etc/modules` -lt 1 ]; then echo "i2c-dev" | sudo tee -a sudo reboot ``` -* Install the Python Virtual Environment System Package: +- Install the Python Virtual Environment System Package: ```bash sudo apt -y update && sudo apt -y install python3-venv ``` -* Use the wrapper script to create the virtual environment: +- Use the wrapper script to create the virtual environment: ```bash cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts ./venvWrapper.py --verbose --venv-name py-venv --create ``` -* Use the wrapper script to install the dependencies in the virtual environment: +- Use the wrapper script to install the dependencies in the virtual environment: ```bash cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts ./venvWrapper.py --venv-name py-venv --install-libs adafruit-circuitpython-sht31d ``` -* Use the wrapper script to run the python script: +- Use the wrapper script to run the python script: ```bash cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts @@ -429,26 +425,25 @@ cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts Real: ```json -{"temperature_c": 22.0, "humidity": 62.1, "temperature_f": 71.6, "error": false} +{ "temperature_c": 22.0, "humidity": 62.1, "temperature_f": 71.6, "error": false } ``` Pritty Print: ```json { - "temperature_c": 22.0, - "humidity": 62.1, - "temperature_f": 71.6, - "error": false + "temperature_c": 22.0, + "humidity": 62.1, + "temperature_f": 71.6, + "error": false } ``` ### Example config -```json5 +```js { module: "MMM-CommandToNotification", - disabled: false, config: { updateInterval: 30, commands: [ @@ -467,9 +462,9 @@ Pritty Print: This config results in: -* if the script does not return a value within 2000ms it will be killed -* the script will be called by the wrapper every 30 seconds -* the values will be published with the notification `TEMPERATURE` +- if the script does not return a value within 2000ms it will be killed +- the script will be called by the wrapper every 30 seconds +- the values will be published with the notification `TEMPERATURE` ## temperature/shtc3 @@ -479,7 +474,7 @@ The output contains a error flag which will be set to "true" if the sensor could ### Requirements -* Make sure to enable the I2C bus of the system by running this commands in the shell and reboot the system: +- Make sure to enable the I2C bus of the system by running this commands in the shell and reboot the system: ```bash if [ `grep -c "i2c-dev" /etc/modules` -lt 1 ]; then echo "i2c-dev" | sudo tee -a /etc/modules; echo "Added"; else echo "Skipped"; fi @@ -489,27 +484,27 @@ if [ `grep -c "i2c-dev" /etc/modules` -lt 1 ]; then echo "i2c-dev" | sudo tee -a sudo reboot ``` -* Install the Python Virtual Environment System Package: +- Install the Python Virtual Environment System Package: ```bash sudo apt -y update && sudo apt -y install python3-venv ``` -* Use the wrapper script to create the virtual environment: +- Use the wrapper script to create the virtual environment: ```bash cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts ./venvWrapper.py --verbose --venv-name py-venv --create ``` -* Use the wrapper script to install the dependencies in the virtual environment: +- Use the wrapper script to install the dependencies in the virtual environment: ```bash cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts ./venvWrapper.py --venv-name py-venv --install-libs smbus2 ``` -* Use the wrapper script to run the python script: +- Use the wrapper script to run the python script: ```bash cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts @@ -521,26 +516,25 @@ cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts Real: ```json -{"temperature_c": 22.0, "humidity": 62.1, "temperature_f": 71.6, "error": false} +{ "temperature_c": 22.0, "humidity": 62.1, "temperature_f": 71.6, "error": false } ``` Pritty Print: ```json { - "temperature_c": 22.0, - "humidity": 62.1, - "temperature_f": 71.6, - "error": false + "temperature_c": 22.0, + "humidity": 62.1, + "temperature_f": 71.6, + "error": false } ``` ### Example config -```json5 +```js { module: "MMM-CommandToNotification", - disabled: false, config: { updateInterval: 30, commands: [ @@ -559,9 +553,9 @@ Pritty Print: This config results in: -* if the script does not return a value within 2000ms it will be killed -* the script will be called by the wrapper every 30 seconds -* the values will be published with the notification `TEMPERATURE` +- if the script does not return a value within 2000ms it will be killed +- the script will be called by the wrapper every 30 seconds +- the values will be published with the notification `TEMPERATURE` ## temperature/ds18b20 @@ -571,39 +565,39 @@ The output contains a error flag which will be set to "true" if the sensor could ### Requirements -* Connect VCC pin to 3.3V -* #Connect Ground pin to Ground -* Add an 4.7kOhm resister between data wire and VCC -* Add the the data wire to GPIO4 (which is the 1-wire bus pin) (more info at: https://www.circuitbasics.com/raspberry-pi-ds18b20-temperature-sensor-tutorial/) -* Add the following lines to `/etc/modules` - * `w1_gpio` - * `w1_therm` -* Add the following line to `/etc/boot/config.txt` - * `dtoverlay=w1-gpio` -* Find the id of your sensor (starting with "28-") in `/sys/bus/w1/devices`: `ls /sys/bus/w1/devices/ | grep 28-` -* Check if you get values: `cat /sys/bus/w1/devices/YOUR_SENSOR_ID/w1_slave` +- Connect VCC pin to 3.3V +- #Connect Ground pin to Ground +- Add an 4.7kOhm resister between data wire and VCC +- Add the the data wire to GPIO4 (which is the 1-wire bus pin) (more info at: https://www.circuitbasics.com/raspberry-pi-ds18b20-temperature-sensor-tutorial/) +- Add the following lines to `/etc/modules` + - `w1_gpio` + - `w1_therm` +- Add the following line to `/etc/boot/config.txt` + - `dtoverlay=w1-gpio` +- Find the id of your sensor (starting with "28-") in `/sys/bus/w1/devices`: `ls /sys/bus/w1/devices/ | grep 28-` +- Check if you get values: `cat /sys/bus/w1/devices/YOUR_SENSOR_ID/w1_slave` -* Install the Python Virtual Environment System Package: +- Install the Python Virtual Environment System Package: ```bash sudo apt -y update && sudo apt -y install python3-venv ``` -* Use the wrapper script to create the virtual environment: +- Use the wrapper script to create the virtual environment: ```bash cd ~/MagicMirror/modules/MMM-Temperature/scripts ./venvWrapper.py --verbose --venv-name py-venv --create ``` -* Use the wrapper script to install the dependencies in the virtual environment: +- Use the wrapper script to install the dependencies in the virtual environment: ```bash cd ~/MagicMirror/modules/MMM-Temperature/scripts ./venvWrapper.py --venv-name py-venv --install-libs json ``` -* Use the wrapper script to run the python script: +- Use the wrapper script to run the python script: ```bash cd ~/MagicMirror/modules/MMM-Temperature/scripts @@ -612,34 +606,33 @@ cd ~/MagicMirror/modules/MMM-Temperature/scripts ### Options -| Option | Description | Type | Default | -| ------- | --- | --- | --- | -| First argument | The id of the sensor is | String | null | +| Option | Description | Type | Default | +| -------------- | ----------------------- | ------ | ------- | +| First argument | The id of the sensor is | String | null | ### Example output Real: ```json -{"temperature_c": 22.0, "temperature_f": 71.6, "error": false} +{ "temperature_c": 22.0, "temperature_f": 71.6, "error": false } ``` Pritty Print: ```json { - "temperature_c": 22.0, - "temperature_f": 71.6, - "error": false + "temperature_c": 22.0, + "temperature_f": 71.6, + "error": false } ``` ### Example config -```json5 +```js { module: "MMM-CommandToNotification", - disabled: false, config: { updateInterval: 45, commands: [ @@ -658,10 +651,10 @@ Pritty Print: This config results in: -* the DS18b20 has the id "123456" -* if the script does not return a value within 3000ms it will be killed -* the script will be called every 45 seconds by the wrapper -* the values will be published with the notification `TEMPERATURE` +- the DS18b20 has the id "123456" +- if the script does not return a value within 3000ms it will be killed +- the script will be called every 45 seconds by the wrapper +- the values will be published with the notification `TEMPERATURE` ## flowercare-mm.json @@ -670,20 +663,20 @@ Please see "flowercare/flowercare-mm.json" file for configuration options. ### Requirements -* Install the Python Virtual Environment System Package: +- Install the Python Virtual Environment System Package: ```bash sudo apt -y update && sudo apt -y install python3-venv ``` -* Use the wrapper script to create the virtual environment: +- Use the wrapper script to create the virtual environment: ```bash cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts ./venvWrapper.py --verbose --venv-name py-venv --create ``` -* Use the wrapper script to install the dependencies in the virtual environment: +- Use the wrapper script to install the dependencies in the virtual environment: ```bash cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts @@ -692,8 +685,8 @@ cd ~/MagicMirror/modules/MMM-CommandToNotification/scripts ## Options -| Option | Description | Type | Default | -| ------- | --- | --- | --- | +| Option | Description | Type | Default | +| -------------- | ----------------------------------- | ------ | ----------------------------------------------------------------------------------------- | | First argument | The path of the configuration file. | String | /home/pi/MagicMirror/modules/MMM-CommandToNotification/scripts/flowercare/flowercare.json | ### Example output @@ -706,21 +699,21 @@ You do not need to read all possible values of a sensor. Reading only the values Real: ```json -{"Flower1": {"temperature": 21.6, "moisture": 62, "light": 0, "conducitivity": 1044, "battery": 50}, "Flower2": "error"} +{ "Flower1": { "temperature": 21.6, "moisture": 62, "light": 0, "conducitivity": 1044, "battery": 50 }, "Flower2": "error" } ``` Pritty Print: ```json { - "Flower1": { - "battery": 50, - "conducitivity": 1044, - "light": 0, - "moisture": 62, - "temperature": 21.6 - }, - "Flower2": "error" + "Flower1": { + "battery": 50, + "conducitivity": 1044, + "light": 0, + "moisture": 62, + "temperature": 21.6 + }, + "Flower2": "error" } ``` @@ -732,11 +725,11 @@ To save the timestamp of the last run a temporary file will be created. The path ## Options -| Option | Description | Type | Default | -| ------- | --- | --- | --- | -| -f | The path of the file to watch | String | "/home/pi/TeleFrame/images/images.json" | -| -t | The path of the temporary file to use to save the timestamp | String | ""/tmp/fileWatch.date | -| -m | The minium time that needs to be past before the change will be accepted | Integer | 1 | +| Option | Description | Type | Default | +| ------ | ------------------------------------------------------------------------ | ------- | --------------------------------------- | +| -f | The path of the file to watch | String | "/home/pi/TeleFrame/images/images.json" | +| -t | The path of the temporary file to use to save the timestamp | String | ""/tmp/fileWatch.date | +| -m | The minium time that needs to be past before the change will be accepted | Integer | 1 | ## Example output @@ -775,10 +768,10 @@ Generates a random integer within a configurable range. ### Options -| Option | Description | Type | Default | -| ------- | --- | --- | --- | -| First argument | The minimal value | Integer | -10 | -| Second argument | The maximum value | Integer | 10 | +| Option | Description | Type | Default | +| --------------- | ----------------- | ------- | ------- | +| First argument | The minimal value | Integer | -10 | +| Second argument | The maximum value | Integer | 10 | ### Example output @@ -792,24 +785,24 @@ Generates a random number within a configurable range and return it as float and ### Options -| Option | Description | Type | Default | -| ------- | --- | --- | --- | -| First argument | The minimal value | Integer | -10 | -| Second argument | The maximum value | Integer | 10 | +| Option | Description | Type | Default | +| --------------- | ----------------- | ------- | ------- | +| First argument | The minimal value | Integer | -10 | +| Second argument | The maximum value | Integer | 10 | ### Example output Real: ```json -{"integer":4,"float":4.414833739448628} +{ "integer": 4, "float": 4.414833739448628 } ``` Pritty Print: ```json { - "integer": 4, - "float": 4.414833739448628 + "integer": 4, + "float": 4.414833739448628 } ``` diff --git a/scripts/flowercare/flowercare-mm.json b/scripts/flowercare/flowercare-mm.json index 26654b1..2ab5106 100644 --- a/scripts/flowercare/flowercare-mm.json +++ b/scripts/flowercare/flowercare-mm.json @@ -1,13 +1,13 @@ { - "sensors": [ - { - "name": "Calla", - "mac": "AA:BB:CC:DD:EE:FF", - "readTemperature": true, - "readMoisture": true, - "readLight": false, - "readConductivity": false, - "readBattery": true - } - ] -} \ No newline at end of file + "sensors": [ + { + "name": "Calla", + "mac": "AA:BB:CC:DD:EE:FF", + "readTemperature": true, + "readMoisture": true, + "readLight": false, + "readConductivity": false, + "readBattery": true + } + ] +}