# OnOffTrait

    struct OnOffTrait

This trait provides an interface for turning devices on and off.
- `


  ### [supportedEventTypes](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV014supportedEventC0Say0aB3SDK0I0_pXpGvpZ)


  ` No supported events for `OnOffTrait`.

  #### Declaration

  Swift

      static let supportedEventTypes: [any Event.Type]

- `


  ### [supportedCommandTypes](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV016supportedCommandC0Say0aB3SDK0I0_pXpGvpZ)


  ` List of the commands that are supported by `OnOffTrait`.

  #### Declaration

  Swift

      static let supportedCommandTypes: [any Command.Type]

- `


  ### [identifier](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV10identifierSSvpZ)


  ` The trait identifier.

  #### Declaration

  Swift

      static let identifier: String

- `


  ### [metadata](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV8metadata0aB3SDK0G8MetadataVvp)


  ` Metadata about this `Trait`.

  #### Declaration

  Swift

      let metadata: TraitMetadata

- `


  ### [attributes](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV10attributesAE10AttributesVvp)


  ` List of attributes for the `OnOffTrait`.

  #### Declaration

  Swift

      let attributes: https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter.html.OnOffTrait.https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait/Attributes.html

- `


  ### [init(decoder:interactionProxy:metadata:)](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV7decoder16interactionProxy8metadataAE0aB3SDK0G7DecoderV_AI011InteractionJ0_pSgAI0G8MetadataVtKcfc)


  ` Creates a new Trait instance using data read from the given `TraitDecoder`.
  Throws
  `HomeError.parseError` when parsing fails.

  #### Declaration

  Swift

      init(decoder: TraitDecoder, interactionProxy: (any InteractionProxy)?, metadata: TraitMetadata) throws

  #### Parameters

  |---|---|
  | ` decoder ` | The raw data representing this Trait. |
  | ` interactionProxy ` | Proxy to the Interaction Client. |
  | ` metadata ` | Metadata about this Trait. |

- `


  ### [encode(with:)](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV6encode4withy0aB3SDK0G7EncoderC_tKF)


  ` Writes this object to the given `TraitEncoder`.
  Throws `HomeError.encodingFailed` if the data could not be encoded.

  #### Declaration

  Swift

      func encode(with encoder: TraitEncoder) throws

- `


  ### [forceRead()](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV9forceReadyyYaKF)


  ` This API provides the ability to invalidate state retrieved through subscriptions to the
  target device in the cases where state is not being reported correctly, either intentionally
  (e.g attributes in Matter traits with the "C" quality) or unintentionally due to poor
  implementations.

  When successful, this API will result in a forced read of the convening scope as specified by
  the sub-class and return the result through existing Trait subscriptions if present and
  active.

  This API is to be used sparingly as it can impact the performance and battery life of the
  target device. As such, this API may be throttled by the platform.
  Callers SHALL be prepared to deal with `HomeError`s thrown by this call.

  #### Declaration

  Swift

      func forceRead() async throws

- `


  ### [Attributes](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait/Attributes.html)


  ` Attributes for the `https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait.html`.

  #### Declaration

  Swift

      struct Attributes

- `


  ### [==(_:_:)](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV2eeoiySbAE_AEtFZ)


  ` Returns a Boolean value indicating whether two values are equal.

  Equality is the inverse of inequality. For any values `a` and `b`,
  `a == b` implies that `a != b` is `false`.

  #### Declaration

  Swift

      static func == (lhs: https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter.html.OnOffTrait, rhs: https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter.html.OnOffTrait) -> Bool

  #### Parameters

  |---|---|
  | ` lhs ` | A value to compare. |
  | ` rhs ` | Another value to compare. |

- `


  ### [hash(into:)](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV4hash4intoys6HasherVz_tF)


  ` Hashes the essential components of this value by feeding them into the
  given hasher.

  Implement this method to conform to the `Hashable` protocol. The
  components used for hashing must be the same as the components compared
  in your type's `==` operator implementation. Call `hasher.combine(_:)`
  with each of these components.
  Important

  In your implementation of `hash(into:)`,
  don't call `finalize()` on the `hasher` instance provided,
  or replace it with a different instance.
  Doing so may become a compile-time error in the future.

  #### Declaration

  Swift

      func hash(into hasher: inout Hasher)

- `


  ### [supportsOffCommand](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV08supportsF7CommandSbvp)


  ` Whether the device supports the `off` command for this trait.

  #### Declaration

  Swift

      var supportsOffCommand: Bool { get }

- `


  ### [off()](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV3offyyYaKF)


  ` Turn off the device, and set the `https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait/Attributes.html#/s:15GoogleHomeTypes6MatterO10OnOffTraitV10AttributesV02onF0SbSgvp` attribute to false.

  #### Declaration

  Swift

      func off() async throws

- `


  ### [offBatchable()](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV12offBatchable0aB3SDK0I7CommandVyytGyKF)


  ` The batchable version of off command above.
  See also
  off

  #### Declaration

  Swift

      func offBatchable() throws -> BatchableCommand<Void>

- `


  ### [supportsOnCommand](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV08supportsE7CommandSbvp)


  ` Whether the device supports the `on` command for this trait.

  #### Declaration

  Swift

      var supportsOnCommand: Bool { get }

- `


  ### [on()](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV2onyyYaKF)


  ` Turn on the device, and set the `https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait/Attributes.html#/s:15GoogleHomeTypes6MatterO10OnOffTraitV10AttributesV02onF0SbSgvp` attribute to true.

  #### Declaration

  Swift

      func on() async throws

- `


  ### [onBatchable()](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV11onBatchable0aB3SDK0I7CommandVyytGyKF)


  ` The batchable version of on command above.
  See also
  on

  #### Declaration

  Swift

      func onBatchable() throws -> BatchableCommand<Void>

- `


  ### [supportsToggleCommand](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV21supportsToggleCommandSbvp)


  ` Whether the device supports the `toggle` command for this trait.

  #### Declaration

  Swift

      var supportsToggleCommand: Bool { get }

- `


  ### [toggle()](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV6toggleyyYaKF)


  ` If the device is off, turn the device on and set the `https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait/Attributes.html#/s:15GoogleHomeTypes6MatterO10OnOffTraitV10AttributesV02onF0SbSgvp` attribute
  to `true`.
  If the device is on, turn the device off and set the `https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait/Attributes.html#/s:15GoogleHomeTypes6MatterO10OnOffTraitV10AttributesV02onF0SbSgvp` attribute
  to `false`.

  #### Declaration

  Swift

      func toggle() async throws

- `


  ### [toggleBatchable()](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV15toggleBatchable0aB3SDK0I7CommandVyytGyKF)


  ` The batchable version of toggle command above.
  See also
  toggle

  #### Declaration

  Swift

      func toggleBatchable() throws -> BatchableCommand<Void>

- `


  ### [supportsOffWithEffectCommand](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV08supportsF17WithEffectCommandSbvp)


  ` Whether the device supports the `offWithEffect` command for this trait.

  #### Declaration

  Swift

      var supportsOffWithEffectCommand: Bool { get }

- `


  ### [offWithEffect(effectIdentifier:effectVariant:)](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV13offWithEffect16effectIdentifier0K7VariantyAE0jL4EnumO_s5UInt8VtYaKF)


  ` Allow devices to be turned off using enhanced ways of fading.

  #### Declaration

  Swift

      func offWithEffect(effectIdentifier: https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter.html.OnOffTrait.https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait/EffectIdentifierEnum.html, effectVariant: UInt8) async throws

  #### Parameters

  |---|---|
  | ` effectIdentifier ` | The fading effect to use when turning the device off. Must be a value from \[OnOffTrait.EffectIdentifierEnum\]. |
  | ` effectVariant ` | Variant of the effect, indicated by the `effectIdentifier` parameter, that is triggered. This must be one of the values in \[OnOffTrait.DelayedAllOffEffectVariantEnum\] or \[OnOffTrait.DyingLightEffectVariantEnum\] that correspond to the effect specified for `effectIdentifier`. |

- `


  ### [offWithEffectBatchable(effectIdentifier:effectVariant:)](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV22offWithEffectBatchable16effectIdentifier0L7Variant0aB3SDK0K7CommandVyytGAE0jM4EnumO_s5UInt8VtKF)


  ` The batchable version of offWithEffect command above.
  See also
  offWithEffect

  #### Declaration

  Swift

      func offWithEffectBatchable(effectIdentifier: https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter.html.OnOffTrait.https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait/EffectIdentifierEnum.html, effectVariant: UInt8) throws -> BatchableCommand<Void>

- `


  ### [supportsOnWithRecallGlobalSceneCommand](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV08supportsE28WithRecallGlobalSceneCommandSbvp)


  ` Whether the device supports the `onWithRecallGlobalScene` command for this trait.

  #### Declaration

  Swift

      var supportsOnWithRecallGlobalSceneCommand: Bool { get }

- `


  ### [onWithRecallGlobalScene()](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV23onWithRecallGlobalSceneyyYaKF)


  ` Allow the recall of the settings (global scene) the device had when the device was turned off.
  This command is ignored if the `https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait/Attributes.html#/s:15GoogleHomeTypes6MatterO10OnOffTraitV10AttributesV18globalSceneControlSbSgvp` attribute is true.
  If the `globalSceneControl` attribute is false, the global scene is recalled, the
  `https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait/Attributes.html#/s:15GoogleHomeTypes6MatterO10OnOffTraitV10AttributesV02onF0SbSgvp` attribute is updated accordingly, and the `globalSceneControl`
  attribute is set to true.
  When this command is called, if the `https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait/Attributes.html#/s:15GoogleHomeTypes6MatterO10OnOffTraitV10AttributesV6onTimes6UInt16VSgvp` attribute is 0, then the
  `https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait/Attributes.html#/s:15GoogleHomeTypes6MatterO10OnOffTraitV10AttributesV11offWaitTimes6UInt16VSgvp` attribute is also set to 0.

  #### Declaration

  Swift

      func onWithRecallGlobalScene() async throws

- `


  ### [onWithRecallGlobalSceneBatchable()](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV32onWithRecallGlobalSceneBatchable0aB3SDK0M7CommandVyytGyKF)


  ` The batchable version of onWithRecallGlobalScene command above.
  See also
  onWithRecallGlobalScene

  #### Declaration

  Swift

      func onWithRecallGlobalSceneBatchable() throws -> BatchableCommand<Void>

- `


  ### [supportsOnWithTimedOffCommand](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV08supportse9WithTimedF7CommandSbvp)


  ` Whether the device supports the `onWithTimedOff` command for this trait.

  #### Declaration

  Swift

      var supportsOnWithTimedOffCommand: Bool { get }

- `


  ### [onWithTimedOff(onOffControl:onTime:offWaitTime:)](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV011onWithTimedF00hF7Control0H4Time07offWaitL0yAE0efK6BitmapV_s6UInt16VAMtYaKF)


  ` Allow the device to be turned on for a specific duration with a guarded off duration so that,
  should the device be subsequently turned off, further `OnWithTimedOff` commands received
  during this time are prevented from turning the devices back on.

  #### Declaration

  Swift

      func onWithTimedOff(onOffControl: https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter.html.OnOffTrait.https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait/OnOffControlBitmap.html, onTime: UInt16, offWaitTime: UInt16) async throws

  #### Parameters

  |---|---|
  | ` onOffControl ` | When set to `1`, the `onWithTimedOff` command will only be processed if the `onOff` attribute is `true`. When set to `0`, the `onWithTimedOff` command is always processed. |
  | ` onTime ` | The duration for which device is turned on. Sets the value of the `onTime` attribute. |
  | ` offWaitTime ` | The guarded off duration to set for the device. Sets the value of the `offWaitTime` attribute. |

- `


  ### [onWithTimedOffBatchable(onOffControl:onTime:offWaitTime:)](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait#/s:15GoogleHomeTypes6MatterO10OnOffTraitV011onWithTimedF9Batchable0hF7Control0H4Time07offWaitM00aB3SDK0K7CommandVyytGAE0efL6BitmapV_s6UInt16VAQtKF)


  ` The batchable version of onWithTimedOff command above.
  See also
  onWithTimedOff

  #### Declaration

  Swift

      func onWithTimedOffBatchable(onOffControl: https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter.html.OnOffTrait.https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait/OnOffControlBitmap.html, onTime: UInt16, offWaitTime: UInt16) throws -> BatchableCommand<Void>

- `


  ### [DelayedAllOffEffectVariantEnum](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait/DelayedAllOffEffectVariantEnum.html)


  ` Delayed fading effects for lighting.

  #### Declaration

  Swift

      enum DelayedAllOffEffectVariantEnum

- `


  ### [DyingLightEffectVariantEnum](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait/DyingLightEffectVariantEnum.html)


  ` Dying effects for lighting.

  #### Declaration

  Swift

      enum DyingLightEffectVariantEnum

- `


  ### [EffectIdentifierEnum](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait/EffectIdentifierEnum.html)


  ` Fading effect types for use with lighting.

  #### Declaration

  Swift

      enum EffectIdentifierEnum

- `


  ### [StartUpOnOffEnum](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait/StartUpOnOffEnum.html)


  ` Startup behaviors for a device.

  #### Declaration

  Swift

      enum StartUpOnOffEnum

- `


  ### [Feature](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait/Feature.html)


  ` OnOff cluster FeatureMap.

  #### Declaration

  Swift

      struct Feature

- `


  ### [OnOffControlBitmap](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Matter/OnOffTrait/OnOffControlBitmap.html)


  ` Flags for cluster control.

  #### Declaration

  Swift

      struct OnOffControlBitmap