Skip to content

Instantly share code, notes, and snippets.

@organicaudio
Last active January 16, 2021 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save organicaudio/185bf842f636fd3fa99dde4b7adfea1c to your computer and use it in GitHub Desktop.
Save organicaudio/185bf842f636fd3fa99dde4b7adfea1c to your computer and use it in GitHub Desktop.
Home Assistant Automation - Media Player activity triggers room lighting
########################################################################
# MEDIA PLAYER ACTIVITY TRIGGERS LIGHTS
#
# when tv is playing from kodi or chromecast light will turn on
# behind tv and set to an appropriate colour for the time of day
# when devices turn off, light turns off
#
# Monitors for:
# - Kodi activity
# - Chromecast TV activity
#
# Actions:
# - activates one of three different light scenes (hue) based
# on the time of day
# - when activity ceases, light turns off
#
# https://gist.github.com/sawyyz/185bf842f636fd3fa99dde4b7adfea1c
########################################################################
- id: tv_kodi_on_day
alias: Automation - Living Room Kodi - On (Day)
trigger:
- platform: state
entity_id: media_player.living_kodi
to: idle
from: 'off'
mode: restart
condition:
- condition: time
after: 09:01:00
before: '18:00:00'
action:
service: scene.turn_on
entity_id: scene.tv_light_day
- id: tv_kodi_on_evening
alias: Automation - Living Room Kodi - On (Evening)
trigger:
- platform: state
entity_id: media_player.living_kodi
to: idle
from: 'off'
mode: restart
condition:
- condition: time
after: '18:01:00'
before: '23:00:00'
action:
service: scene.turn_on
entity_id: scene.tv_light_evening
- id: tv_kodi_on_night
alias: Automation - Living Room Kodi - On (Night)
trigger:
- platform: state
entity_id: media_player.living_kodi
to: idle
from: 'off'
mode: restart
condition:
- condition: time
after: '23:01:00'
before: 06:00:00
action:
service: scene.turn_on
entity_id: scene.tv_light_night
- id: tv_kodi_off
alias: Automation - Living Room Kodi - Off
trigger:
- platform: state
entity_id: media_player.living_kodi
to: 'off'
from: idle
for: 00:00:10
mode: restart
condition:
- condition: state
entity_id: media_player.living_tv
state: 'off'
action:
service: homeassistant.turn_off
entity_id: light.tv
- id: tv_chromecast_on_day
alias: Automation - Living Room TV - On (Day)
trigger:
- platform: state
entity_id: media_player.living_tv
to: playing
from: 'off'
- platform: state
entity_id: media_player.living_tv
to: paused
from: 'off'
- platform: state
entity_id: media_player.living_tv
to: idle
from: 'off'
mode: restart
condition:
- condition: time
after: 09:01:00
before: '18:00:00'
action:
service: scene.turn_on
entity_id: scene.tv_light_day
- id: tv_chromecast_on_evening
alias: Automation - Living Room TV - On (Evening)
trigger:
- platform: state
entity_id: media_player.living_tv
to: playing
from: 'off'
- platform: state
entity_id: media_player.living_tv
to: idle
from: 'off'
mode: restart
condition:
- condition: time
after: '18:01:00'
before: '23:00:00'
action:
service: scene.turn_on
entity_id: scene.tv_light_evening
- id: tv_chromecast_on_night
alias: Automation - Living Room TV - On (Night)
trigger:
- platform: state
entity_id: media_player.living_tv
to: playing
from: 'off'
- platform: state
entity_id: media_player.living_tv
to: paused
from: 'off'
- platform: state
entity_id: media_player.living_tv
to: idle
from: 'off'
mode: restart
condition:
- condition: time
after: '23:01:00'
before: 06:00:00
action:
service: scene.turn_on
entity_id: scene.tv_light_night
- id: tv_chromecast_off
alias: Automation - Living Room TV - Off
trigger:
- platform: state
entity_id: media_player.living_tv
from: playing
to: 'off'
for: 00:00:10
- platform: state
entity_id: media_player.living_tv
from: paused
to: 'off'
for: 00:00:10
- platform: state
entity_id: media_player.living_tv
from: idle
to: 'off'
for: 00:00:10
mode: restart
condition:
- condition: state
entity_id: media_player.living_kodi
state: 'off'
action:
service: homeassistant.turn_off
entity_id: light.tv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment