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

@hass-blocks/core

v3.17.9

Published

A strongly typed declarative framework for configuring Home Assistant automations

Readme

This project is still currently in development. It may be buggy and is certainly not feature complete. I could definitely do with additional contributors so do get in touch!

Hass Blocks

A strongly-typed declarative framework for configuring Home Assistant automations.

Getting Started

Installing

npm install @hass-blocks/core

Bootstrapping

Before you can build automations, you first need to configure the connection to Home Assistant. To do this, ensure you have populated the following environment variables:

  • HASS_HOST - the hostname of your Home Assistant installation
  • HASS_PORT - the port your Home Assistant installation is available on (defaults to 8123 if not provided)
  • HASS_TOKEN - a long lived access token you've configured

Once this is done, the below code will bootstrap the connection and give you a registry object that you can register automations with

import { initialiseBlocks} from "@hass-blocks/core"

const { registry } = await initialiseBlocks()

How it works

Hass-blocks is all about creating blocks that describe what you want to happen and combining them with triggers to make an automation. There are a few different kinds of blocks

  • Actions - a generic block that describes something you want to happen
  • Service Calls - an action that calls a Home Assistant service
  • Assertions - a block that decides whether a sequence of actions should continue executing
  • Sequences - a block that when executed executs a number of different blocks, either in sequence or all at once
  • Conditions - a block that decides which block to execute based on a condition

Since this is a framework, its your job to write a whole bunch of blocks that you can then compose together in order to build your automations, so lets talk a little bit about how to do that.

It is very much my intention to write a package containing a whole series of premade blocks that you can use to easily build your automations. If this feels useless right now, its because its in its very early stages. Watch this space...

Creating your automation

A pretty standard action in my flat is to turn on the living room light - lets turn that into a block

import { serviceCall } from "@hass-blocks/core"

const turnOnLivingRoomLight = serviceCall({
  name: "Turn on the light in the living room",
  params: {
    domain: "light",
    service: "turn_on",
    target: {
      entity_id: "light.living_room"
    }
  }
})

As well as making standalone actions, you can create factory functions that generate actions. So given that I am going to want to turn my light both on and off, lets do some refactoring

const turnLivingRoomLights = (onOrOff: "on" | "off") =>
  serviceCall({
    name: 'Turn on the light in the living room',
    params: {
      domain: 'light',
      service: onOrOff === "on" ? "on" : "off",
      target: {
        entity_id: 'light.living_room',
      },
    },
  });

Ideally I want it to turn on when I walk in the room, so lets make a trigger

import { trigger } from "@hass-blocks/core"

const whenSomeoneWalksInTheLivingRoom = trigger({
  name: 'When someone walks in the living room',
  trigger: {
    platform: 'state',
    entity_id: 'binary_sensor.motion_occupancy',
    from: 'off',
    to: 'on',
  },
});

I don't want to switch the light off straight away - so lets implement a 'wait' action factory

import { action } from "@hass-blocks/core"

export const waitMinutes = (duration: number) =>
  action({
    name: `Wait ${duration} minutes`,
    callback: async () => {
      return await new Promise<void>((accept) =>
        setTimeout(
          () => {
            accept();
          },
          1000 * 60 * duration
        )
      );
    },
  });

Ok, looks like we are ready to create our first automation! Lets put it all together

export const livingRoomMotionSensor = automation({
  name: "Living room motion sensor",
  when: someoneWalksInTheLivingRoom,
  then: [
    turnLivingRoomLights('on'),
    waitMinutes(10),
    turnLivingRoomLights('off')
  ]
})

And now the final part of the puzzle - lets register it with our client!

registry.registerAutomation(livingRoomMotionSensor)