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>
}