Home Cinema Automations with Home Assistant and Chromecast

The addition of Chromecast to my setup has opened up even more automation opportunities. In particular, to improve the movie watching and media consumption experience.

These automations add a nice touch to your home cinema, allowing automatic light dimming based on Chromecast’s current state.

Refer to the Google Cast documentation on Home Assistant’s website to setup your Chromecast with Home Assistant.

Check what entity id is assigned to it by opening the known_devices.yaml file after a server restart.

The following automations use the state component to trigger automations based on the state of the chromecast. Your chromecast can be in 3 states: idle, playing,paused and we can write automations that take advantage of these states.


- alias: Media player paused
  trigger:
    - platform: state
      # entity_id: media_player.plex_web_chrome
      entity_id: media_player.tv
      to: 'paused'
  condition:
    condition: template
    value_template: "{{states.media_player.tv.attributes.media_content_type != 'music' }}"
  action:
    service: light.turn_on
    entity_id: light.living_room_table_lamp


- alias: Media player idle
  trigger:
    - platform: state
      entity_id: media_player.tv
      to: 'idle'
  condition:
    condition: template
    value_template: "{{states.media_player.tv.attributes.media_content_type != 'music' }}"

  action:
    service: light.turn_on
    entity_id: light.living_room_table_lamp

- alias: Media player playing
  trigger:
    platform: state
    entity_id: media_player.tv
    to: 'playing'
    for:
      seconds: 5
  condition:
    condition: template
    value_template: "{{states.media_player.tv.attributes.media_content_type != 'music' }}"
  action:
    - service: media_player.turn_off
      entity_id: media_player.soundtouch
    - service: light.turn_off
      entity_id: light.living_room_table_lamp

These automations turn a lamp on and off depending on Chromecasts playing state. The lamp is a placeholder as I am working on a LED controller for common anode RGB LED strips to replace the cheap remote control controller that came with my RGB LED strip. I added a condition to my autmations using the condition template component, because I realised my actions would execute not only for movies and youtube videos (‘video’ content type) but also when casting music through Spotify. The conditions stop these automations from happening when casting music.

Feel free to adapt to your needs, I thought I should include it in case you find it useful.