public final class Scene

  1. Object
  2. Scene

A named set of accessory states that can be applied in one go: HomeKit’s HMActionSet, a Google Home scene.

Run one with SmartHome.executeScene(Scene).

Scenes, and not automations

A scene is a list of things to set. An automation is a scene plus a trigger – a time, a sensor crossing a threshold, someone arriving – and the three ecosystems model triggers in three incompatible ways: HomeKit has HMTimerTrigger, HMEventTrigger and HMCharacteristicThreshold, Google has its own automations language, and Matter has nothing at all. There is no honest common shape, so this release exposes scenes and SmartHome.isAutomationSupported() answers false everywhere.

An immutable snapshot.

Constructors

public Scene(String id, String name, String structureId, SceneType type, boolean executable, List<SceneAction> actions)Creates a scene snapshot.

Methods

public String getId()The identifier this scene is addressed by.
public String getName()The user-visible name, empty when the scene has none.
public String getStructureId()The structure this scene belongs to.
public SceneType getType()What kind of scene this is.
public boolean isExecutable()Whether this scene can be run with SmartHome.executeScene(Scene).
public List<SceneAction> getActions()What this scene does.
public String toString()Returns a string representation of the object.

Inherited methods

Constructor details

Scene

public Scene(String id, String name, String structureId, SceneType type, boolean executable, List<SceneAction> actions)
Creates a scene snapshot. Called by the ports and by the local home.

Parameters

id String
the scene identifier
name String
the user-visible name, or null for none
structureId String
the structure this scene belongs to
type SceneType
what kind of scene it is; null becomes SceneType.USER_DEFINED
executable boolean
whether it can be run from here
actions List<SceneAction>
what it does; null becomes empty, which is also what a backend that will not enumerate a scene’s contents produces

Throws

IllegalArgumentException
when id is null or empty

Method details

getId

public String getId()
The identifier this scene is addressed by.

Returns

the identifier, never null

getName

public String getName()
The user-visible name, empty when the scene has none. The user’s own text; treat it as untrusted beyond display.

Returns

the name, never null

getStructureId

public String getStructureId()
The structure this scene belongs to.

Returns

the structure identifier, or null when unknown

getType

public SceneType getType()
What kind of scene this is.

Returns

the type, never null

isExecutable

public boolean isExecutable()

Whether this scene can be run with SmartHome.executeScene(Scene).

false for a SceneType.TRIGGER_OWNED scene, and for one the user’s permissions on this home do not let them run. Calling executeScene anyway fails with HomeError.UNAUTHORIZED rather than quietly doing nothing, but checking first is how you avoid offering a button that cannot work.

Returns

true when the scene can be run

getActions

public List<SceneAction> getActions()

What this scene does.

Empty is not the same as “does nothing”. Some backends will run a scene without enumerating its contents, so an empty list means the platform did not say. Do not render “this scene is empty” from it.

Returns

an immutable list, possibly empty

toString

public String toString()
Returns a string representation of the object. In general, the toString method returns a string that “textually represents” this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@’, and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + ‘@’ + Integer.toHexString(hashCode())