
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
tsnode-homeassistant
Advanced tools
It's simple reactive way of access and control HomeAssistant using the websocket api.
This is very first versions of the library and some functionality is missing...
Please, do not hasitate to create an issues if you will find any bug or missing functionality.
$ npm i --save tsnode-homeassistant
Or use seed project
https://github.com/troyanskiy/tsnode-homeassistant-seed
import { HomeAssistant, IHAEvent } from 'tsnode-homeassistant';
import { IButtonEventData } from './data';
import { CONFIG } from './config';
import { map } from 'rxjs/operators';
// Create the HomeAssistant instance and connect to the HA server
const ha = new HomeAssistant(CONFIG);
ha
.events // Events object
.select('deconz_event') // Select HA events
.pipe(
map(($event: IHAEvent<IButtonEventData>) => $event.data) // Map event
)
.subscribe(data => { // Subscribe to events
console.log('The event', data);
});
ha
.states
.onChange
.subscribe(state => console.log(state));
connectionStatus$: Observable<HAConnectionStatus>
connectionStatus: HAConnectionStatus
ready$: Observable<void>
haVersion: string
events: HomeAssistantEvents
Details below
service: HomeAssistantService
Details below
entities: HomeAssistantEntities
Details below
Available as object on HomeAssistant instance <instance>.events
*.events.select(eventType: string): Observable<IHAEvent<T>>
export interface IHAEvent<T = any> {
data: T; // event data
event_type: string; // event type or name
time_fired: string; // time of event fire
origin: string; // event origin
context?: IHAEventContext;
}
export interface IHAEventContext {
id: string;
parent_id: string | null;
user_id: string | null;
}
Above
Available as object on HomeAssistant instance <instance>.service
*.service.call(domain: HADomain, service: HAServiceActionType, serviceDataOrEntity?: any): Observable<IHAResultMessage>
Will return an observable with service execution result
ha
.service
.call(
HADomain.Light,
HAServiceType.TurnOn,
'light.EntityId1'
)
ha
.service
.call(
HADomain.Light,
HAServiceType.TurnOn,
'EntityId1'
)
ha
.service
.call(
HADomain.Switch,
HAServiceType.TurnOff,
['EntityId1', 'switch.EntityId2']
)
ha
.service
.call(
HADomain.Switch,
HAServiceType.Toggle,
{
entity_id: ['EntityId1', 'EntityId2']
}
)
toggle(domain: HADomain, entities: string[] | string, force?: boolean): Observable<IHAResultMessage>
Will return an observable with service execution result
If
force === true it will call TurnOn serviceforce === false it will call TurnOff serviceforce is missing will call Toggle serviceha
.service
.toggle(
HADomain.Switch,
['EntityId1', 'EntityId2']
)
Available as object on HomeAssistant instance <instance>.entities
All the entities/states are loaded and saved in the memory every time when Node.js instance is connected to the HomeAssistant server
*.entities.onChange: Subject<HAEntity>
ha
.entities
.onChange
.pipe(
filter(entity => entity.id === 'MyEntityId')
)
.subscribe(entity => {
// do something with new state
console.log('Received new state of entity', entity);
})
Will call HA to get all the states, updates them in the memory and returns as observable resolution
*.entities.fetchEntities(): Observable<HAEntity[]>
Will return entity from memory or null if not found
*.entities.getState(entityId: string): HAEntity | null
FAQs
TypeScript/RXJS Node.js api for HomeAssistant
We found that tsnode-homeassistant demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.