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

homeassistant-react-hooks

v0.1.14

Published

A library providing hooks to easily integrate data from home assistant

Downloads

5

Readme

HomeAssistant React Hooks

This is a collection of react hooks and apis to get state / push events to home assistant using websockets. It can be used to for example create custom dashboards that integrate with home assistant.

Package on NPM

Installation

You can use this library by running either yarn add homeassistant-react-hooks or npm i homeassistant-react-hooks

Token

To create a token that can be used with this, go to your user profile and scroll down to the bottom where you can create a token.

Examples

Code example

import { HassProvider, useHassDevice } from "homeassistant-react-hooks";

// This should be loaded from an external file (to not expose secrets in for example version control)
const config = {
    token: "HOME_ASSISTANT_ACCESS_TOKEN",
    host: "example.com",
};

const MediaPlayer = () => {
    const { title, artist, imgUrl } = useMediaPlayer("kitchen");

    return (
        <div className="media-player">
            <h1>{title} - {artist}</h1>
            <img src={imgUrl} alt="Artwork" />
        </div>
    );
}

const App = () => {
    return (
        <HassProvider token={config.token} connectionOptions={{ host: config.host, port: 443, protocol: "wss" }}>
            <MediaPlayer />
        </HassProvider>
    );
};

Projects using this module

Hooks

To see what each hook returns, use your editor's intellisense (because I'm too lazy to add all of them to this list)

useHassDevice

Access a "raw" home assistant device, with access to all attributes and data, create using the full entity id, for example media_player.kitchen

useLight

Access a light in home assistant. This is probably missing some fields because my lights that I can control with home assistant does not support color so I can't test that. Feel free to create a pull request fixing it if you want.

Do not include the domain in the entity id, for example bedroom_ceiling_1 instead of light.bedroom_ceiling_1

useMediaPlayer

Access a cleaned up / processed media player object containing things like position and artwork url etc.

Do not include the domain in the entity id, for example bedroom_ceiling_1 instead of light.bedroom_ceiling_1

useWeather

Access a weather object with some added fields (like minimum temperature etc.)

This might not work if the weather source isn't setting the first day forecast to today, something I know for example the SMHI source is doing wrong.