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.

Contact Sensor not seen as actual sensor in homekit

See original GitHub issue

Hi i have created a contact sensor which is kinda working but i have two issues.

In the homekit app in IOS 10, i do see it as a contact sensor and it shows the correct state. but when i go to the automation tab, the option “A sensor detects something” is still grayed out. i was kinda hoping that once i have one sensor in homekit i could use this.

On the background, the sensor state is read every second, but in the IOS application it’s only updated when it’s refreshed from the IOS app. Is there a way to publish the state to all devices, so i see a state change in the homescreen once a door has been opened.

Here is the code of the contact sensor i’m using

var Accessory = require('../').Accessory;
var Service = require('../').Service;
var Characteristic = require('../').Characteristic;
var uuid = require('../').uuid;
var wpi = require('wiring-pi');

var DeurSensorPin=22; //sensor 2 GPIO25 
var lastState=0;
// here's a door device that we'll expose to HomeKit
var DOOR = {
  open: false,
  sensor: 0,
  read: function(){
    wpi.setup('phys');
    wpi.pinMode(DeurSensorPin,wpi.INPUT)
    var DeurSensorValue = wpi.digitalRead(DeurSensorPin);
    //console.log('read sensor',DeurSensorValue);
    DOOR.sensor=DeurSensorValue;
    if(DOOR.sensor==0){
       DOOR.open=false;
       if(lastState!=false){
         console.log('door is closed');
         lastState=false;
       }
    }else{
       DOOR.open=true;
       if(lastState!=true){
       console.log('door is open');
       lastState=true;
       }
    }
  },wait: function() {
     var seconds=1;
     var waitTill = new Date(new Date().getTime() + seconds * 1000);
     while(waitTill > new Date()){}
  },
  identify: function() {
    console.log("Identify the door!");
  }
}

// Generate a consistent UUID for our Lock Accessory that will remain the same even when
// restarting our server. We use the `uuid.generate` helper function to create a deterministic
// UUID based on an arbitrary "namespace" and the word "door".
var doorUUID = uuid.generate('hap-nodejs:accessories:contactsensor');

// This is the Accessory that we'll return to HAP-NodeJS that represents our door
var door = exports.accessory = new Accessory('ContactSensor', doorUUID);

// Add properties for publishing (in case we're using Core.js and not BridgedCore.js)
door.username = "AA:BB:CC:DD:EE:01";
door.pincode = "314-00-000";

// set some basic properties (these values are arbitrary and setting them is optional)
door
  .getService(Service.AccessoryInformation)
  .setCharacteristic(Characteristic.Manufacturer, "Door Sensor")
  .setCharacteristic(Characteristic.Model, "Nemef")
  .setCharacteristic(Characteristic.SerialNumber, "1");

// listen for the "identify" event for this Accessory
door.on('identify', function(paired, callback) {
  DOOR.identify();
  callback(); // success
});

door
   .addService(Service.ContactSensor,"Binnen Deur Sensor")
   .getCharacteristic(Characteristic.ContactSensorState)
   .on('get', function(callback) {
    DOOR.read();
    // return our current value
    callback(null, DOOR.open);
});

setInterval(function() {  
  DOOR.read()
  
  // update the characteristic value so interested iOS devices can get notified
   door
    .getService(Service.ContactSensor)
    .getCharacteristic(Characteristic.ContactSensorState, DOOR.open);  
}, 1000);

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ebaauwcommented, Apr 25, 2018

I think this is a limitation of Apple’s Home app, not of HomeKit. Using another app, like Eve, you should be able to define triggers on any characteristic with notify permission.

1reaction
viictor924commented, Oct 10, 2017

Hi @madcat-nl, I was wondering if you were ever able to figure out the “when sensor detects something” automation rule. I heard this was a new feature in iOS 11 but I wasn’t able to figure it out.

I’ve got a temperature and humidity sensor connected to homekit but the “sensor detects something” automation is still grayed out. I was able to use the EVE app as a workaround but it would be nice if it was all done via the Home app.

FYI, I use a dht22 sensor via homebridge using this plugin: https://github.com/NorthernMan54/homebridge-dht

img_0075 jpg

img_0074 jpg

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sensors from Home Assistant not visible in Homekit
Hi! I am completely new to Home Assistant - finished my setup on Raspberry pi 2 days ago. I am having issues with...
Read more >
No sensors visible in Homekit - Konnected Help & Support
Hi! I recently got my Konnected boards and to test things out I connected 3 window/door sensors to one of the boards. I...
Read more >
3 ways to better use Contact Sensors in your Apple Homekit ...
Follow me@homekitgeek on twitter and instagramwww.homekitgeek blogwww.facebook.com/homekitgeekIf you're interested in adding some new ...
Read more >
Insane Contact Sensor Automation Ideas for HomeKit + Setup!
Let's look at some contact sensor automations! Ideas include a DIY outdoor contact sensor, time based lighting, Siri announcement, and more!
Read more >
Sensors not showing up in Homekit : r/Abode - Reddit
I've recently setup a new abode system with a bunch of door and window sensors, I've got a lot of them. My problem...
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