question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Motion Sensor does not push refresh by itself (only when i pull up the control center)

See original GitHub issue

Hi,

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:closed
  • Created 7 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
snowdd1commented, Feb 16, 2017

…and the same for the other event, too, of course.

0reactions
snowdd1commented, Feb 16, 2017
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found