0.0.3 • Published 6 years ago
@ciesielskico/home-assistant-rxjs v0.0.3
home-assistant-rxjs
rxjs wrapper for home-assistant-js-websocket
Getting started
npm install @ciesielskico/home-assistant-rxjsCreate long-lived access token under http://homeassistant:8123/profile
Create a
.envfile
HOST=http://homeassistant.local:8123
ACCESS_TOKEN=<long-lived-access-token>
LOGLEVEL=INFO- Initialize
HomeAssistantRXJSand define your automations
const home = new HomeAssistantRXJS();
home.initialize();
const motion$ = home.entities.pipe(
select('binary_sensor.hall_motion_sensor', 'state'),
);
// When motion detected turn the light on
// and after 2 seconds turn it off
motion$
.pipe(
filter(state => state === 'on'),
switchMapTo(home.lights.turnOn('light.hall_light')),
delay(2000),
switchMapTo(home.lights.turnOff('light.hall_light')),
)
.subscribe();Deploy as add-on on Home Assistant
Install the Samba share add-on
Open the share under
\\192.168.x.<ha-ip>Create folder
ha-rxjsinsideaddonsCopy
src,package.json,config.json,Dockerfileandrun.shIn Home Assistant under Supervisor choose
Add-On StoreRefresh (upper-right corner)
Install
Start add-on
Development
Start Typescript dev server
npm run dev
Local build
docker build --build-arg BUILD_FROM="homeassistant/amd64-base:latest" -t ha-rxjs .
Local run
docker run --rm --env-file=.env ha-rxjs
Known bugs
- app doesn't exit properly (probably to do with connection)
- require/imports esm throwing warnings