DSL operator reference

Operators allow you to check the value of trait attributes against specific values, compare them to one another, and to combine expressions used in condition nodes.

Operators are made available through the following import statements:

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

Comparison operators

between

Evaluates to true when the value of Expression 1 is between that of Expression 2 and Expression 3 (inclusive). Expressions are ranked differently depending on their data type. Simple data types such as numbers and strings are ranked the same way they are in Kotlin.

Example
Expression 1 Expression 2 Expression 3 Result
6 1 3 false
2 1 3 true

DSL example

val time = stateReader<_>(structure, Time)
condition() {
  expression = time.currentTime
     .between(
      time.sunsetTime,
      time.sunriseTime)
}

equals

Evaluates to true when the Expression 1 equals Expression 2.

Example
Expression 1 Expression 2 Result
6 1 false
2 2 true

DSL example

washer.operationalState equals STOPPED

greaterThan

Evaluates to true when the Expression 1 is greater than Expression 2.

Example
Expression 1 Expression 2 Result
6 1 true
1 6 false

DSL example

( blindsPosition.currentPositionLift greaterThan 0u )

greaterThanOrEquals

Evaluates to true when the Expression 1 is greater than or equal to Expression 2.

Example
Expression 1 Expression 2 Result
8 6 true
6 6 true
1 6 false

DSL example

( starterNode.measuredValue greaterThanOrEquals 50 )

lessThan

evaluates to true when the Expression 1 is less than Expression 2.

Example
Expression 1 Expression 2 Result
6 1 false
1 6 true

DSL example

time.currentTime lessThan LocalTime.of(22,0,0,0)

lessThanOrEquals

Evaluates to true when the Expression 1 is less than or equal to Expression 2.

Example
Expression 1 Expression 2 Result
8 6 false
6 6 true
1 6 true

DSL example

( starterNode.measuredValue lessThanOrEquals 25 )

notEquals

Evaluates to true when the Expression 1 is not equal to Expression 2.

Example
Expression 1 Expression 2 Result
6 1 true
1 6 true
2 2 false

DSL example

occupancyStateChange.occupied notEquals 0

Arithmetic operators

Add

The addition operator ( + ).

DSL example

var totalCount = 0
...
totalCount = totalCount + 1

Subtract

The subtraction operator ( - ).

DSL example

var countdown = 10
...
countdown = countdown - 1

Multiply

The multiplication operator ( * ).

DSL example

val millis = seconds * 1000

Divide

The division operator ( / ).

DSL example

val rpm = revolutions / minutes

Logical operators

and

Combines two expressions in a logical AND expression, evaluating to true when both expressions are true.

Example
Expression 1 Expression 2 Result
false false false
true false false
false true false
true true true

DSL example

((device.occupied notEquals 0) and
   time.currentTime.between(time.sunriseTime, time.sunsetTime))

not

Negates the logical value of an expression.

Example
Expression Result
true false
false true

DSL example

time.currentTime not (between(time.sunriseTime, time.sunsetTime))

or

Combines two expressions into a logical OR expression.

Example
Expression 1 Expression 2 Result
false false false
true false true
false true true

DSL example

(time.currentTime equals LocalTime.of(10,0,0,0)) or
  (time.currentTime equals LocalTime.of(22,0,0,0))