-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
536d561
commit 67da9f6
Showing
12 changed files
with
394 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Oops, something went wrong.