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

@heathbar/home-assistant-rxjs

v1.0.0

Published

RxJs wrapper for home assistant state changes

Downloads

2

Readme

home-assistant-rxjs

A simple service that exposes Home Assistant events as an RxJs stream (with TypeScript support).

Usage

Subscribe to all changes of all entities

const hass = new HomeAssistant('http://192.168.0.101:8123');

hass.entities$.subscribe(entities => console.log(entities));
hass.config$.subscribe(entities => console.log(entities));
hass.services$.subscribe(entities => console.log(entities));

callService

Call any Home Assistant service

await hass.callService('light', 'turn_on', { entity_id: 'light.my_light', brightness_pct: 50, color_name: 'blue' });

await hass.callService('media_player', 'media_play_pause', { entity_id: 'media_player.my_music_player'});

await hass.callService('script', 'party_time');

selectEntity

Filters out all events except for the specified entity

hass.entities$.pipe(
    selectEntity('sensor.temperature')
).subscribe(temperatureEntity => console.log(temperatureEntity));

// Emits HassEntity instances 

{
    attributes: { 
        device_class: "temperature"
        friendly_name: "Outdoor Temperature"
        icon: "mdi:thermometer"
        unit_of_measurement: "°F"
    },
    context: { ... },
    entity_id: 'sensor.temperature',
    last_changed: "2021-09-25T05:18:10.850272+00:00"
    last_updated: "2021-09-25T05:18:10.850272+00:00",
    state: '47.4'
}

selectEntityState

Filters out all events except for the specified entity and emit only the current state of the given entity

hass.entities$.pipe(
    selectEntityState('sensor.temperature')
).subscribe(temperatureState => console.log(temperatureState));

// Emits strings

'47.4'

Additional Information

This library was designed with the browser in mind, although it would not be much work to make it work in node.

This library relies on the official home-assistant-js-websocket library to provide OAuth authorization to your Home Assistant instance.

On first launch, the library will forward the browser to the specified Home Assistant host to initiate an OAuth session. On success, the library will store the auth token it receives in sessionStorage.

autoConnect

By default, the library will initiate a connection when you create a new HomeAssistant instance. This can be disabled as follows

const hass = new HomeAssistant('http://192.168.0.101:8123', { autoConnect: false });

// and later...

await hass.connect()

tokenKey

By default, the library will store its auth token in session storage under the key hass-token. This can be changed as follows

const hass = new HomeAssistant('http://192.168.0.101:8123', { tokenKey: 'some-other-key' });