automations
구조체는 자동화 스크립트의 핵심입니다. 여기에서 시작 조건, 조건, 작업을 비롯한 자동화 동작이 지정됩니다.
이를 통칭하여 자동화 규칙이라고도 합니다.
automations
구조체에는 하나 이상의 자동화 규칙이 포함되며 각 규칙에는 항상 시작 조건 및 작업 집합이 포함됩니다. 규칙은 선택적으로 조건을 포함할 수 있습니다. 조건은 스크립트를 실행하기 위해 충족되어야 하는 추가 한정자입니다.
키 | 유형 | 설명 |
---|---|---|
|
선택사항 자동화 이름입니다. 이는 사용자에게 표시되지 않으며 개발자 참조용입니다. |
|
|
[Starter] |
필수 시작 조건 목록입니다. |
|
선택사항 조건 |
|
|
[조치] |
필수 작업 목록 |
예
다음은 automations
구조체의 두 가지 소개 예시입니다.
첫 번째 예에서는 'My TV'라는 TV
가 켜지면 자동화가 시작됩니다.
트리거되면 다음 작업이 실행됩니다.
'Light A' 및 'Light B'라는 이름의 두 LIGHT
기기가 켜져 있고 밝기 수준 50으로 설정되어 있습니다.
automations:
- name: Dim the lights
starters:
- type: device.state.OnOff
device: My TV - Living Room
state: on
is: true
actions:
- type: device.command.OnOff
devices:
- Light A - Living Room
- Light B - Living Room
on: true
- type: device.command.BrightnessAbsolute
devices:
- Light A - Living Room
- Light B - Living Room
brightness: 50
두 번째 예에서는 매주 월요일과 목요일 일몰 시 동일한 자동화가 시작됩니다.
automations:
- name: Dim the lights
starters:
- type: time.schedule
at: SUNSET
weekday:
- MONDAY
- THURSDAY
state: on
is: true
actions:
- type: device.command.OnOff
devices:
- Light A - Living Room
- Light B - Living Room
on: true
- type: device.command.BrightnessAbsolute
devices:
- Light A - Living Room
- Light B - Living Room
brightness: 50
시작 조건
Starter 구조체는 자동화 스크립트를 실행하는 시작 조건을 지정하는 곳입니다. 각 automation
에는 시작 조건이 하나 이상 포함될 수 있으며, 후속 조건이 평가되려면 하나 이상의 시작 조건이 true
로 평가되어야 합니다.
time.schedule
시작 조건의 예는 다음과 같습니다.
type: time.schedule
at: sunrise+30min
weekdays:
- MON
- TUE
기기 상태 변경에 관한 시작 조건의 예는 다음과 같습니다.
type: device.state.Volume
device: My TV - Living Room
state: currentVolume
greaterThan: 1
lessThan: 10
기기 이벤트의 시작 조건의 예는 다음과 같습니다.
type: device.event.DoorbellPress
device: My doorbell - Frontdoor
홈 재택 모드 변경의 시작 조건의 예는 다음과 같습니다.
type: home.state.HomePresence
state: homePresenceMode
is: HOME
조건
조건을 논리 연산자 and
, or
, not
와 결합하여 더 복잡한 로직을 표현할 수 있습니다.
다음 예에는 time
조건 하나와 device.state
조건 하나가 있는 condition
구조체가 있습니다. 이 구조체를 사용하면 월요일이나 화요일, 일몰과 일출 사이일 때 또는 TV 볼륨이 1~10인 경우 스크립트를 실행할 수 있습니다.
type: or
conditions:
- type: time.between
before: sunrise
after: sunset
weekdays:
- MON
- TUE
- type: device.state
device: My TV - Living Room
trait: Volume
state: currentVolume
greaterThanOrEqualTo: 1
lessThanOrEqualTo: 10
자동화 스크립트의 실행을 주말 오전 10시 이전으로 제한하는 기본 time
조건 예시입니다.
type: time.between
before: 10am
weekdays:
- SAT
- SUN
온도 조절기 기기 센서 온도 조건:
type: device.state.TemperatureSetting
device: My Thermostat - Living Room
state: thermostatTemperatureAmbient
greaterThan: 65F
home.state.HomePresence
조건의 예는 다음과 같습니다.
type: home.state.HomePresence
state: homePresenceMode
is: AWAY
작업
시작 조건과 조건과 마찬가지로 각 작업에는 지정된 작업의 종류를 나타내는 type
가 있습니다.
가장 중요하고 유용한 유형은 device.command
명령어 유형입니다. 조명을 끄는 작업의 예
type: device.command.OnOff
devices:
- Light A - Living Room
on: false
다른 여러 작업 사이에 지연을 추가하는 작업입니다.
type: time.delay
for: 5min