অটোমেশনের উদাহরণ

অন্য ডিভাইস চালু বা বন্ধ হলে একটি ডিভাইস চালু করুন

import com.google.home.Home
import com.google.home.HomeDevice
import com.google.home.HomeManager
import com.google.home.Id
import com.google.home.Structure
import com.google.home.automation.Action
import com.google.home.automation.Automation
import com.google.home.automation.Condition
import com.google.home.automation.Equals
import com.google.home.automation.Node
import com.google.home.automation.SequentialFlow
import com.google.home.automation.Starter
import com.google.home.matter.standard.OnOff
import com.google.home.matter.standard.OnOffLightDevice

...

automation {
  sequential {
    val starterNode = starter<_>(device1, OnOffLightDevice, OnOff)
    val device2State = stateReader<_>(device2, OnOffLightDevice, OnOff)
    condition {
      // Only send the command if device2 is off
      expression = device2State.onOff equals false
    }
   // turn on device 2
   action(device2, OnOffLightDevice) { command(OnOff.on()) }
   }
}

খুব উজ্জ্বল হলে অন্ধকে বন্ধ করুন

import com.google.home.Home
import com.google.home.HomeDevice
import com.google.home.HomeManager
import com.google.home.Id
import com.google.home.Structure
import com.google.home.automation.Action
import com.google.home.automation.And
import com.google.home.automation.Automation
import com.google.home.automation.Condition
import com.google.home.automation.Equals
import com.google.home.automation.Node
import com.google.home.automation.SequentialFlow
import com.google.home.automation.Starter
import com.google.home.automation.StateReader
import com.google.home.matter.standard.IlluminanceMeasurement
import com.google.home.matter.standard.IlluminanceMeasurement.measuredValue
import com.google.home.matter.standard.LightSensorDevice
import com.google.home.matter.standard.WindowCovering
import com.google.home.matter.standard.WindowCovering.currentPositionLift

...

automation {
  sequential {
    val starterNode = starter<_>(device1,
                              LightSensorDevice,
                              IlluminanceMeasurement)
    val blindsPosition = stateReader<_>(blinds, WindowCoveringDevice, WindowCovering)

    condition {
      // only send the command if
      // the blinds are open
      ( blindsPosition.currentPositionLift greaterThan 0u ) and
      // it's brighter than a certain threshold value
      ( starterNode.measuredValue greaterThan 0xAAFF )
    }
    // close the blind
    action(blinds, WindowCoveringDevice) { command(WindowCovering.downOrClose()) }
   }
}

তাপমাত্রা একটি থ্রেশহোল্ড ছাড়িয়ে গেলে ফ্যানটি চালু করুন

import com.google.home.Home
import com.google.home.HomeDevice
import com.google.home.HomeManager
import com.google.home.Id
import com.google.home.Structure
import com.google.home.automation.Action
import com.google.home.automation.And
import com.google.home.automation.Automation
import com.google.home.automation.Condition
import com.google.home.automation.Equals
import com.google.home.automation.Node
import com.google.home.automation.SequentialFlow
import com.google.home.automation.Starter
import com.google.home.automation.StateReader
import com.google.home.matter.standard.FanDevice
import com.google.home.matter.standard.OnOff
import com.google.home.matter.standard.OnOffTrait.Attributes.onOff
import com.google.home.matter.standard.TemperatureMeasurement
import com.google.home.matter.standard.TemperatureMeasurement.measuredValue
import com.google.home.matter.standard.TemperatureSensorDevice

...

automation {
  sequential {
    val starterNode = starter<_>(thermometer,
                               TemperatureSensorDevice,
                               TemperatureMeasurement)

    val fanStateReaderNode = stateReader<_>(fan, FanDevice, OnOff)
    condition {
      // only send the command if the temperature is above 78F
      (starterNode.measuredValue greaterThan 78) and
      // the fan is off
       fanStateReaderNode.onOff equals false
     }
     // turn on the fan
    action(fan, FanDevice) { command(OnOff.on()) }
   }
}

আলো সক্রিয় করুন এবং গতি সনাক্ত করা হলে একটি সতর্কতা শব্দ করুন

import com.google.home.Home
import com.google.home.HomeDevice
import com.google.home.HomeManager
import com.google.home.Id
import com.google.home.Structure
import com.google.home.automation.Action
import com.google.home.automation.Automation
import com.google.home.automation.Condition
import com.google.home.automation.Equals
import com.google.home.automation.Node
import com.google.home.automation.ParallelFlow
import com.google.home.automation.SequentialFlow
import com.google.home.automation.Starter
import com.google.home.automation.StateReader
import com.google.home.google.AssistantBroadcast
import com.google.home.google.MotionDetection
import com.google.home.matter.standard.OccupancySensor
import com.google.home.matter.standard.OnOff
import com.google.home.matter.standard.OnOffTrait.Attributes.onOff
import com.google.home.matter.standard.OnOffLightDevice
import com.google.home.matter.standard.SpeakerDevice
import java.time.Duration

...

automation {
  sequential {
    val starterNode = starter<_>(device, OccupancySensorDevice, MotionDetection)
    // only proceed if there is currently motion taking place
    condition { starterNode.motionDetectionEventInProgress equals true }
    // ignore the starter for one minute after it was last triggered
    suppressFor(Duration.ofMinutes(1))
    // make three announcements three seconds apart
    action(device, SpeakerDevice) {
        command(AssistantBroadcast.broadcast("Intruder detected!"))
    }
    delayFor(Duration.ofSeconds(3))
    action(device, SpeakerDevice) {
        command(AssistantBroadcast.broadcast("Intruder detected!"))
    }
    delayFor(Duration.ofSeconds(3))
    action(device, SpeakerDevice) {
        command(AssistantBroadcast.broadcast("Intruder detected!"))
    }
    // flash lights every two seconds
    action(light, OnOffLightDevice) { command(OnOff.toggle()) }
    delayFor(Duration.ofSeconds(2))
    action(light, OnOffLightDevice) { command(OnOff.toggle()) }
    delayFor(Duration.ofSeconds(2))
    action(light, OnOffLightDevice) { command(OnOff.toggle()) }
    delayFor(Duration.ofSeconds(2))
    action(light, OnOffLightDevice) { command(OnOff.toggle()) }
    delayFor(Duration.ofSeconds(2))
    action(light, OnOffLightDevice) { command(OnOff.toggle()) }
    delayFor(Duration.ofSeconds(2))
    action(light, OnOffLightDevice) { command(OnOff.toggle()) }

  }
}

সূর্যোদয়ের 15 মিনিট আগে খড়খড়ি খুলুন

import com.google.home.Home
import com.google.home.HomeDevice
import com.google.home.HomeManager
import com.google.home.Id
import com.google.home.Structure
import com.google.home.automation.Action
import com.google.home.automation.And
import com.google.home.automation.Automation
import com.google.home.automation.Condition
import com.google.home.automation.Equals
import com.google.home.automation.LessThanOrEquals
import com.google.home.automation.ManualStarter
import com.google.home.automation.Node
import com.google.home.automation.SequentialFlow
import com.google.home.automation.Starter
import com.google.home.automation.StateReader
import com.google.home.google.Time
import com.google.home.google.Time.sunriseTime
import com.google.home.matter.standard.WindowCovering
import java.time.Duration
import java.time.LocalTime

...

automation {
  sequential {
    // 15 minutes before sunrise
    val unused =
      starter<_>(structure, Time.ScheduledTimeEvent) {
        parameter(Time.ScheduledTimeEvent.solarTime(
          SolarTimeStruct(SolarTimeType.Sunrise,
                          java.time.Duration.ofMinutes(-15))))
      }
    }
    sequential {
      manualStarter()
    }
    // simultaneously open the five blinds
    parallel {
      action(blind1, WindowCovering) { command(WindowCovering.upOrOpen()) }
      action(blind2, WindowCovering) { command(WindowCovering.upOrOpen()) }
      action(blind3, WindowCovering) { command(WindowCovering.upOrOpen()) }
      action(blind4, WindowCovering) { command(WindowCovering.upOrOpen()) }
      action(blind5, WindowCovering) { command(WindowCovering.upOrOpen()) }
    }
  }
}

খুব উজ্জ্বল এবং/অথবা খুব গরম না হলে সকাল 7:00টায় ব্লাইন্ডগুলি খুলুন

মনে রাখবেন যে এই উদাহরণটি Time.ScheduledTimeEvent ব্যবহার করে, যার জন্য Google Home app (GHA) ব্যবহার করে কাঠামোটিকে একটি ঠিকানা বরাদ্দ করা প্রয়োজন।

import com.google.home.Home
import com.google.home.HomeDevice
import com.google.home.HomeManager
import com.google.home.Id
import com.google.home.Structure
import com.google.home.automation.Action
import com.google.home.automation.And
import com.google.home.automation.Automation
import com.google.home.automation.Condition
import com.google.home.automation.Equals
import com.google.home.automation.LessThanOrEquals
import com.google.home.automation.ManualStarter
import com.google.home.automation.Node
import com.google.home.automation.SequentialFlow
import com.google.home.automation.Starter
import com.google.home.automation.StateReader
import com.google.home.google.Time
import com.google.home.matter.standard.IlluminanceMeasurement
import com.google.home.matter.standard.TemperatureMeasurement
import com.google.home.matter.standard.TemperatureMeasurement.measuredValue
import com.google.home.matter.standard.TemperatureSensorDevice
import com.google.home.matter.standard.WindowCovering
import java.time.Duration
import java.time.LocalTime

...

automation {
  sequential {
    select {
      sequential {
      // run the automation daily at 7am
        val earlyMorning =  starter<_>(structure, Time.ScheduledTimeEvent) {
          parameter(Time.ScheduledTimeEvent.clockTime(LocalTime.of(7, 0, 0, 0)))
        }
        val temperature = starter<_>(device, TemperatureSensorDevice, TemperatureMeasurement)
        val brightness = starter<_>(device1, IlluminanceMeasurement)
        // don't run more often than every 15 minutes
        suppressFor(Duration.ofMinutes(15))
        condition {
           // temperature is below 32C/90F
          (temperature.measuredValue lessThanOrEquals 32)
          or
          // too bright
          (brightness.measuredValue greaterThan 0xAAFF)
        }
      }
      sequential {
        manualStarter()
      }
    }
    // simultaneously open the five blinds
    parallel {
      action(blind1, WindowCovering) { command(WindowCovering.upOrOpen()) }
      action(blind2, WindowCovering) { command(WindowCovering.upOrOpen()) }
      action(blind3, WindowCovering) { command(WindowCovering.upOrOpen()) }
      action(blind4, WindowCovering) { command(WindowCovering.upOrOpen()) }
      action(blind5, WindowCovering) { command(WindowCovering.upOrOpen()) }
    }
  }
}

লাইট অন থাকলে ফ্যান বন্ধ করুন এবং স্পিড সেটিং পরিবর্তন করুন

import com.google.home.Home
import com.google.home.HomeClient
import com.google.home.HomeDevice
import com.google.home.HomeManager
import com.google.home.Id
import com.google.home.Structure
import com.google.home.automation.Action
import com.google.home.automation.Automation
import com.google.home.automation.Command
import com.google.home.automation.Condition
import com.google.home.automation.Equals
import com.google.home.automation.Node
import com.google.home.automation.SequentialFlow
import com.google.home.automation.Starter
import com.google.home.automation.StateReader
import com.google.home.automation.Update
import com.google.home.matter.standard.DimmableLightDevice
import com.google.home.matter.standard.FanControl
import com.google.home.matter.standard.FanControlTrait.FanModeEnum
import com.google.home.matter.standard.FanDevice
import com.google.home.matter.standard.OnOff
import com.google.home.matter.standard.OnOffTrait.Attributes.onOff

...

automation {
  name = "Turn off the fan when the light is turned on."
  description = "If light is on, turn off the fan and change the speed setting."
  isActive = true
  sequential {
    // When the light's OnOff state changes...
    val starterNode = starter<_>(device, DimmableLightDevice, OnOff)
    // ...and if the light is turned on...
    condition() {
      expression = starterNode.onOff equals true
    }
    // ...turn off the fan and change the speed.
    action(device, FanDevice) {
      update(FanControl) {
        setFanMode(FanModeEnum.Off)
        setPercentSetting(20u)
      }
    }
  }
}

এলাকা দখল হয়ে থাকলে আলো জ্বালিয়ে দিন

import com.google.home.Home
import com.google.home.HomeClient
import com.google.home.HomeDevice
import com.google.home.HomeManager
import com.google.home.Id
import com.google.home.Structure
import com.google.home.automation.Action
import com.google.home.automation.Automation
import com.google.home.automation.Command
import com.google.home.automation.Condition
import com.google.home.automation.Equals
import com.google.home.automation.Node
import com.google.home.automation.SequentialFlow
import com.google.home.automation.Starter
import com.google.home.automation.StateReader
import com.google.home.google.AreaPresenceState
import com.google.home.google.AreaPresenceState.PresenceStateOccupied
import com.google.home.google.AreaPresenceStateTrait.PresenceState
import com.google.home.matter.standard.DimmableLightDevice
import com.google.home.matter.standard.OnOff
import com.google.home.matter.standard.OnOffTrait.Attributes.onOff

...

automation {
  description = "If the area is occupied, turn the light on."
  isActive = true
  sequential {
    // If the presence state changes...
    val starterNode = starter<_>(structure, AreaPresenceState)
    // ...and if the area is occupied...
      condition() {
        expression =
          starterNode.presenceState equals
            AreaPresenceState.PresenceStateOccupied
      }
      // ...turn the light on.
    action(device, DimmableLightDevice) { command(OnOff.on()) }
  }
}

বাড়িতে কেউ না থাকলে আলো নিভিয়ে দিন

import com.google.home.Home
import com.google.home.HomeClient
import com.google.home.HomeDevice
import com.google.home.HomeManager
import com.google.home.Id
import com.google.home.Structure
import com.google.home.automation.Action
import com.google.home.automation.Automation
import com.google.home.automation.Command
import com.google.home.automation.Condition
import com.google.home.automation.Equals
import com.google.home.automation.Node
import com.google.home.automation.SequentialFlow
import com.google.home.automation.Starter
import com.google.home.automation.StateReader
import com.google.home.google.AreaAttendanceState
import com.google.home.google.AreaAttendanceStateTrait.AttendanceState
import com.google.home.matter.standard.DimmableLightDevice
import com.google.home.matter.standard.OnOff
import com.google.home.matter.standard.OnOffTrait.Attributes.onOff

...

automation {
  sequential {
    val starterNode = starter<_>(device, DimmableLightDevice, OnOff)
    val stateReaderNode = stateReader<_>(structure, AreaAttendanceState)

    condition() {
      val expr1 = starterNode.onOff equals true
      val expr2 =
        stateReaderNode.attendanceState equals
          AttendanceState.AttendanceStateNoHouseholdMembers
      // If the light is turned on and no one from the household is present
      expression = expr1 and expr2
    }
    // turn the light off
    action(device, DimmableLightDevice) { command(OnOff.off()) }
  }
}

একটি নির্দিষ্ট সময়ে একটি বিজ্ঞপ্তি পাঠান

মনে রাখবেন যে এই উদাহরণটি Time.ScheduledTimeEvent ব্যবহার করে, যার জন্য Google Home app (GHA) ব্যবহার করে কাঠামোটিকে একটি ঠিকানা বরাদ্দ করা প্রয়োজন।

import com.google.home.Home
import com.google.home.HomeClient
import com.google.home.HomeDevice
import com.google.home.HomeManager
import com.google.home.Id
import com.google.home.Structure
import com.google.home.automation.Action
import com.google.home.automation.Automation
import com.google.home.automation.Command
import com.google.home.automation.Condition
import com.google.home.automation.Equals
import com.google.home.automation.Node
import com.google.home.automation.SequentialFlow
import com.google.home.automation.Starter
import com.google.home.automation.StateReader
import com.google.home.google.Notification
import com.google.home.google.Time
import com.google.home.google.Time.ScheduledTimeEvent
import com.google.home.google.Time.ScheduledTimeEvent.clockTime
import java.time.LocalTime

...

automation {
  sequential {
    val email1 = "your.email@gmail.com"
    // If the time is 1:01:01:001
    val unused =
      starter<_>(structure, Time.ScheduledTimeEvent) {
        parameter(Time.ScheduledTimeEvent.clockTime(
          LocalTime.of(1, 1, 1, 1)))
      }
    action(structure) {
      // send a notification to the email list
      command(
        Notification.sendNotifications(
          "title",
          {
            body = "body"
          },
        )
      )
    }
  }
}

আলো জ্বললে একটি নির্দিষ্ট সময়ে একটি বার্তা সম্প্রচার করুন

মনে রাখবেন যে এই উদাহরণটি Time.ScheduledTimeEvent ব্যবহার করে, যার জন্য Google Home app (GHA) ব্যবহার করে কাঠামোটিকে একটি ঠিকানা বরাদ্দ করা প্রয়োজন।

import com.google.home.Home
import com.google.home.HomeClient
import com.google.home.HomeDevice
import com.google.home.HomeManager
import com.google.home.Id
import com.google.home.Structure
import com.google.home.automation.Action
import com.google.home.automation.Automation
import com.google.home.automation.Command
import com.google.home.automation.Condition
import com.google.home.automation.Equals
import com.google.home.automation.Node
import com.google.home.automation.SequentialFlow
import com.google.home.automation.Starter
import com.google.home.automation.StateReader
import com.google.home.google.AssistantBroadcast
import com.google.home.google.Time
import com.google.home.google.Time.ScheduledTimeEvent
import com.google.home.google.Time.ScheduledTimeEvent.clockTime
import com.google.home.matter.standard.DimmableLightDevice
import com.google.home.matter.standard.OnOff
import com.google.home.matter.standard.OnOffTrait.Attributes.onOff
import java.time.LocalTime

...

automation {
  sequential {
    // If the time is 12:00...
    val unused =
      starter<_>(structure, Time.ScheduledTimeEvent) {
        parameter(Time.ScheduledTimeEvent.clockTime(LocalTime.of(12, 0, 0, 0)))
      }

    val stateReaderNode = stateReader<_>(device, DimmableLightDevice, OnOff)
    // ...and the light is on...
    condition() { expression = stateReaderNode.onOff equals true }
    // ...broadcast a message over any devices that support Google Assistant.
    action(structure) {
      command(AssistantBroadcast.broadcast("It's midday."))
    }
  }
}

আলো জ্বললে একটি নির্দিষ্ট সময়ে সঙ্গীত বাজান

মনে রাখবেন যে এই উদাহরণটি Time.ScheduledTimeEvent ব্যবহার করে, যার জন্য Google Home app (GHA) ব্যবহার করে কাঠামোটিকে একটি ঠিকানা বরাদ্দ করা প্রয়োজন।

import com.google.home.Home
import com.google.home.HomeClient
import com.google.home.HomeDevice
import com.google.home.HomeManager
import com.google.home.Id
import com.google.home.Structure
import com.google.home.automation.Action
import com.google.home.automation.Automation
import com.google.home.automation.Command
import com.google.home.automation.Condition
import com.google.home.automation.Equals
import com.google.home.automation.Node
import com.google.home.automation.SequentialFlow
import com.google.home.automation.Starter
import com.google.home.automation.StateReader
import com.google.home.google.AssistantFulfillment
import com.google.home.google.Time
import com.google.home.google.Time.ScheduledTimeEvent
import com.google.home.google.Time.ScheduledTimeEvent.clockTime
import com.google.home.matter.standard.DimmableLightDevice
import com.google.home.matter.standard.SpeakerDevice
import com.google.home.matter.standard.OnOff
import com.google.home.matter.standard.OnOffTrait.Attributes.onOff
import java.time.LocalTime

...

automation {
  sequential {
    // When the time is 3:15pm...
    val unused =
      starter<_>(structure, Time.ScheduledTimeEvent) {
        parameter(Time.ScheduledTimeEvent.clockTime(LocalTime.of(15, 15, 0, 0)))
      }
    val stateReaderNode = stateReader<_>(device, DimmableLightDevice, OnOff)
    // ...and the light's OnOff state is on...
    condition() { expression = stateReaderNode.onOff equals true }
    // ...tell Google Assistant to play music
    action(device, SpeakerDevice) {
      command(AssistantFulfillment.okGoogle("Play some music"))
    }
  }
}