home-assistant.io/source/_cookbook/dim_lights_when_playing_media.markdown
Franck Nijhof 1833c32a2c Cleans up front matter (#9835)
* Sets front matter defaults

* Removes default front matter from section templates/pages

* Removes default front matter from addon pages

* Removes default front matter from integration pages

* Removes default front matter from posts

* Removes default front matter from docs pages

* Removes default front matter from other pages

* Fixes blog category pages
2019-07-11 14:35:08 -07:00

1.9 KiB

title, description, ha_category
title description ha_category
Dim lights when playing media Dim lights up or down when playing media Automation Examples

Like it how the lights dim up/down at the movies? Do it at home as well!

This example uses the media player, lights (transitions) and the sun integration. We'll use actions to detect media player state changes and scenes to control multiple lights and transition between scenes.

Scenes

One scene for normal light, one for when movies are on. A 2 second transition gives a nice 'feel' to the switch.

scene:
  - name: Livingroom normal
    entities:
        light.light1:
            state: on
            transition: 2
            brightness_pct: 60
        light.light2:
            state: on
            transition: 2
            brightness_pct: 85
  - name: Livingroom dim
    entities:
        light.light1:
            state: on
            transition: 2
            brightness_pct: 30
        light.light2:
            state: on
            transition: 2
            brightness_pct: 55

Automation

The paused/stopped state is best matched using "from: 'playing'". Adding in the sun condition as we only want this when it's dark.

automation:
  - alias: "Media player paused/stopped"
    trigger:
      - platform: state
        entity_id: media_player.htpc
        from: 'playing'
        to: 'idle'
    condition:
      - condition: state
        entity_id: sun.sun
        state: 'below_horizon'
    action:
        service: scene.turn_on
        entity_id: scene.livingroom_normal

  - alias: "Media player playing"
    trigger:
      - platform: state
        entity_id: media_player.htpc
        to: 'playing'
        from: 'idle'
    condition:
      - condition: state
        entity_id: sun.sun
        state: 'below_horizon'
    action:
        service: scene.turn_on
        entity_id: scene.livingroom_dim