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

node-home-assistant

v0.2.2

Published

Home Assistant utility library and command line interface

Readme

Node Home Assistant

Home Assistant utility library and command line interface

NOTE: This is a work in progress ymmv. Currently it's working in my very limited testing and uses the Server Sent Events interface Home Assistant surfaces along with the REST api.

Command Line

Install

  1. Install the module npm install -g node-home-assistant
  2. Add an environment variable with your Home Assistant URL and Password exported as HA_URL and HA_PASSWORD
  3. Run ha history as a quick test
  4. See other commands and examples by running ha with no other options
  5. The command line tool surfaces a lot of the defaults and configuration via environment variables, checkout config.js for a listing

Command line help output

$ ha

Usage: ha [cmd]

Options:
  -V, --version                                 output the version number
  -v, --version                                 get version
  -d, --debug                                   output debug messages
  -u, --url <url>                               home assistant url
  -p, --password <password>                     home assistant password
  -h, --help                                    output usage information

Commands:
  history [options]                             Get history, defaults to all history from past hour
  states [options]                              Get list of all known states, returns only the list of entity_ids with states
  entities [options]                            Get list of all known entities, returns only the list of entity_ids
  dashboard [options]                           Display a dashboard that is updated with state data as events occur
  service <domain> <service> [data]             Calls home assistant service with data provided, outputs the response body from home assistant
  show [options] <entity|entities> [entity_id]  Get all details of one or more home assistant entities, returns only JSON object. If no entity is found JSON object will be empty, no error will be thrown
  *

  Examples:

    * History:
      $ ha history --pretty --relative-dates
      $ ha history --entity_id binary_sensor.motion_office_motion
      $ ha history --include office --exclude group --pretty
      $ ha history --include '(office|livingroom)' --exclude '(sensor|group)' --pretty
      $ ha history --from "3 days ago" --to "2 days ago"
      $ ha history -i '(office|bedroom)' -e '(^sensor|device_tracker|group)' -f '1 day ago' --pretty
    * States:
      $ ha states
      $ ha states --pretty --relative-dates
      $ ha states -i '^sensor' -e '_motion$|transmission|pihole'
    * Entities:
      $ ha entities
      $ ha entities --pretty
      $ ha entities --include '^sensor' --exclude '_motion$|transmission|pihole'
    * Entity Details:
      $ ha show entities
      $ ha show entities group.all_switches
      $ ha show entities --include sensor
    * Calling Services
      $ ha service light turn_on '{ "entity_id": "light.garage_hue_room" }'
      $ ha service light turn_off '{ "entity_id": "light.garage_hue_room" }'
      $ ha service light turn_off
    * Dashboard:
        $ ha dashboard
        $ ha dashboard --include '^sensor' --exclude '_motion$|transmission|pihole'

Use as a library in your own project

  1. Install module locally npm install --save node-home-assistant
  2. Check out the _examples directory in this project which shows some usage of the API and Events listener interfaces
  3. Quick example below:
const HomeAssistant = require('node-home-assistant');

const config = {
    baseUrl: 'http://localhost:8123',
    apiPass: 'supersecretpassword'
};

const homeAssistant = new HomeAssistant(config, { startListening: true });

// Call a service with domain, service, data
homeAssistant.api.callService('light', 'turn_off', { entity_id: 'light.office_hue_room' })
    .then(res => console.log('Light switched off', res))
    .catch(e => console.log(e));

// Events by event_type as sent by home assistant ('state_changed' and 'service_executed' from home assistant below)
homeAssistant.events.on('ha_events:state_changed', (evt) => console.log(`(ha_events:state_changed) ${JSON.stringify(evt)}`));

TODO

  • [x] CLI option to call service
  • [ ] More tests
  • [ ] Finish CLI Dashboard
  • [ ] Update API to use new home assistant authentication methods