Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
alexciesielski committed Apr 2, 2020
1 parent f34819f commit 536d561
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 37 deletions.
32 changes: 9 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,28 @@ HOST=http://homeassistant.local:8123
ACCESS_TOKEN=<long-lived-access-token>
```

4. Create a class that extends `HomeAssistantRXJS` and define your automations
4. Initialize `HomeAssistantRXJS` and define your automations

```
import {
delay,
distinctUntilChanged,
filter,
switchMapTo,
} from 'rxjs/operators';
import { HomeAssistantRXJS, select } from '@ciesielskico/home-assistant-rxjs';
export class Home extends HomeAssistantRXJS {
constructor() {
super();
this.initialize();
}
}
const home = new Home();
// When motion detected turn the light on
// and after 2 seconds turn it off
const home = new HomeAssistantRXJS();
home.initialize();
const motion$ = home.entities.pipe(
select('binary_sensor.office_office_motion_114', 'state'),
select('binary_sensor.hall_motion_sensor', '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.office_office_ceiling_light_104')),
switchMapTo(home.lights.turnOn('light.hall_light')),
delay(2000),
switchMapTo(home.lights.turnOff('light.office_office_ceiling_light_104')),
switchMapTo(home.lights.turnOff('light.hall_light')),
)
.subscribe();
```

## Deploy as add-on on Home Assistant
Expand Down
21 changes: 7 additions & 14 deletions example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,21 @@ import {
} from 'rxjs/operators';
import { HomeAssistantRXJS, select } from '../lib';

export class Home extends HomeAssistantRXJS {
constructor() {
super();
this.initialize();
}
}

const home = new Home();

// When motion detected turn the light on
// and after 2 seconds turn it off
const home = new HomeAssistantRXJS();
home.initialize();

const motion$ = home.entities.pipe(
select('binary_sensor.office_office_motion_114', 'state'),
select('binary_sensor.hall_motion_sensor', '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.office_office_ceiling_light_104')),
switchMapTo(home.lights.turnOn('light.hall_light')),
delay(2000),
switchMapTo(home.lights.turnOff('light.office_office_ceiling_light_104')),
switchMapTo(home.lights.turnOff('light.hall_light')),
)
.subscribe();

0 comments on commit 536d561

Please sign in to comment.