โอเปอเรเตอร์ช่วยให้คุณตรวจสอบค่าของแอตทริบิวต์ลักษณะเทียบกับค่าที่เฉพาะเจาะจง เปรียบเทียบค่าเหล่านั้นกับค่าอื่นๆ และรวมนิพจน์ที่ใช้ในโหนด condition
โอเปอเรเตอร์พร้อมใช้งานผ่านคำสั่ง import ต่อไปนี้
import com.google.home.automation.and
import com.google.home.automation.between
import com.google.home.automation.contains
import com.google.home.automation.equals
import com.google.home.automation.greaterThan
import com.google.home.automation.greaterThanOrEquals
import com.google.home.automation.lessThan
import com.google.home.automation.not
import com.google.home.automation.notEquals
import com.google.home.automation.or
โอเปอเรเตอร์การเปรียบเทียบ
ระหว่าง
ประเมินเป็น true เมื่อค่าของนิพจน์ 1 อยู่ระหว่างค่าของนิพจน์ 2 และนิพจน์ 3 (รวมค่าขอบเขต) ระบบจะจัดอันดับนิพจน์แตกต่างกันไปตามประเภทข้อมูล ประเภทข้อมูลธรรมดา เช่น ตัวเลขและสตริง จะได้รับการจัดอันดับในลักษณะเดียวกับใน Kotlin
| นิพจน์ 1 | นิพจน์ 2 | นิพจน์ 3 | ผลลัพธ์ |
|---|---|---|---|
6 |
1 |
3 |
false |
2 |
1 |
3 |
true |
ตัวอย่าง DSL
val time = stateReader<_>(structure, Time)
condition() {
expression = time.currentTime
.between(
time.sunsetTime,
time.sunriseTime)
}
ใช้วันที่กับ between()
เมื่อใช้โอเปอเรเตอร์ between() คุณจะระบุช่วงวันที่ได้ดังนี้
val exp2 =
time.currentDate.between(
LocalDate.of(2025, Month.OCTOBER, 1),
LocalDate.of(2025, Month.DECEMBER, 15),
)
อย่างไรก็ตาม คุณไม่ได้จำกัดอยู่เพียงวันที่แบบเต็ม DSL ของระบบอัตโนมัติยังช่วยให้คุณแสดงช่วงวันที่ได้หลายวิธีดังนี้
- ใช้เฉพาะปีและเดือน
val exp2 =
time.currentDate.yearMonth.between(
YearMonth.of(2024, Month.OCTOBER),
YearMonth.of(2026, Month.JANUARY),
)
- ใช้เฉพาะเดือนและวัน
val exp2 =
time.currentDate.monthDay.between(
MonthDay.of(Month.OCTOBER, 1),
MonthDay.of(Month.DECEMBER, 15),
)
- ใช้เฉพาะวันของเดือน
val exp2 = time.currentDate.day.between(1, 15)
เท่ากับ
ประเมินเป็น true เมื่อนิพจน์ 1 เท่ากับนิพจน์ 2
| นิพจน์ 1 | นิพจน์ 2 | ผลลัพธ์ |
|---|---|---|
6 |
1 |
false |
2 |
2 |
true |
ตัวอย่าง DSL
washer.operationalState equals STOPPED
greaterThan
ประเมินเป็น true เมื่อนิพจน์ 1 มากกว่านิพจน์ 2
| นิพจน์ 1 | นิพจน์ 2 | ผลลัพธ์ |
|---|---|---|
6 |
1 |
true |
1 |
6 |
false |
ตัวอย่าง DSL
( blindsPosition.currentPositionLift greaterThan 0u )
greaterThanOrEquals
ประเมินเป็น true เมื่อนิพจน์ 1 มากกว่าหรือเท่ากับนิพจน์ 2
| นิพจน์ 1 | นิพจน์ 2 | ผลลัพธ์ |
|---|---|---|
8 |
6 |
true |
6 |
6 |
true |
1 |
6 |
false |
ตัวอย่าง DSL
( starterNode.measuredValue greaterThanOrEquals 50 )
lessThan
ประเมินเป็น true เมื่อนิพจน์ 1 น้อยกว่านิพจน์ 2
| นิพจน์ 1 | นิพจน์ 2 | ผลลัพธ์ |
|---|---|---|
6 |
1 |
false |
1 |
6 |
true |
ตัวอย่าง DSL
time.currentTime lessThan LocalTime.of(22,0,0,0)
lessThanOrEquals
ประเมินเป็น true เมื่อนิพจน์ 1 น้อยกว่าหรือเท่ากับนิพจน์ 2
| นิพจน์ 1 | นิพจน์ 2 | ผลลัพธ์ |
|---|---|---|
8 |
6 |
false |
6 |
6 |
true |
1 |
6 |
true |
ตัวอย่าง DSL
( starterNode.measuredValue lessThanOrEquals 25 )
notEquals
ประเมินเป็น true เมื่อนิพจน์ 1 ไม่เท่ากับนิพจน์ 2
| นิพจน์ 1 | นิพจน์ 2 | ผลลัพธ์ |
|---|---|---|
6 |
1 |
true |
1 |
6 |
true |
2 |
2 |
false |
ตัวอย่าง DSL
occupancyStateChange.occupied notEquals 0
โอเปอเรเตอร์ทางคณิตศาสตร์
เพิ่ม
โอเปอเรเตอร์การบวก ( + )
ตัวอย่าง DSL
var totalCount = 0
...
totalCount = totalCount + 1
ลบ
โอเปอเรเตอร์การลบ ( - )
ตัวอย่าง DSL
var countdown = 10
...
countdown = countdown - 1
คูณ
โอเปอเรเตอร์การคูณ ( * )
ตัวอย่าง DSL
val millis = seconds * 1000
หาร
โอเปอเรเตอร์การหาร ( / )
ตัวอย่าง DSL
val rpm = revolutions / minutes
โอเปอเรเตอร์แบบลอจิคัล
และ
รวม 2 นิพจน์ไว้ในนิพจน์ AND แบบลอจิคัล โดยประเมินเป็น true เมื่อทั้ง 2 นิพจน์เป็น true
| นิพจน์ 1 | นิพจน์ 2 | ผลลัพธ์ |
|---|---|---|
false |
false |
false |
true |
false |
false |
false |
true |
false |
true |
true |
true |
ตัวอย่าง DSL
((device.occupied notEquals 0) and
time.currentTime.between(time.sunriseTime, time.sunsetTime))
ไม่ใช่
แสดงผลค่าตรรกะของนิพจน์แบบกลับกัน
| นิพจน์ | ผลลัพธ์ |
|---|---|
true |
false |
false |
true |
ตัวอย่าง DSL
time.currentTime not (between(time.sunriseTime, time.sunsetTime))
หรือ
รวม 2 นิพจน์ไว้ในนิพจน์ OR แบบลอจิคัล
| นิพจน์ 1 | นิพจน์ 2 | ผลลัพธ์ |
|---|---|---|
false |
false |
false |
true |
false |
true |
false |
true |
true |
ตัวอย่าง DSL
(time.currentTime equals LocalTime.of(10,0,0,0)) or
(time.currentTime equals LocalTime.of(22,0,0,0))