You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+74-63
Original file line number
Diff line number
Diff line change
@@ -2,60 +2,70 @@
2
2
3
3
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).
4
4
5
-
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.
5
+
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.
Just enter the module's directory, pull the update:
17
+
18
+
```bash
19
+
cd~/MagicMirror/modules/MMM-CommandToNotification
20
+
git pull
14
21
```
15
22
16
23
## Basic configuration
17
24
18
25
Add the following code to your ~/MagicMirror/config/config.js:
19
26
20
-
```json5
27
+
```js
21
28
{
22
-
module:"MMM-CommandToNotification",
23
-
disabled:false,
24
-
config: {
25
-
commands: [
26
-
]
27
-
},
29
+
module:"MMM-CommandToNotification",
30
+
config: {
31
+
commands: [
32
+
]
33
+
},
28
34
},
29
35
```
30
36
31
37
### General
32
38
39
+
<!-- prettier-ignore-start -->
33
40
| Option | Description | Type | Default |
34
-
| ------- | --- | --- | --- |
41
+
| ------- | -----------| ----|------- |
35
42
| updateInterval | How often should the scripts be iterated (in seconds) | Integer | 30 |
36
43
| commands | A array containing the command definition objects | Array |[]|
37
44
| 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 |
38
45
| debug | This flag controls if debug messages should be output on the console | Boolean | false |
| script | Either a absolute path or the realtive path of a script starting at the "scripts" directory. | true | String | null |
45
54
| args | Arguments which should be passed to the script | false | String | "" |
46
55
| timeout | Should the script be killed if it does not return within a specific amount of milliseconds? | false | Integer | infinity |
47
56
| 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 |[]|
48
-
| 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 |
49
-
| 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 |
57
+
| 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 |
58
+
| 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 |
50
59
| conditions | A map containing conditions that need to match to send the notifications | false | Map | null |
60
+
<!-- prettier-ignore-end -->
51
61
52
62
### Notifications
53
63
54
64
The notifications array contains all notifications that should be send if a command is called (and the conditions matched).
55
65
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.
56
66
Lets see the following example:
57
67
58
-
```json
68
+
```js
59
69
notifications: [
60
70
["TEST1","MY_NEW_PAYLOAD"],
61
71
"TEST2",
@@ -68,57 +78,58 @@ In this example the notification "TEST1" will have "MY_NEW_PAYLOAD" as output wh
68
78
69
79
**All conditions specified need to match to send notifications!**
70
80
71
-
| Option | Description | Type | Default |
72
-
| ------- | --- | --- | --- |
81
+
<!-- prettier-ignore-start -->
82
+
| Option | Description | Type | Default |
83
+
| -------| ----------- | -----| ------- |
73
84
| 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 |
74
-
| 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 |
85
+
| 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 |
86
+
<!-- prettier-ignore-end -->
75
87
76
88
### Example
77
89
78
90
Add the following example to produce the following result:
79
91
80
-
* the scripts will be iterated every 10 seconds
81
-
* the script "scripts/randomInteger.js" gets called every iteration
82
-
* a random number between -10 and 10 is produced
83
-
* 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
84
-
* if the script produces output the output will be send as payload of the notifications TEST1 and TEST2
85
-
* the script "scripts/randomNumberJson.js" will be called every fourth iteration because a three skips are configured
86
-
* 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.
87
-
* the timeout of the script is set to 10 seconds
88
-
* 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"
89
-
* 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
90
-
91
-
```json5
92
+
- the scripts will be iterated every 10 seconds
93
+
- the script "scripts/randomInteger.js" gets called every iteration
94
+
- a random number between -10 and 10 is produced
95
+
- 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
96
+
- if the script produces output the output will be send as payload of the notifications TEST1 and TEST2
97
+
- the script "scripts/randomNumberJson.js" will be called every fourth iteration because a three skips are configured
98
+
- 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.
99
+
- the timeout of the script is set to 2000 milliseconds
100
+
- 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"
101
+
- 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
102
+
103
+
```js
92
104
{
93
-
module:"MMM-CommandToNotification",
94
-
disabled:false,
95
-
config: {
96
-
updateInterval:10,
97
-
commands: [
98
-
{
99
-
script:"./randomInteger.js",
100
-
args:"-10 10",
101
-
timeout:5,
102
-
notifications: [
103
-
"TEST1",
104
-
"TEST2",
105
-
],
106
-
},
107
-
{
108
-
script:"./randomNumberJson.js",
109
-
args:"-50 20",
110
-
skips:3,
111
-
timeout:10,
112
-
conditions: {
113
-
returnCode: [0,1,2]
114
-
}
115
-
notifications: [
116
-
"TEST3",
117
-
["TEST4", true]
118
-
],
119
-
}
120
-
]
121
-
},
105
+
module:"MMM-CommandToNotification",
106
+
config: {
107
+
updateInterval:10,
108
+
commands: [
109
+
{
110
+
script:"./randomInteger.js",
111
+
args:"-10 10",
112
+
timeout:1000,
113
+
notifications: [
114
+
"TEST1",
115
+
"TEST2",
116
+
],
117
+
},
118
+
{
119
+
script:"./randomNumberJson.js",
120
+
args:"-50 20",
121
+
skips:3,
122
+
timeout:2000,
123
+
conditions: {
124
+
returnCode: [0,1,2]
125
+
},
126
+
notifications: [
127
+
"TEST3",
128
+
["TEST4", true]
129
+
],
130
+
}
131
+
]
132
+
},
122
133
},
123
134
```
124
135
@@ -128,6 +139,6 @@ Add the following example to produce the following result:
128
139
129
140
## Developer commands
130
141
131
-
*`npm install` - Install devDependencies like ESLint.
132
-
*`npm run lint` - Run linting and formatter checks.
133
-
*`npm run lint:fix` - Fix linting and formatter issues.
142
+
-`npm install` - Install devDependencies like ESLint.
143
+
-`npm run lint` - Run linting and formatter checks.
144
+
-`npm run lint:fix` - Fix linting and formatter issues.
0 commit comments