โอเปอเรเตอร์ช่วยให้คุณตรวจสอบค่าของแอตทริบิวต์ลักษณะเทียบกับค่าที่เฉพาะเจาะจง
เปรียบเทียบค่าเหล่านั้นกับค่าอื่นๆ และรวมนิพจน์ที่ใช้ในโหนด 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))