Android के लिए थर्मोस्टेट डिवाइस की गाइड

थर्मोस्टैट डिवाइस टाइप को Home API के कई ट्रैट का इस्तेमाल करके लागू किया जा सकता है. हालांकि, मुख्य ट्रैट Thermostat है. थर्मोस्टैट डिवाइसों के लिए ज़रूरी और वैकल्पिक विशेषताएं यहां दी गई हैं.

Home APIs डिवाइस टाइप विशेषताएं Kotlin सैंपल ऐप्लिकेशन इस्तेमाल का उदाहरण

थर्मोस्टैट

ThermostatDevice

home.matter.0000.types.0301

ऐसा डिवाइस जिसमें तापमान, नमी या जगह में मौजूद लोगों की संख्या के लिए, पहले से मौजूद या अलग सेंसर हो सकते हैं. साथ ही, इसमें तापमान को अपनी पसंद के मुताबिक सेट किया जा सकता है. थर्मोस्टैट, हीटिंग और/या कूलिंग की ज़रूरत से जुड़ी सूचनाएं, हीटिंग/कूलिंग यूनिट (उदाहरण के लिए, इनडोर एयर हैंडलर) को भेज सकता है. इसके अलावा, वह हीटिंग या कूलिंग यूनिट को सीधे तौर पर कंट्रोल करने की सुविधा भी दे सकता है.

ज़रूरी विशेषताएं
     matter Identify
     matter Thermostat

ज़रूरी नहीं हैं
     matter ThermostatUserInterfaceConfiguration
     google ExtendedThermostat
थर्मोस्टैट

Automation API से जुड़ी सहायता

ऑटोमेशन एपीआई में, थर्मोस्टैट के ये ट्रैट और एलिमेंट काम करते हैं.

विशेषता ट्रैट का टाइप तत्व प्रकार एलिमेंट
थर्मोस्टैट matter कमांड SetpointRaiseLower
थर्मोस्टैट matter एट्रिब्यूट activePresetHandle
थर्मोस्टैट matter एट्रिब्यूट localTemperature
थर्मोस्टैट matter एट्रिब्यूट बुकिंग की स्थिति
थर्मोस्टैट matter एट्रिब्यूट occupiedCoolingSetpoint
थर्मोस्टैट matter एट्रिब्यूट occupiedHeatingSetpoint
थर्मोस्टैट matter एट्रिब्यूट outdoorTemperature
थर्मोस्टैट matter एट्रिब्यूट setpointChangeSource
थर्मोस्टैट matter एट्रिब्यूट systemMode
थर्मोस्टैट matter एट्रिब्यूट temperatureSetpointHold
थर्मोस्टैट matter एट्रिब्यूट temperatureSetpointHoldDuration
थर्मोस्टैट matter एट्रिब्यूट thermostatRunningMode
थर्मोस्टैट matter एट्रिब्यूट thermostatRunningState
थर्मोस्टैट matter एट्रिब्यूट unoccupiedCoolingSetpoint
थर्मोस्टैट matter एट्रिब्यूट unoccupiedHeatingSetpoint
ExtendedThermostat google एट्रिब्यूट activePresetHandle
ExtendedThermostat google एट्रिब्यूट activeRemoteTemperatureSensorIds
ExtendedThermostat google एट्रिब्यूट averageLocalTemperature
ExtendedThermostat google एट्रिब्यूट extendedRunningMode
ExtendedThermostat google एट्रिब्यूट extendedSystemMode

आस-पास का तापमान जानना

थर्मोस्टैट का इस्तेमाल करके, आस-पास का तापमान देखना

Thermostat Thermostat एट्रिब्यूट का इस्तेमाल करके, थर्मोस्टैट के आस-पास के तापमान की जानकारी पाने के लिए, localTemperature एट्रिब्यूट को पढ़ें.

Device APIAutomation API
// Get the ambient temperature
val thermostat = home.devices().list().first { device -> device.has(Thermostat) }

val thermostatTraitFlow: Flow<Thermostat?> =
  thermostat
    .type(ThermostatDevice)
    .mapNotNull { it.standardTraits.thermostat }
    .distinctUntilChanged()

val localTempFlow = thermostatTraitFlow.mapNotNull { it?.localTemperature }
val automation = automation {
  sequential {
    val starterNode = starter<_>(thermostat, ThermostatDevice, Thermostat)

    // If the temperature is higher than 35C...
    condition { expression = starterNode.localTemperature greaterThan 35 }

    // ...and the automation hasn't been run for at least an hour...
    suppressFor(Duration.ofHours(1))

    // ...broadcast a message
    action(speaker, SpeakerDevice) {
      command(AssistantBroadcast.broadcast("It's very hot outside."))
    }
  }
}

TemperatureMeasurement का इस्तेमाल करके, आस-पास का तापमान पता करना

TemperatureMeasurement TemperatureMeasurement एट्रिब्यूट का इस्तेमाल करके, थर्मोस्टैट के आस-पास के तापमान की जानकारी पाने के लिए, measuredValue एट्रिब्यूट को पढ़ें.

Device APIAutomation API
val temperatureTraitFlow: Flow<TemperatureMeasurement?> =
  thermostat
    .type(TemperatureSensorDevice)
    .map { it.standardTraits.temperatureMeasurement }
    .distinctUntilChanged()

val localTemp: Short? = temperatureTraitFlow.first()?.measuredValue
val automation = automation {
  sequential {
    val temperature = starter<_>(thermostat, ThermostatDevice, TemperatureMeasurement)
    val stateReaderNode = stateReader<_>(light, DimmableLightDevice, OnOff)
    condition() {
      val expr1 = temperature.measuredValue greaterThanOrEquals 35
      val expr2 = stateReaderNode.onOff equals true
      expression = expr1 and expr2
    }
    action(light, DimmableLightDevice) { command(OnOff.on()) }
  }
}

ExtendedThermostat का इस्तेमाल करके, औसत तापमान का पता लगाना

एक से ज़्यादा सेंसर से मिले तापमान का औसत देखने के लिए, ExtendedThermostat averageLocalTemperature एट्रिब्यूट की वैल्यू देखें.

Device APIAutomation API
// Get the average temperature
val thermostat = home.devices().list().first { device -> device.has(TemperatureSensorDevice) }

val temperatureTraitFlow: Flow<TemperatureMeasurement?> =
  thermostat
    .type(TemperatureSensorDevice)
    .map { it.standardTraits.temperatureMeasurement }
    .distinctUntilChanged()

val localTemp: Short? = temperatureTraitFlow.first()?.measuredValue
val automation = automation {
  sequential {
    val temperature = starter<_>(thermostat, ThermostatDevice, ExtendedThermostat)
    val stateReaderNode = stateReader<_>(light, DimmableLightDevice, OnOff)
    //  if the average temperature is >= 35C
    condition() {
      val expr1 = temperature.averageLocalTemperature greaterThanOrEquals 35
      val expr2 = stateReaderNode.onOff equals true
      expression = expr1 and expr2
    }
    // Turn on the light
    action(light, DimmableLightDevice) { command(OnOff.on()) }
  }
}

आस-पास की नमी का पता लगाना

RelativeHumidityMeasurement विशेषता का इस्तेमाल करके, थर्मोस्टैट के आस-पास की आर्द्रता का पता लगाने के लिए, measuredValue एट्रिब्यूट पढ़ें.

Device APIAutomation API
// Get the ambient humidity

val humidityTraitFlow: Flow<RelativeHumidityMeasurement?> =
  humiditySensingThermostat
    .type(HumiditySensorDevice)
    .map { it.standardTraits.relativeHumidityMeasurement }
    .distinctUntilChanged()

val localHumidity: UShort? = humidityTraitFlow.first()?.measuredValue
val automation = automation {
  sequential {
    val humidity = starter<_>(thermostat, HumiditySensorDevice, RelativeHumidityMeasurement)
    val stateReaderNode = stateReader<_>(light, DimmableLightDevice, OnOff)
    // if the ambient humidity is >= 80%
    condition() {
      val expr1 = (humidity.measuredValue greaterThanOrEquals 80u)
      val expr2 = (stateReaderNode.onOff equals true)
      expression = expr1 and expr2
    }
    // Turn on the light
    action(light, DimmableLightDevice) { command(OnOff.on()) }
  }
}

तापमान का दिखाया गया स्केल चुनना

थर्मोस्टैट डिसप्ले के लिए इस्तेमाल होने वाली तापमान की यूनिट बदलने के लिए, ThermostatUserInterfaceConfigurationTrait के temperatureDisplayMode एट्रिब्यूट की वैल्यू को TemperatureDisplayModeEnum.Celsius या TemperatureDisplayModeEnum.Fahrenheit पर सेट करें.

Device APIAutomation API
// Set the displayed temperature scale to Fahrenheit
val uiConfig =
  home
    .devices()
    .list()
    .filter { device -> device.has(ThermostatUserInterfaceConfiguration) }
    .first()

val uiConfigTraitFlow: Flow<ThermostatUserInterfaceConfiguration?> =
  uiConfig
    .type(ThermostatDevice)
    .map { it.standardTraits.thermostatUserInterfaceConfiguration }
    .distinctUntilChanged()

val uiConfigTrait: ThermostatUserInterfaceConfiguration = uiConfigTraitFlow.first()!!

if (
  uiConfigTrait.supports(ThermostatUserInterfaceConfiguration.Attribute.temperatureDisplayMode)
) {
  val unused =
    uiConfigTrait.update { setTemperatureDisplayMode(TemperatureDisplayModeEnum.Fahrenheit) }
}
val automation = automation {
  isActive = true
  sequential {
    val stateReaderNode =
      stateReader<_>(thermostat, ThermostatDevice, ThermostatUserInterfaceConfiguration)

    // When someone says "Show the temperature in Fahrenheit",
    val unused =
      starter<_>(structure, VoiceStarter.OkGoogleEvent) {
        parameter(VoiceStarter.OkGoogleEvent.query("Show the temperature in Fahrenheit"))
      }
    // if the temperature isn't being shown in Fahrenheit
    condition() {
      expression =
        stateReaderNode.temperatureDisplayMode notEquals TemperatureDisplayModeEnum.Fahrenheit
    }
    // display the current temperature using Fahrenheit
    action(thermostat, ThermostatDevice) {
      update(ThermostatUserInterfaceConfiguration) {
        setTemperatureDisplayMode(TemperatureDisplayModeEnum.Fahrenheit)
      }
    }
  }
}

ऑपरेटिंग मोड बदलना

थर्मोस्टैट को कुछ ऑपरेटिंग मोड तक सीमित किया जा सकता है. ये मोड, ThermostatTrait.SystemModeEnum से तय किए जाते हैं. इसके लिए, ThermostatTrait.Attributes.systemMode एट्रिब्यूट को सेट करें. इसकी वैल्यू, ThermostatTrait.Attributes.SystemModeEnum से तय की जाती हैं.

Device APIAutomation API
val thermostatDevice = structure.devices().list().first { device -> device.has(Thermostat) }

val thermostatTraitFlow: Flow<Thermostat?> =
  thermostat.type(ThermostatDevice).map { it.standardTraits.thermostat }.distinctUntilChanged()

val thermostatTrait: Thermostat = thermostatTraitFlow.first()!!

// Set the system mode to Auto
if (thermostatTrait.supports(Thermostat.Attribute.systemMode)) {
  val unused = thermostatTrait.update { setSystemMode(SystemModeEnum.Auto) }
}
val automation = automation {
  isActive = true
  // When the door lock state changes
  sequential {
    val doorLockEvent = starter<_>(doorLock, DoorLockDevice, LockOperationEvent)
    val stateReaderNode = stateReader<_>(thermostat, ThermostatDevice, SimplifiedThermostat)

    // if the door is unlocked and the thermostat is in Eco mode
    condition() {
      val expr1 = (doorLockEvent.lockOperationType equals LockOperationTypeEnum.Unlock)
      val expr2 = (stateReaderNode.systemMode equals SimplifiedThermostatSystemModeEnum.Eco)
      expression = expr1 and expr2
    }

    // Set the thermostat to Auto mode
    action(thermostat, ThermostatDevice) {
      command(SimplifiedThermostat.setSystemMode(SimplifiedThermostatSystemModeEnum.Auto))
    }
  }
}

जब थर्मोस्टैट को SystemModeEnum.Auto पर सेट किया जाता है, तो थर्मोस्टैट के चालू मोड के बारे में ज़्यादा जानकारी ThermostatTrait.Attributes.thermostatRunningMode से पढ़ी जा सकती है. इसमें ThermostatRunningModeEnum की वैल्यू अपने-आप भर जाती हैं.

Device APIAutomation API
// Get the current thermostat running mode

val runningModeTraitFlow: Flow<Thermostat?> =
  thermostat.type(ThermostatDevice).map { it.standardTraits.thermostat }.distinctUntilChanged()

val runningMode: ThermostatTrait.ThermostatRunningModeEnum? =
  runningModeTraitFlow.first()?.thermostatRunningMode
val automation = automation {
  isActive = true
  sequential {
    val stateReaderNode = stateReader<_>(thermostat, ThermostatDevice, Thermostat)
    // at 10:00am
    val unused =
      starter<_>(structure, Time.ScheduledTimeEvent) {
        parameter(Time.ScheduledTimeEvent.clockTime(LocalTime.of(10, 0, 0, 0)))
      }

    // if the thermostat is in Auto mode and is currently cooling
    condition() {
      val expr1 = (stateReaderNode.systemMode equals ThermostatTrait.SystemModeEnum.Auto)
      val expr2 =
        (stateReaderNode.thermostatRunningMode equals
          ThermostatTrait.ThermostatRunningModeEnum.Cool)
      expression = expr1 and expr2
    }
    // announce that it's in Cool mode
    action(structure) {
      command(AssistantBroadcast.broadcast("The thermostat is currently running in Cool mode."))
    }
  }
}

SimplifiedThermostatTrait को ऑटोमेशन में ऑपरेटिंग मोड सेट करने की प्रोसेस को आसान बनाने के लिए डिज़ाइन किया गया है. SimplifiedThermostatTrait का इस्तेमाल करके, थर्मोस्टैट के ऑपरेटिंग मोड को बदलने के लिए, SetSystemModeCommand का इस्तेमाल करें. इसकी वैल्यू, SimplifiedThermostatTrait.SystemModeEnum से तय की जाती हैं.

यह ट्रैट सिर्फ़ Automation API के साथ इस्तेमाल करने के लिए उपलब्ध है.

Automation API
val automation = automation {
  isActive = true

  sequential {
    // When the presence state changes...
    val starterNode = starter<_>(structure, AreaPresenceState)
    // ...and if the area is unoccupied...
    condition() {
      expression = starterNode.presenceState equals PresenceState.PresenceStateVacant
    }
    // Set the thermostat to Eco mode
    action(thermostat, ThermostatDevice) {
      command(SimplifiedThermostat.setSystemMode(SimplifiedThermostatSystemModeEnum.Eco))
    }
  }
}

थर्मोस्टैट के काम करने के सिस्टम मोड जानने के लिए, ThermostatTrait.Attributes.controlSequenceOfOperation को पढ़ें. इसकी वैल्यू, ThermostatTrait.ControlSequenceOfOperationEnum से तय होती हैं.

Device APIAutomation API
// Get the controlSequenceOfOperation
val standardTraitFlow: Flow<Thermostat?> =
  thermostat.type(ThermostatDevice).map { it.standardTraits.thermostat }.distinctUntilChanged()

val controlSequenceOfOperation: ThermostatTrait.ControlSequenceOfOperationEnum? =
  standardTraitFlow.first()?.controlSequenceOfOperation
val automation = automation {
  isActive = true
  sequential {
    val stateReaderNode = stateReader<_>(thermostat, ThermostatDevice, Thermostat)
    // When someone says "Switch to cool mode",
    val unused =
      starter<_>(structure, VoiceStarter.OkGoogleEvent) {
        parameter(VoiceStarter.OkGoogleEvent.query("Switch to cool mode"))
      }
    // if the thermostat is capable of operating in Cool mode,
    condition() {
      val expr1 =
        stateReaderNode.controlSequenceOfOperation notEquals
          ControlSequenceOfOperationEnum.HeatingOnly
      val expr2 =
        stateReaderNode.controlSequenceOfOperation notEquals
          ControlSequenceOfOperationEnum.HeatingWithReheat
      expression = expr1 and expr2
    }

    action(thermostat, ThermostatDevice) {
      // switch to Cool mode
      update(SimplifiedThermostat) {
        command(SimplifiedThermostat.setSystemMode(SimplifiedThermostatSystemModeEnum.Cool))
      }
    }
  }
}

प्रोग्रामिंग के ऑपरेशन मोड में बदलाव करना

Thermostat के thermostatProgrammingOperationMode का इस्तेमाल करके, थर्मोस्टैट के प्रोग्रामिंग ऑपरेशन मोड को बदला जा सकता है. इसकी वैल्यू, ProgrammingOperationModeBitmap से तय की जाती हैं.

Device APIAutomation API
val thermostatTraitFlow: Flow<Thermostat?> =
  thermostat.type(ThermostatDevice).map { it.standardTraits.thermostat }.distinctUntilChanged()

val thermostatTrait: Thermostat = thermostatTraitFlow.first()!!

if (thermostatTrait.supports(Thermostat.Attribute.thermostatProgrammingOperationMode)) {
  val programmingOperationMode = thermostatTrait.thermostatProgrammingOperationMode!!

  // Enable autoRecovery on the thermostatProgrammingOperationMode
  val unused =
    thermostatTrait.update {
      setThermostatProgrammingOperationMode(
        ThermostatTrait.ProgrammingOperationModeBitmap(
          programmingOperationMode.scheduleActive,
          true,
          programmingOperationMode.economy,
        )
      )
    }
}
// When someone says "Reset programming operation mode"
val automation = automation {
  isActive = true
  sequential {
    val unused =
      starter<_>(structure, VoiceStarter.OkGoogleEvent) {
        parameter(VoiceStarter.OkGoogleEvent.query("Reset programming operation mode"))
      }
    // Set all the flags on the programming operation mode
    action(thermostat, ThermostatDevice) {
      update(Thermostat) {
        setThermostatProgrammingOperationMode(ProgrammingOperationModeBitmap(true, true, true))
      }
    }
  }
}

सेट किया गया तापमान बदलना

Thermostat का इस्तेमाल करके, सेट किया गया तापमान बदलने के लिए, ThermostatTrait.SetpointRaiseLowerCommand को कॉल करें.

Device APIAutomation API
val thermostatTraitFlow: Flow<Thermostat?> =
  thermostat.type(ThermostatDevice).map { it.standardTraits.thermostat }.distinctUntilChanged()

val thermostatTrait: Thermostat = thermostatTraitFlow.first()!!

// lower the temperature setpoint by 1 degree C
thermostatTrait.setpointRaiseLower(amount = 1, mode = SetpointRaiseLowerModeEnum.Cool)
val automation = automation {
  isActive = true
  sequential {
    val stateReaderNode = stateReader<_>(thermostat, ThermostatDevice, Thermostat)
    // At 10:00pm
    val unused =
      starter<_>(structure, Time.ScheduledTimeEvent) {
        parameter(Time.ScheduledTimeEvent.clockTime(LocalTime.of(22, 0, 0, 0)))
      }
    // if the setpoint is warmer than 19C
    condition() { expression = stateReaderNode.occupiedCoolingSetpoint greaterThan 19 }

    // lower the temperature setpoint by 5 degrees
    action(thermostat, ThermostatDevice) {
      command(Thermostat.setpointRaiseLower(SetpointRaiseLowerModeEnum.Cool, 5))
    }
  }
}

सेट किए गए तापमान को प्राथमिकता देना

पहले से प्रोग्राम किए गए शेड्यूल के बजाय, तापमान के सेटपॉइंट को प्राथमिकता दी जा सकती है. इसके लिए, ThermostatTrait के temperatureSetpointHold एट्रिब्यूट को TemperatureSetpointHoldEnum.SetpointHoldOn पर सेट करें. इसके अलावा, शेड्यूल को प्राथमिकता देने के लिए, उसे TemperatureSetpointHoldEnum.SetpointHoldOff पर सेट करें.

Device APIAutomation API
val thermostatTraitFlow: Flow<Thermostat?> =
  thermostat.type(ThermostatDevice).map { it.standardTraits.thermostat }.distinctUntilChanged()

val thermostatTrait: Thermostat = thermostatTraitFlow.first()!!

if (thermostatTrait.supports(Thermostat.Attribute.temperatureSetpointHold)) {
  // Set temperatureSetpointHold to SetpointHoldOn
  // allowing temperature setpoints to override any preprogrammed schedules.

  val unused =
    thermostatTrait.update {
      setTemperatureSetpointHold(TemperatureSetpointHoldEnum.SetpointHoldOn)
    }
val automation = automation {
  isActive = true
  sequential {

    // When someone says "Prioritize thermostat setpoint"
    val unused =
      starter<_>(structure, VoiceStarter.OkGoogleEvent) {
        parameter(VoiceStarter.OkGoogleEvent.query("Prioritize thermostat setpoint"))
      }
    // make temperature setpoints override any preprogrammed schedules.
    action(thermostat, ThermostatDevice) {
      val unused2 =
        update(Thermostat) {
          setTemperatureSetpointHold(TemperatureSetpointHoldEnum.SetpointHoldOn)
        }
    }
  }

सेटपॉइंट होल्ड कितने मिनट तक चालू रहेगा, यह कंट्रोल करने के लिए ThermostatTrait.Attributes.temperatureSetpointHoldDuration सेट करें.

Device APIAutomation API
val thermostatTraitFlow: Flow<Thermostat?> =
  thermostat.type(ThermostatDevice).map { it.standardTraits.thermostat }.distinctUntilChanged()

val thermostatTrait: Thermostat = thermostatTraitFlow.first()!!

if (thermostatTrait.supports(Thermostat.Attribute.temperatureSetpointHoldDuration)) {
  // Set the setpoint hold duration to 60 minutes
  val unused = thermostatTrait.update { setTemperatureSetpointHoldDuration(60u) }
}
val automation = automation {
  isActive = true
  sequential {
    val stateReaderNode = stateReader<_>(thermostat, ThermostatDevice, Thermostat)
    val unused = starter<_>(thermostat, ThermostatDevice, Thermostat)

    // if the temperature setpoint hold duration is less than 60 minutes...
    condition() { expression = stateReaderNode.temperatureSetpointHoldDuration.lessThan(60u) }

    // ...and the automation hasn't been run for at least 24 hours...
    suppressFor(Duration.ofHours(24))

    // ...set the temperature setpoint hold duration to 60 minutes
    action(thermostat, ThermostatDevice) {
      val unused2 = update(Thermostat) { setTemperatureSetpointHoldDuration(60u) }
    }
  }
}

तापमान के सेटपॉइंट को होल्ड करने की नीति बदलने के लिए, ThermostatTrait.SetTemperatureSetpointHoldPolicyCommand को कॉल करें. इससे यह तय होता है कि थर्मोस्टैट की होल्ड की स्थिति कब और कैसे खत्म होगी.

मान्य वैल्यू, TemperatureSetpointHoldPolicyBitmap से तय होती हैं.

Device API
val thermostatTraitFlow: Flow<Thermostat?> =
  thermostat.type(ThermostatDevice).map { it.standardTraits.thermostat }.distinctUntilChanged()

val thermostatTrait: Thermostat = thermostatTraitFlow.first()!!
if (thermostatTrait.supports(Thermostat.Attribute.temperatureSetpointHoldPolicy)) {

  // Set the temperature setpoint hold policy to holdDurationElapsedOrPresetChanged
  val unused =
    thermostatTrait.setTemperatureSetpointHoldPolicy(
      ThermostatTrait.TemperatureSetpointHoldPolicyBitmap(
        holdDurationElapsed = false,
        holdDurationElapsedOrPresetChanged = true,
      )
    )
}

val automation = automation {
  isActive = true
  sequential {

    // When someone says "Set my preferred hold duration",
    val unused =
      starter<_>(structure, VoiceStarter.OkGoogleEvent) {
        parameter(VoiceStarter.OkGoogleEvent.query("Set my preferred hold duration"))
      }

    // set the temperature setpoint hold policy to holdDurationElapsedOrPresetChanged
    action(thermostat, ThermostatDevice) {
      command(
        Thermostat.setTemperatureSetpointHoldPolicy(
          TemperatureSetpointHoldPolicyBitmap(
            holdDurationElapsed = false,
            holdDurationElapsedOrPresetChanged = true,
          )
        )
      )
    }
  }
}