npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

homebridge-contact-switch-notification

v0.0.1

Published

Contact-Switch Notification plugin for homebridge

Downloads

8

Readme

Homebridge Contact Switch Notification

Summary: Provides a switch which can be toggled by automations, which will open/close a (fake) contact sensor when toggled. The sensor can be subscribed to for notifications.

A common need in Homekit is for push notifications. The Home app natively supports push notifications for Blinds & Windows, Doors & Locks, Sensors (e.g. motion, other contact sensors), and Security devices. But, aside from time of day and people present, these notifications are all-or-nothing, no other conditions allowed. And you can't get notified about changes to other Homekit accessories, like switches, etc.

What if you want to be notified if a pair of doors both stay open for more than 2 minutes after 3pm? Impossible, right? There are solutions which use external services (like IFTTT, getPushed, etc.), but what if you want to keep it all local to Homekit, away from prying eyes on the cloud?

The solution is to create a dummy notification accessory (a fake door!) that can be subscribed to for push notifications, from the front page of the Home app, and use automations to toggle it at the right time (whenever you define that to be).

One solution to this need (on which this plugin is based) is homebridge-motion-switch, which uses a switch with a fake motion sensor, which gets triggered (and thus can send a notification) when the switch is toggled.

But the notification says "Motion detected by Room MySensorName". What if you instead have a situation where being alerted with a push message mentioning a door, window, or other contact sensor message would be more appropriate than motion? This plugin is for you. Note that a Homekit contact sensor can be customized in the Home app to be displayed as a Door, Blinds, Garage Door, Window, or generic Contact Sensor, and this changes the notfication message. Note also that you get two notifications: once when opened, and again when closed, so this plugin is really ideal for notifications regarding two state systems (the doors were both opened for more than 2minutes... now they are both closed). See the auto_reset config variable below if you want to have this 2nd notification be meaningful.

Setup

npm install -g homebridge-contact-switch

And add the following to the accessories list in your Homebridge config. Change names as you wish.

{
  "accessory": "Contact Switch Notification",
  "contact_name": "My Door",
  "name": "Door Notifier",
  "auto_reset": false
}

Here name is the name of the overall accessory, with two services (a switch to activate the notifier, and a contact sensor named contact_name). If auto_reset is true (the default), the switch and contact will be auto-reset after 1 second (generating another notification). If it is false, you need to arrange to turn off the switch yourself (the contact will be automatically reset then, sending a closed notification).

Once added to Homekit, you will need to turn on Notifications for the fake contact sensor you just added, and possibly change it to a door, windows, etc. (see e.g. this note).

Example: Door Was Left Open!!!

As an example non-trivial use of this notifier: we'll set up notification if a door is left open for more than one minute (a common occurrence in my household!), notifying again if and when it (finally!) gets closed. This takes 3 automations to make work, and another dummy switch.

  1. Create a dummy regular switch to track the state of the door (using e.g. a StatefulDummySwitch): call it Door Open.
  2. Create a Contact Switch Notification accessory named Door Open Notifier with contact_name: "Door was LEFT OPEN!!!", using "auto_reset": false.
  3. In the Home app, drill down into the Door Open Notifier accessory settings, click on the contact sensor service, and choose Display As as Door.
  4. In the Home app, create an automation that toggles the Door Open dummy switch on when the real door opens (#1), and turns it off after 1 minute (or however long you want to give).
  5. Create another automation (#2) for when the accessory Door Open turns off (which will happen automatically after one minute), toggling the Door Notifier switch on. Now, as a final step, use the Eve app to add a condition to automation #2: only run it if your real door is (still) open! Note that Home will report but cannot yet set these conditions on automations, so you have to use a 3rd party app like Eve.
  6. Create an automation (#3) that turns off the Door Notifier switch when the real door closes. Usually this will do nothing, since it will have never gotten turned on!

Here's the config:

    {
      "accessory": "StatefulDummySwitch",
      "name": "DoorOpen"
    },
    {
      "accessory": "Contact Switch Notification",
      "name": "Door Open Notifier",
      "contact_name": "Door Left OPEN!!!",
      "auto_reset": false
    },

Here's how it work: when the real door opens, automation #1 sets the dummy switch on, and begins a 1 minute count-down. At the end of the minute, the dummy switch is turned off, triggering automation #2, which checks the state of the door. If the actual door is closed, nothing happens, no notification, etc. But if the door is still open, automation #2 toggles the notifier switch this plugin provides. The notifier switch opens the "fake" contact, which sends out a notification, ala "Room Front Door Left OPEN!!! was opened". With auto_reset: false set in the config, the notifier switch will stay on. Once the door is actually closed, automation #3 toggles off the notifier switch, and you get a final notification of it closing.