Motion Sensor does not push refresh by itself (only when i pull up the control center)
See original GitHub issueHi,
i used a plugin from “homebridge-hc-sr501” and customiced it for me.
I want to activate an motionSensor when a pin is detecting something and and deactivate when another pin detect something. Sounds very easy 😃
I got now the main function, but i get the notification at least when i pull up (refresh) the Control center on my iPhone. I think i missed the function to pull the service by its own…
Can anyone help me there?
Is it correct that the this.service.getCharacteristic(Characteristic.MotionDetected) .on('get', this.getState.bind(this));
should take care of this?
var Service;
var Characteristic;
var HomebridgeAPI;
var Gpio = require('onoff').Gpio;
var insideTriggered = false;
var outsideTriggered = false;
module.exports = function(homebridge) {
Service = homebridge.hap.Service;
Characteristic = homebridge.hap.Characteristic;
HomebridgeAPI = homebridge;
// console.log(Service.ContactSensor);
homebridge.registerAccessory("homebridge-hc-sr501", "HC-SR501", SR501);
};
function SR501(log, config) {
this.log = log;
this.name = config.name;
this.pinIdInside = config.pinIdInside;
this.pinIdOutside = config.pinIdOutside;
this.sensorInside = new Gpio(this.pinIdInside, 'in', 'both');
this.sensorOutside = new Gpio(this.pinIdOutside, 'in', 'both');
this.sensorInside.watch(function (err, value) {
if (err) {
throw err;
}
console.log("SENSOR INSIDE -sensorInside.watch" + value);
if (value == 1){
insideTriggered = true;
outsideTriggered = false;
console.log("SENSOR INSIDE -insideTriggered: " + insideTriggered + " -outsideTriggered: " + outsideTriggered);
}
});
this.sensorOutside.watch(function (err, value) {
if (err) {
throw err;
}
console.log("SENSOR OUTSIDE -sensorOutside.watch" + value);
if (value == 1){
outsideTriggered = true;
insideTriggered = false;
console.log("SENSOR OUTSIDE -insideTriggered: " + insideTriggered + " -outsideTriggered: " + outsideTriggered);
}
});
// info service
this.informationService = new Service.AccessoryInformation();
this.informationService
.setCharacteristic(Characteristic.Manufacturer, "PIR Manufacturer")
.setCharacteristic(Characteristic.Model, config.model || "HC-SR501")
.setCharacteristic(Characteristic.SerialNumber, config.serial || "4BD53931-D4A9-4850-8E7D-8A51A942FA29");
this.service = new Service.MotionSensor(this.name);
this.service.getCharacteristic(Characteristic.MotionDetected)
.on('get', this.getState.bind(this));
var that = this;
if (insideTriggered == true) {
that.service.setCharacteristic(Characteristic.MotionDetected, 1);
insideTriggered = false;
console.log("OUTSIDE TRIGGERED -Characteristic.MotionDetected 1");
}
if (outsideTriggered == true) {
that.service.setCharacteristic(Characteristic.MotionDetected, 0);
outsideTriggered = false;
console.log("INSIDE TRIGGERED -Characteristic.MotionDetected 0");
}
process.on('SIGINT', function () {
that.motionSensor.unexport();
});
}
SR501.prototype.getState = function(callback) {
var val = insideTriggered;
console.log("MANUAL UPDATE -getState insideTriggered: " + insideTriggered);
callback(null, val);
};
SR501.prototype.getServices = function() {
console.log("??? getServices this.informationService " + this.informationService);
console.log("??? getServices this.service " + this.service);
return [this.informationService, this.service];
};
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Motion Detection & Notification Not Working - Reolink
Reason and fixes for motion detection security cameras not detecting motion, detect movement but not record, no motion notification & alert.
Read more >Customize iPhone for motion sensitivities - Apple Support
If you have sensitivity to motion on your iPhone, you can stop or reduce or stop the movement of some screen elements, transitions,...
Read more >Guide to Motion Sensor Lights: Everything You Need to Know
This guide is full of motion sensor light knowledge. We talk about everything from what they are, why you need them, and where...
Read more >Apple Watch Troubleshooting: Common Problems and Solutions
Struggling with some Apple Watch issues? We've compiled a list of some of the most common problems and how to deal with them....
Read more >Troubleshoot when your thermostat won't turn on
Nest Thermostat E Nest Learning Thermostat.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
…and the same for the other event, too, of course.
https://en.wikipedia.org/wiki/Unix_signal#SIGINT
Usually ctrl-c in terminal.