> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/home-assistant/core/llms.txt
> Use this file to discover all available pages before exploring further.

# Scenes

> Understanding scenes in Home Assistant Core

Scenes capture and restore the state of multiple entities at once. They provide a simple way to set your home to a specific configuration with a single action.

## What is a Scene?

A scene is a snapshot of desired entity states that can be activated to set multiple entities to specific states simultaneously. Unlike automations and scripts, scenes don't have complex logic - they simply set states.

<CodeGroup>
  ```yaml Example Scene theme={null}
  scene:
    - name: Movie Time
      entities:
        light.living_room:
          state: on
          brightness: 30
          color_temp: 400
        light.kitchen:
          state: off
        media_player.tv:
          state: playing
          volume_level: 0.3
        cover.blinds:
          state: closed
  ```
</CodeGroup>

## Scene Structure

Scenes are entities with the domain `scene` and are implemented in `homeassistant/components/scene/`.

### Scene Entity

The base scene class extends `RestoreEntity`:

<CodeGroup>
  ```python homeassistant/components/scene/__init__.py:97-145 theme={null}
  class BaseScene(RestoreEntity):
      """Base type for scenes."""

      _attr_should_poll = False
      __last_activated: str | None = None

      @property
      @final
      def state(self) -> str | None:
          """Return the state of the scene."""
          if self.__last_activated is None:
              return None
          return self.__last_activated

      async def _async_activate(self, **kwargs: Any) -> None:
          """Activate scene."""
          raise NotImplementedError

      def activate(self, **kwargs: Any) -> None:
          """Activate scene. Try to get entities into requested state."""
          raise NotImplementedError

      async def async_activate(self, **kwargs: Any) -> None:
          """Activate scene. Try to get entities into requested state."""
  ```
</CodeGroup>

### Key Properties

* `entity_id`: Format is `scene.<scene_name>`
* `state`: ISO timestamp of last activation
* `entities`: Dictionary of entity states to set

## Defining Scenes

Scenes can be defined in multiple ways:

### YAML Configuration

```yaml theme={null}
scene:
  - name: Romantic
    icon: mdi:candle
    entities:
      light.tv_back_light:
        state: on
        brightness: 1
        rgb_color: [255, 0, 0]
      light.ceiling:
        state: off
      media_player.speaker:
        state: playing
        source: Spotify
```

### Home Assistant Platform

The built-in platform allows dynamic scene creation:

```yaml theme={null}
scene:
  - platform: homeassistant
    name: Concentrate
    entities:
      light.office:
        state: on
        brightness: 255
        color_temp: 250
```

### Scene Service

Create scenes dynamically using the `scene.create` service:

```yaml theme={null}
service: scene.create
data:
  scene_id: my_dynamic_scene
  snapshot_entities:
    - light.living_room
    - light.kitchen
    - media_player.tv
```

Or specify exact states:

```yaml theme={null}
service: scene.create
data:
  scene_id: custom_scene
  entities:
    light.living_room:
      state: on
      brightness: 200
    cover.blinds:
      state: closed
```

## Activating Scenes

### Turn On Service

Scenes are activated using the `scene.turn_on` service:

```yaml theme={null}
service: scene.turn_on
target:
  entity_id: scene.movie_time
data:
  transition: 2  # Optional transition time in seconds
```

### From Automations

```yaml theme={null}
automation:
  - alias: "Evening Scene"
    trigger:
      - platform: sun
        event: sunset
    action:
      - service: scene.turn_on
        target:
          entity_id: scene.evening
```

### From Scripts

```yaml theme={null}
script:
  bedtime:
    sequence:
      - service: scene.turn_on
        target:
          entity_id: scene.goodnight
      - delay: "00:00:30"
      - service: lock.lock
        target:
          entity_id: lock.front_door
```

## Scene Entity States

The state of a scene entity represents the last time it was activated:

```python theme={null}
state = hass.states.get("scene.movie_time")
# state.state = "2024-03-10T14:30:00+00:00"
```

<Info>
  Scenes maintain their last activation timestamp, which is persisted across restarts.
</Info>

## Transition Support

Some entity types support smooth transitions when activating scenes:

```yaml theme={null}
service: scene.turn_on
target:
  entity_id: scene.bright
data:
  transition: 5  # Fade lights over 5 seconds
```

<CodeGroup>
  ```python homeassistant/components/scene/__init__.py:78-82 theme={null}
  component.async_register_entity_service(
      SERVICE_TURN_ON,
      {ATTR_TRANSITION: vol.All(vol.Coerce(float), vol.Clamp(min=0, max=6553))},
      "_async_activate",
  )
  ```
</CodeGroup>

Transition is primarily supported by:

* Lights
* Some media players
* Smart switches with dimming

## Scene Components

### Base Scene Class

<CodeGroup>
  ```python homeassistant/components/scene/__init__.py:97-110 theme={null}
  class BaseScene(RestoreEntity):
      """Base type for scenes."""

      _attr_should_poll = False
      __last_activated: str | None = None

      @property
      @final
      def state(self) -> str | None:
          """Return the state of the scene."""
          if self.__last_activated is None:
              return None
          return self.__last_activated
  ```
</CodeGroup>

### Scene Class

<CodeGroup>
  ```python homeassistant/components/scene/__init__.py:147-159 theme={null}
  class Scene(BaseScene):
      """A scene is a group of entities and the states we want them to be."""

      @final
      async def _async_activate(self, **kwargs: Any) -> None:
          """Activate scene.

          Should not be overridden, handle setting last press timestamp.
          """
          self._async_record_activation()
          self.async_write_ha_state()
          await self.async_activate(**kwargs)
  ```
</CodeGroup>

## Dynamic Scenes

Create scenes programmatically using the `scene.create` service:

### Snapshot Current State

```yaml theme={null}
# Capture current state of entities
service: scene.create
data:
  scene_id: before_party
  snapshot_entities:
    - light.living_room
    - light.kitchen
    - light.bedroom
    - media_player.tv
```

Later, restore the scene:

```yaml theme={null}
service: scene.turn_on
target:
  entity_id: scene.before_party
```

### Specify Exact States

```yaml theme={null}
service: scene.create
data:
  scene_id: work_from_home
  entities:
    light.office:
      state: on
      brightness: 255
      color_temp: 250
    climate.office:
      state: heat
      temperature: 21
    media_player.speaker:
      state: playing
      volume_level: 0.2
```

## Scene Best Practices

<Card title="Meaningful Names" icon="tag">
  Use descriptive names that clearly indicate what the scene does.
</Card>

<Card title="Complete States" icon="list-check">
  Include all relevant entities to ensure consistent scene activation.
</Card>

<Card title="Test Transitions" icon="clock">
  Test transition times with different entity types to ensure smooth changes.
</Card>

<Card title="Scene Snapshots" icon="camera">
  Use `scene.create` with `snapshot_entities` to capture current states before changes.
</Card>

## Integration with Other Components

### With Automations

```yaml theme={null}
automation:
  - alias: "Morning Routine"
    trigger:
      - platform: time
        at: "07:00:00"
    action:
      - service: scene.turn_on
        target:
          entity_id: scene.wake_up
```

### With Scripts

```yaml theme={null}
script:
  party_mode:
    sequence:
      - service: scene.turn_on
        target:
          entity_id: scene.party_lights
      - service: media_player.play_media
        target:
          entity_id: media_player.speaker
        data:
          media_content_id: "spotify:playlist:party"
```

### Scene Triggers

Scenes can be used in automation triggers:

```yaml theme={null}
scene:
  - name: trigger
    entities:
      sensor.scene_trigger:
        state: "movie"
```

## Comparing Scenes, Scripts, and Automations

| Feature        | Scenes                     | Scripts                   | Automations           |
| -------------- | -------------------------- | ------------------------- | --------------------- |
| **Triggers**   | None                       | None                      | Yes                   |
| **Conditions** | None                       | Yes (in sequences)        | Yes                   |
| **Complexity** | Simple state setting       | Complex sequences         | Complex with triggers |
| **Timing**     | Instant (with transitions) | Sequential with delays    | Event-driven          |
| **Use Case**   | Set multiple entity states | Reusable action sequences | React to events       |

## Platform-Specific Scenes

Some integrations provide their own scene platforms:

```yaml theme={null}
scene:
  - platform: hue
    # Hue-specific scene configuration
  
  - platform: homekit_controller
    # HomeKit scene configuration
```

## Scene Services

### scene.turn\_on

Activate a scene:

```yaml theme={null}
service: scene.turn_on
target:
  entity_id: scene.relax
data:
  transition: 3
```

### scene.create

Create or update a scene:

```yaml theme={null}
service: scene.create
data:
  scene_id: my_scene
  snapshot_entities:
    - light.living_room
  # OR
  entities:
    light.living_room:
      state: on
      brightness: 128
```

### scene.reload

Reload scene configuration:

```yaml theme={null}
service: scene.reload
```

## Scene Storage

Scenes maintain minimal state - primarily the last activation timestamp:

```python theme={null}
class BaseScene(RestoreEntity):
    async def async_internal_added_to_hass(self) -> None:
        """Call when the scene is added to hass."""
        await super().async_internal_added_to_hass()
        state = await self.async_get_last_state()
        if (
            state is not None
            and state.state is not None
            and state.state != STATE_UNAVAILABLE
        ):
            self.__last_activated = state.state
```

## Common Use Cases

### Home Theater

```yaml theme={null}
scene:
  - name: Movie Night
    entities:
      light.living_room: off
      light.tv_backlight:
        state: on
        brightness: 10
        rgb_color: [0, 0, 255]
      media_player.tv:
        state: on
        source: "HDMI 1"
      cover.blinds: closed
```

### Work Mode

```yaml theme={null}
scene:
  - name: Focus Time
    entities:
      light.office:
        state: on
        brightness: 255
        color_temp: 250
      climate.office:
        temperature: 21
      media_player.speaker:
        state: off
```

### Departure

```yaml theme={null}
scene:
  - name: Away
    entities:
      light.all_lights: off
      climate.thermostat:
        preset_mode: away
      lock.front_door: locked
      alarm_control_panel.home:
        state: armed_away
```

## Related Resources

<CardGroup cols={2}>
  <Card title="Automations" icon="wand-magic-sparkles" href="/concepts/automations">
    Use scenes in automation actions
  </Card>

  <Card title="Scripts" icon="scroll" href="/concepts/scripts">
    Incorporate scenes into scripts
  </Card>

  <Card title="Service Calls" icon="tower-broadcast" href="/architecture/services">
    Learn about the service system
  </Card>

  <Card title="State Machine" icon="database" href="/architecture/state-machine">
    Understand entity state management
  </Card>
</CardGroup>
