i-client

The Home Assistant client API. Once initialised, the client will make requests via **either** the websocket or HTTP API where appropriate

Name i-client
Type Interface
Path packages/hass-ts/src/lib/core/client/i-client.ts

Methods

callService

Call a service action

See

Signature
    callService(params: Omit<CallServiceCommand, 'id' | 'type'>): Promise<State[]>; 
Parameters
Name Type Description
params Omit<CallServiceCommand, 'id' | 'type'> parameters to send with the service command
Return Value
Promise<State[]>

close

Close the websocket connection

Signature
    close(): Promise<void>; 
Return Value
Promise<void>

getAreas

Gets a list of areas registered with home assistant

Signature
    getAreas(): Promise<HassArea[]>; 
Return Value
Promise<HassArea[]>

getCalendars

Get a list of all registered calendars

Signature
    getCalendars(): Promise<CalendarDetails>; 
Return Value
Promise<CalendarDetails>

getConfig

Get the current Home Assistant configuration

Signature
    getConfig(): Promise<Config>; 
Return Value
Promise<Config>

getDevices

Get a list of all devices currently registered by home assistant

Signature
    getDevices(): Promise<HassDevice[]>; 
Return Value
Promise<HassDevice[]>

getEntities

Get a list of all entities currently registered by home assistant

Signature
    getEntities(): Promise<HassEntity[]>; 
Return Value
Promise<HassEntity[]>

getErrorLog

Retrieve all errors logged during the current session of Home Assistant as a plaintext response.

Signature
    getErrorLog(): Promise<string>; 
Return Value
Promise<string>

getEvents

Get the complete list of events that can be listened to and the number of subscribers

Signature
    getEvents(): Promise<EventDetails[]>; 
Return Value
Promise<EventDetails[]>

getHistory

Returns an array of state changes from the past

Signature
    getHistory(params: GetHistoryParams): Promise<State[][]>; 
Parameters
Name Type Description
params GetHistoryParams
Return Value
Promise<State[][]>

getLogbook

Gets a list of entries from the Home Assistant logbook

Signature
    getLogbook(params?: GetLogbookParams): Promise<LogBookEntry[]>; 
Parameters
Name Type Description
params GetLogbookParams params to filter the results
Return Value
Promise<LogBookEntry[]>

getPanels

Get a list of all registered panels

Signature
    getPanels(): Promise<Record<string, Panel>>; 
Return Value
Promise<Record<string, Panel>>

getServiceDomains

Get a list of possible domains for services

Signature
    getServiceDomains(): Promise<ServiceDomainDetails[]>; 
Return Value
Promise<ServiceDomainDetails[]>

getServices

Get details of all the services currently registered in home assistant, grouped by domain

Signature
    getServices(): Promise<Record<string, Service>>; 
Return Value
Promise<Record<string, Service>>

getState

Get the current state of a specific entity

Signature
    getState(entityId: string): Promise<State>; 
Parameters
Name Type Description
entityId string The entity id in the form .
Return Value
Promise<State>

getStates

Get a list of the current states of all entities

Signature
    getStates(): Promise<State[]>; 
Return Value
Promise<State[]>

registerTrigger

Subscribe to a trigger. See https://developers.home-assistant.io/docs/api/websocket/#subscribe-to-trigger

Signature
    registerTrigger(trigger: SubscribeToTriggerMessage['trigger'], callback: (event: unknown) => void | Promise<void>): Promise<void>; 
Parameters
Name Type Description
trigger SubscribeToTriggerMessage['trigger']
callback (event: unknown) => void | Promise<void>
Return Value
Promise<void>

subscribeToEvents

Subscribe to events

Signature
    subscribeToEvents(callback: (message: Event | TriggerEventMessage['event']) => void): Promise<void>; 
Parameters
Name Type Description
callback (message: Event | TriggerEventMessage['event']) => void Fire this callback when any Home Assistant events are triggered
Return Value
Promise<void>

subscribeToEvents

Subscribe to events of a specific type

Signature
    subscribeToEvents(type: string, callback: (message: Event | TriggerEventMessage['event']) => void): Promise<void>; 
Parameters
Name Type Description
type string type of the event to listen for
callback (message: Event | TriggerEventMessage['event']) => void Fire this callback when the Home Assistant events are triggered
Return Value
Promise<void>