Skip to content
This repository was archived by the owner on Mar 6, 2022. It is now read-only.
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
4 changes: 3 additions & 1 deletion MMM-PIR-Sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ Module.register('MMM-PIR-Sensor',{
// Override socket notification handler.
socketNotificationReceived: function (notification, payload) {
if (notification === 'USER_PRESENCE') {
this.sendNotification(notification, payload)
this.sendNotification(notification, payload);
if (payload === false && this.config.powerSavingNotification === true){
this.sendNotification("SHOW_ALERT",{type:"notification", message:this.config.powerSavingMessage});
}
} else if (notification === 'SHOW_ALERT') {
this.sendNotification(notification, payload)
} else if (notification === 'POWER_SAVE') {
this.sendNotification(notification, payload)
}
},

Expand Down
17 changes: 12 additions & 5 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,35 @@ module.exports = NodeHelper.create({
// If relays are being used in place of HDMI
if (this.config.relayPin !== false) {
this.relay.writeSync(this.config.relayState);
this.sendSocketNotification('POWER_SAVE', false);
}
else if (this.config.relayPin === false) {
var self=this;
// Check if hdmi output is already on
exec("/usr/bin/vcgencmd display_power").stdout.on('data', function(data) {
if (data.indexOf("display_power=0") === 0)
if (data.indexOf("display_power=0") === 0) {
exec("/usr/bin/vcgencmd display_power 1", null);
self.sendSocketNotification('POWER_SAVE', false);
}
});
}
},

deactivateMonitor: function () {
// If always-on is enabled, keep monitor activated
let alwaysOnTrigger = this.alwaysOn && (this.alwaysOn.readSync() === this.config.alwaysOnState)
let alwaysOffTrigger = this.alwaysOff && (this.alwaysOff.readSync() === this.config.alwaysOffState)
let alwaysOnTrigger = this.alwaysOn && (this.alwaysOn.readSync() === this.config.alwaysOnState);
let alwaysOffTrigger = this.alwaysOff && (this.alwaysOff.readSync() === this.config.alwaysOffState);
if (alwaysOnTrigger && !alwaysOffTrigger) {
return;
}
// If relays are being used in place of HDMI
if (this.config.relayPin !== false) {
this.relay.writeSync((this.config.relayState + 1) % 2);
this.sendSocketNotification('POWER_SAVE', true);
}
else if (this.config.relayPin === false) {
exec("/usr/bin/vcgencmd display_power 0", null);
this.sendSocketNotification('POWER_SAVE', true);
}
},

Expand All @@ -67,7 +73,7 @@ module.exports = NodeHelper.create({
// Setup for alwaysOn switch
if (this.config.alwaysOnPin) {
this.alwaysOn = new Gpio(this.config.alwaysOnPin, 'in', 'both');
const alwaysOnState = this.config.alwaysOnState
const alwaysOnState = this.config.alwaysOnState;
this.alwaysOn.watch(function (err, value) {
if (value === alwaysOnState) {
self.sendSocketNotification('ALWAYS_ON', true);
Expand All @@ -93,7 +99,7 @@ module.exports = NodeHelper.create({
// Setup for alwaysOff switch
if (this.config.alwaysOffPin) {
this.alwaysOff = new Gpio(this.config.alwaysOffPin, 'in', 'both');
const alwaysOffState = this.config.alwaysOffState
const alwaysOffState = this.config.alwaysOffState;
this.alwaysOff.watch(function (err, value) {
if (value === alwaysOffState) {
self.sendSocketNotification('ALWAYS_OFF', true);
Expand All @@ -109,6 +115,7 @@ module.exports = NodeHelper.create({
}

// Setup for sensor pin
console.log("Creating GPIO for sensorPin: " + this.config.sensorPin);
this.pir = new Gpio(this.config.sensorPin, 'in', 'both');

// Setup value which represent on and off
Expand Down