Skip to content

Commit

Permalink
feat: add logger
Browse files Browse the repository at this point in the history
  • Loading branch information
alexciesielski committed Apr 7, 2020
1 parent 536d561 commit 67da9f6
Show file tree
Hide file tree
Showing 12 changed files with 394 additions and 279 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ rxjs wrapper for [home-assistant-js-websocket](https://github.com/home-assistant

2. Create long-lived access token under http://homeassistant:8123/profile

3. Create a `.env` file with two properties `HOST` and `ACCESS_TOKEN`.
3. Create a `.env` file

```
HOST=http://homeassistant.local:8123
ACCESS_TOKEN=<long-lived-access-token>
LOGLEVEL=INFO
```

4. Initialize `HomeAssistantRXJS` and define your automations
Expand All @@ -29,7 +30,6 @@ const motion$ = home.entities.pipe(
// and after 2 seconds turn it off
motion$
.pipe(
distinctUntilChanged(),
filter(state => state === 'on'),
switchMapTo(home.lights.turnOn('light.hall_light')),
delay(2000),
Expand Down
14 changes: 4 additions & 10 deletions example/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
import {
delay,
distinctUntilChanged,
filter,
switchMapTo,
} from 'rxjs/operators';
import { delay, filter, switchMapTo } from 'rxjs/operators';
import { HomeAssistantRXJS, select } from '../lib';

const home = new HomeAssistantRXJS();
home.initialize();

const motion$ = home.entities.pipe(
select('binary_sensor.hall_motion_sensor', 'state'),
select('binary_sensor.office_office_motion_114', 'state'),
);

// When motion detected turn the light on
// and after 2 seconds turn it off
motion$
.pipe(
distinctUntilChanged(),
filter(state => state === 'on'),
switchMapTo(home.lights.turnOn('light.hall_light')),
switchMapTo(home.lights.turnOn('light.office_office_ceiling_light_104')),
delay(2000),
switchMapTo(home.lights.turnOff('light.hall_light')),
switchMapTo(home.lights.turnOff('light.office_office_ceiling_light_104')),
)
.subscribe();
Loading

0 comments on commit 67da9f6

Please sign in to comment.