automations 구조체는 자동화 스크립트의 핵심입니다. 여기에서 시작 조건, 조건, 작업을 비롯한 자동화 동작이 지정됩니다.
이를 통칭하여 자동화 규칙이라고도 합니다.
automations 구조체에는 하나 이상의 자동화 규칙이 포함되며 각 규칙에는 항상 시작 조건과 작업 집합이 포함됩니다. 규칙에는 스크립트가 실행되기 위해 충족되어야 하는 추가 한정자인 조건이 선택적으로 포함될 수 있습니다.
| 키 | 유형 | 설명 |
|---|---|---|
|
|
선택사항 자동화의 이름입니다. 사용자에게는 표시되지 않으며 개발자 참조용입니다. |
|
|
|
[Starter] |
필수 스타터 목록입니다. |
|
|
선택사항 조건 |
|
|
|
[작업] |
필수 작업 목록 |
예
다음은 automations 구조체의 두 가지 소개 예시입니다.
첫 번째 예에서는 'My TV'라는 TV가 켜지면 자동화가 시작됩니다.
트리거되면 다음 작업이 실행됩니다.
'조명 A' 및 '조명 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
선발 명단
시작 조건 구조체는 자동화 스크립트가 실행되도록 하는 시작 조건을 지정하는 곳입니다. 각 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