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 🙏

© 2026 – Pkg Stats / Ryan Hefner

homebridge-api-state-switch

v1.0.0

Published

A Homebridge plugin that exposes virtual switches whose state is controlled entirely by polling an API endpoint.

Readme

🔌 ⚡ homebridge-api-state-switch

Create virtual HomeKit switches whose ON/OFF state is controlled entirely by polling an API endpoint.


This Homebridge plugin lets you expose virtual switches that automatically flip ON or OFF based on the results of a GET request to any HTTP API.

It's perfect for things like:

  • 🗑️ Bin day reminders
  • 📅 “Is today a holiday?”
  • 🌦️ “Is it raining right now?”
  • 🚗 “Is the car charging?”
  • 🖥️ “Is this server online?”
  • 🧹 “Is the robot vacuum currently cleaning?”
  • 🛏️ Presence / status switches
  • 🌡️ Custom sensor states from any backend you build

You write the API → Homebridge polls it → HomeKit gets a virtual switch with real-time state.

No control endpoints required.
No devices needed.
Just pure API → Switch state binding.


✨ Features

  • Polls any HTTP GET endpoint on an interval
  • Converts API responses into HomeKit switch ON/OFF state
  • Optional jsonPath to extract boolean values from JSON
  • Optionally read-only (user cannot toggle the switch)
  • Supports multiple switches
  • Works with Siri, automations, scenes, widgets
  • Designed using the latest official Homebridge plugin template
  • Lightweight & fast — no cloud dependencies

📦 Installation

Through Homebridge UI (recommended)

  1. Open Homebridge Config UI X
  2. Go to Plugins
  3. Search for:
    homebridge-api-state-switch
  4. Install
  5. Restart Homebridge

⚙️ Configuration

Add this to your config.json (or use the UI settings panel):

{
  "platform": "ApiStateSwitchPlatform",
  "switches": [
    {
      "name": "Bin Day",
      "url": "https://my-api.dev/bins/today",
      "jsonPath": "today.isBinDay",
      "interval": 3600,
      "readOnly": true
    }
  ]
}

Field Breakdown

| Field | Type | Required | Description | |--------------|---------|----------|-------------| | name | string | Yes | The HomeKit switch name. | | url | string | Yes | GET endpoint to poll for state. | | jsonPath | string | No | Dot-notation path inside JSON to extract a boolean (e.g. today.isBinDay). | | interval | number | Yes | Polling interval in seconds. | | readOnly | boolean | No | Prevents the user toggling the switch in HomeKit (default: true). |


🧠 How It Works

Every interval seconds:

  1. The plugin sends a GET request to the configured url.
  2. If a jsonPath is provided, that nested value is extracted using dot-notation
    Example response:
    { "today": { "isBinDay": true } }
    

With jsonPath: today.isBinDay → the switch becomes ON.


You can then build automations like:

  • “When Bin Day turns ON → send a notification”
  • “When Server Offline switch turns ON → flash a light”
  • “When Rain switch turns ON → close the skylight”

🧪 Example API Responses

Simple boolean

true

JSON response

{
    "today": {
        "isBinDay": true
    }
}

Nested extraction

Config:

"jsonPath": "today.isBinDay"

🛠 Example: Minimal test API (Node.js)

import express from "express";
const app = express();

app.get("/bins/today", (req, res) => {
res.json({ today: { isBinDay: new Date().getDay() === 2 } }); // Tuesday
});

app.listen(3000, () => console.log("Test API running on port 3000"));

Run:

node server.js

Use this in your plugin config:

http://localhost:3000/bins/today

🔒 Security Notes

  • Only GET requests are supported currently.
  • HTTPS is strongly recommended.
  • If your API requires headers or tokens, support is planned for a future release.

🐞 Debugging

Enable debug logs in Homebridge UI.

You’ll see logs like:

Updated "Bin Day" → true

Or errors like:

Polling failed for "Bin Day": Request failed with status 500

🔧 Roadmap

Planned / potential features:

  • Custom headers / bearer token support
  • Cron-style polling
  • ContactSensor / OccupancySensor support
  • Multiple boolean outputs from a single endpoint
  • Retry / backoff strategies
  • Webhook-triggered updates (instead of polling)

🤝 Contributing

Issues and pull requests are welcome.

If you’d like to extend functionality (headers, cron, service types, richer parsing, etc.), feel free to open an issue or PR.


📜 License

MIT