use-homeassistant
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

use-homeassistant

Helpers and hooks for building Homeassistant custom dashboards in React. Originally extracted from a personal dashboard. Connects to the Homeassistant websocket API via home-assistant-js-websocket, and the Homeassistant REST API.

Usage

Wrap the components that require interaction with Homeassistant in a HomeassistantProvider, then use provided hooks to fetch data.

More in-depth documentation is available here.

import { HomeassistantProvider, useEntity } from 'use-homeassistant'

const url = 'http://homeassistant.local:8123'
const token = '...' // https://developers.home-assistant.io/docs/auth_api/#long-lived-access-token

const Lightbulb = () => {
  const { state, attributes: { friendly_name } } = useEntity('entity.example_light')

  return <div>
    The light with HA name {friendly_name} is currently {state}
  </div>
}

const App = () => {
  return <HomeassistantProvider homeassistantUrl={url} accessToken={token}>
    <Lightbulb>
  </HomeassistantProvider>
}

Readme

Keywords

Package Sidebar

Install

npm i use-homeassistant

Weekly Downloads

5

Version

0.0.2

License

MIT

Unpacked Size

52.3 kB

Total Files

33

Last publish

Collaborators

  • tmikoss