Skip to content

Commit

Permalink
it is now possible to configure different delays for different profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-Hirschberger committed Apr 2, 2020
1 parent cdf50e6 commit 332f495
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
14 changes: 14 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "airbnb-base",
"globals": {
"Module": true,
"Log": true,
"MM": true
},
"rules": {
"comma-dangle": "off",
"object-shorthand": "off",
"func-names": "off",
"space-before-function-paren": "off"
}
}
2 changes: 2 additions & 0 deletions MMM-Screen-Powersave-Notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Module.register('MMM-Screen-Powersave-Notification', {

defaults: {
delay: 60,
profiles: {},
screenOnCommand: '/usr/bin/vcgencmd display_power 1',
screenOffCommand: '/usr/bin/vcgencmd display_power 0',
screenStatusCommand: '/usr/bin/vcgencmd display_power'
Expand All @@ -23,6 +24,7 @@ Module.register('MMM-Screen-Powersave-Notification', {
notificationReceived: function (notification, payload) {
if (
(notification === 'USER_PRESENCE') ||
(notification === 'CHANGED_PROFILE') ||
(notification === 'SCREEN_TOGGLE') ||
(notification === 'SCREEN_ON') ||
(notification === 'SCREEN_OFF') ||
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
MMM-Screen-Powersave-Notification is a module for the [MagicMirror](https://github.com/MichMich/MagicMirror) project by [Michael Teeuw](https://github.com/MichMich) and is based on https://github.com/mboskamp/MMM-PIR and https://github.com/mboskamp/MMM-PIR.

It uses notifications to check for user presence or forced on and offs of the screen. After a configurated time without user presence the display will turn off. Additionaly scripts can be run after the screen turned of or on.
If you like you can specify different delays for different profiles. The "normal" delay is used if no specific delay for a profile is configured.

## Installation
```sh
Expand All @@ -18,6 +19,9 @@ To display the module insert it in the config.js file. Here is an example:
module: 'MMM-Screen-Powersave-Notification',
config: {
delay: 60,
profiles: {
"pageOneEverone pageTwoEveryone": 600
}
}
}
```
Expand All @@ -27,6 +31,7 @@ To display the module insert it in the config.js file. Here is an example:
| Option | Description | Type | Default |
| ------- | --- | --- | --- |
| delay | time before the mirror turns off the display if no user activity is detected. (in seconds) | Integer | 60 |
| profiles | it is possible to configure different delays for different profiles (i.e. if you use profiles as pages) | Map | empty |
| screenOnCommand | the command which is used to turn the screen on | String | '/usr/bin/vcgencmd display_power 1' |
| screenOffCommand | the command which is used to turn the screen off | String | '/usr/bin/vcgencmd display_power 0' |
| screenStatusCommand | the command which is used to check if the screen is on (result needs to be 'display_power 1' if on) | String | '/usr/bin/vcgencmd display_power' |
Expand Down
25 changes: 22 additions & 3 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module.exports = NodeHelper.create({
start: function () {
this.started = false
this.forcedDown = false
this.currentProfile = ''
this.currentProfilePattern = new RegExp('.*')
},

isScreenOn: function () {
Expand Down Expand Up @@ -113,12 +115,22 @@ module.exports = NodeHelper.create({
if ( self.deactivateMonitorTimeout ){
clearTimeout(self.deactivateMonitorTimeout)
}
if ((reset === true) && (self.config.delay > 0)) {

var currentDelay = self.config.delay

for (var curConfigProfileString in self.config.profiles){
console.log("Checking delay of: "+curConfigProfileString + " current Profile: "+self.currentProfile)
if(self.currentProfilePattern.test(curConfigProfileString)){
currentDelay = self.config.profiles[curConfigProfileString]
}
}

if ((reset === true) && (currentDelay > 0)) {
self.deactivateMonitorTimeout = setTimeout(function () {
self.turnScreenOff(false)
self.clearAndSetScreenTimeout(false)
}, self.config.delay * 1000)
console.log(this.name + ': Resetted screen timeout to ' + self.config.delay + ' seconds!')
}, currentDelay * 1000)
console.log(this.name + ': Resetted screen timeout to ' + currentDelay + ' seconds!')
} else {
console.log(this.name + ': Disabled screen timeout!')
}
Expand Down Expand Up @@ -152,6 +164,13 @@ module.exports = NodeHelper.create({
self.config.delay = 0
}
self.clearAndSetScreenTimeout(true)
} else if (notification === 'CHANGED_PROFILE'){
if(typeof payload.to !== 'undefined'){
self.currentProfile = payload.to
self.currentProfilePattern = new RegExp('\\b'+payload.to+'\\b')

self.clearAndSetScreenTimeout(true);
}
} else {
console.log(this.name + ': Received Notification: ' + notification)
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "MMM-Screen-Powersave-Notification",
"version": "0.0.1",
"version": "0.0.2",
"description": "",
"main": "MMM-Screen-Powersave-Notification.js",
"dependencies": {
Expand Down

0 comments on commit 332f495

Please sign in to comment.