diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..40b878d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules/
\ No newline at end of file
diff --git a/MMM-MotionControl.js b/MMM-MotionControl.js
index 03c5735..e53a17a 100644
--- a/MMM-MotionControl.js
+++ b/MMM-MotionControl.js
@@ -5,12 +5,15 @@
* MIT Licensed.
*/
+require('moment');
+
Module.register("MMM-MotionControl",{
defaults: {
delay: 15000,
interval: 5000,
useFacialRecognitionOCV3: false,
- useMMMFaceRecoDNN: false
+ useMMMFaceRecoDNN: false,
+ ontime: []
},
timeout: null,
@@ -23,14 +26,34 @@ Module.register("MMM-MotionControl",{
self.sendNotification("GET_LOGGED_IN_USERS");
}, this.config.interval);
}
- },
+ },
+
+ inOnTime: function() {
+ var inOnTime = false;
+ var today = moment().startOf('day');
+ this.config.ontime.forEach(time => {
+ var split = time.split('-');
+ var from = today.add(split[0].substr(0, 2), 'h').add(split[0].substr(2, 2), 'm');
+ var to = today.add(split[1].substr(0, 2), 'h').add(split[1].substr(2, 2), 'm');
+
+ if (moment().isBetween(from, to)) {
+ inOnTime = true;
+ }
+ });
+
+ return inOnTime;
+ },
notificationReceived: function(notification, payload, sender) {
- if (this.config.useFacialRecognitionOCV3 === true) {
- this.handleFacialRecognitionOCV3(notification, payload, sender);
- }
- if (this.config.useMMMFaceRecoDNN === true) {
- this.handleFaceRecoDNN(notification, payload, sender);
+ if (this.inOnTime()) {
+ _self.sendNotification('CECControl', 'on');
+ } else {
+ if (this.config.useFacialRecognitionOCV3 === true) {
+ this.handleFacialRecognitionOCV3(notification, payload, sender);
+ }
+ if (this.config.useMMMFaceRecoDNN === true) {
+ this.handleFaceRecoDNN(notification, payload, sender);
+ }
}
},
diff --git a/README.md b/README.md
index 2f4116f..e506c2d 100644
--- a/README.md
+++ b/README.md
@@ -18,6 +18,7 @@ Config | Description
`interval` | Interval to check modules.
**Default Value:** `5000`
`useFacialRecognitionOCV3`| Use the module MMM-Facial-Recognition-OCV3 to control the TV
**Default Value:** `false`
`useMMMFaceRecoDNN`| Use the module MMM-Face-Reco-DNN to control the TV
**Default Value:** `false`
+`ontime`| Time where TV is always on. Array with times `['0700-1200', '1300-2000']`.
**Default Value:** `[]`
### Full configuration of the module
@@ -32,7 +33,9 @@ Config | Description
// Use the module MMM-Facial-Recognition-OCV3
useFacialRecognitionOCV3: false,
// Use the module MMM-Face-Reco-DNN
- useMMMFaceRecoDNN: false
+ useMMMFaceRecoDNN: false,
+ // Array where tv should be on
+ ontime: []
}
}
```
diff --git a/package-lock.json b/package-lock.json
new file mode 100644
index 0000000..08501ed
--- /dev/null
+++ b/package-lock.json
@@ -0,0 +1,13 @@
+{
+ "name": "mmm-motioncontrol",
+ "version": "1.0.0",
+ "lockfileVersion": 1,
+ "requires": true,
+ "dependencies": {
+ "moment": {
+ "version": "2.24.0",
+ "resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz",
+ "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg=="
+ }
+ }
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..bff7e54
--- /dev/null
+++ b/package.json
@@ -0,0 +1,28 @@
+{
+ "name": "mmm-motioncontrol",
+ "version": "1.0.0",
+ "description": "Magic Mirror Module to check motion and turn tv on or off",
+ "main": "MMM-MotionControl.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/nischi/MMM-MotionControl.git"
+ },
+ "keywords": [
+ "motion",
+ "control",
+ "magicmirror",
+ "module"
+ ],
+ "author": "Thierry Nischelwitzer",
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/nischi/MMM-MotionControl/issues"
+ },
+ "homepage": "https://github.com/nischi/MMM-MotionControl#readme",
+ "dependencies": {
+ "moment": "^2.24.0"
+ }
+}