Last active
July 22, 2023 22:27
-
-
Save clempat/093d1b27b1abf35be9ad7bd7fc3fb9a7 to your computer and use it in GitHub Desktop.
Blueprint Home Assistant Cinema mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
blueprint: | |
name: Scene switcher when media is playing | |
description: | | |
This allow you to change a scene when it is playing, paused or stopped. | |
There is the possibility to excludes apps | |
The scene trigger only when at least one light of the scene is on | |
domain: automation | |
input: | |
media_player: | |
name: Media Player | |
description: Media Player to track | |
selector: | |
entity: | |
domain: media_player | |
app_to_exclude: | |
name: Apps to exclude | |
default: "" | |
description: | | |
Liste of App to exclude (ex: Spotify,Google Cast). This is optional | |
playing_scene: | |
name: Playing Scene | |
description: | | |
The scene to turn on when playing. | |
selector: | |
entity: | |
domain: scene | |
paused_scene: | |
name: Paused Scene | |
default: | |
description: | | |
The scene to turn on when in paused. | |
If not indicated the automation will come to old lights state | |
selector: | |
entity: | |
domain: scene | |
standby_scene: | |
name: Standby Scene | |
default: | |
description: | | |
The scene to turn on when in standby. | |
If not indicated the automation will come to old lights state | |
selector: | |
entity: | |
domain: scene | |
idle_scene: | |
name: Idle Scene | |
default: | |
description: | | |
The scene to turn on when in idle. | |
If not indicated the automation will come to old lights state | |
selector: | |
entity: | |
domain: scene | |
off_scene: | |
name: Off Scene | |
default: | |
description: | | |
The scene to turn on when in off. | |
If not indicated the automation will come to old lights state | |
selector: | |
entity: | |
domain: scene | |
delay: | |
name: Delay | |
description: How long the state need to be maintained before changing the light. | |
default: 0 | |
selector: | |
number: | |
min: 0.0 | |
max: 120.0 | |
unit_of_measurement: seconds | |
step: 1.0 | |
mode: slider | |
fallback_scene: | |
name: Default Scene | |
default: | |
description: | | |
If there is no previous scene created like due to restart this scene will be activated instead of the previous lights. | |
selector: | |
entity: | |
domain: scene | |
variables: | |
app_to_exclude: !input "app_to_exclude" | |
app_to_exclude_sanitized: "{{ app_to_exclude.split(',') | map('trim') | list }}" | |
playing_scene: !input "playing_scene" | |
idle_scenet: !input "idle_scene" | |
paused_scene: !input "paused_scene" | |
off_scene: !input "off_scene" | |
standby_scene: !input "standby_scene" | |
fallback_scene: !input "fallback_scene" | |
delay: !input "delay" | |
trigger: | |
platform: state | |
entity_id: !input media_player | |
for: | |
seconds: !input delay | |
action: | |
- variables: | |
main_lights: "{{ state_attr(playing_scene, 'entity_id') }}" | |
scene_main_lights_object_id: "{{ states[playing_scene].object_id }}" | |
current_app_name: "{{ trigger.to_state.attributes.app_name }}" | |
is_excluded_app: "{{ app_to_exclude_sanitized | select('eq', current_app_name) | list | count > 0 }}" | |
has_light_on: "{{ expand(main_lights) | selectattr('state','eq','on') | list | count > 0 }}" | |
- choose: | |
# Switch on | |
- conditions: | |
- "{{ trigger.from_state.state == 'off' }}" | |
sequence: | |
- service: scene.create | |
data_template: | |
scene_id: "media_scene_{{scene_main_lights_object_id}}_lights_previous" | |
snapshot_entities: "{{ main_lights }}" | |
# Playing | |
- conditions: | |
- "{{ trigger.to_state.state == 'playing' }}" | |
- "{{ trigger.from_state.state != 'playing' }}" | |
- "{{ not is_excluded_app }}" | |
- "{{ has_light_on }}" | |
sequence: | |
- service: scene.turn_on | |
data: | |
entity_id: !input "playing_scene" | |
transition: 1 | |
# Paused | |
- conditions: | |
- "{{ trigger.to_state.state == 'paused' }}" | |
- "{{ trigger.from_state.state != 'paused' }}" | |
- "{{ not is_excluded_app }}" | |
- "{{ paused_scene is not none }}" | |
- "{{ has_light_on }}" | |
sequence: | |
- service: scene.turn_on | |
data: | |
entity_id: !input "paused_scene" | |
transition: 1 | |
# Idle | |
- conditions: | |
- "{{ trigger.to_state.state == 'idle' }}" | |
- "{{ trigger.from_state.state != 'idle' }}" | |
- "{{ not is_excluded_app }}" | |
- "{{ idle_scene is not none }}" | |
- "{{ has_light_on }}" | |
sequence: | |
- service: scene.turn_on | |
data: | |
entity_id: !input "idle_scene" | |
transition: 1 | |
# Standby | |
- conditions: | |
- "{{ trigger.to_state.state == 'standby' }}" | |
- "{{ trigger.from_state.state != 'standby' }}" | |
- "{{ not is_excluded_app }}" | |
- "{{ standby_scene is not none }}" | |
- "{{ has_light_on }}" | |
sequence: | |
- service: scene.turn_on | |
data: | |
entity_id: !input "standby_scene" | |
transition: 1 | |
# Standby | |
- conditions: | |
- "{{ trigger.to_state.state == 'off' }}" | |
- "{{ not is_excluded_app }}" | |
- "{{ off_scene is not none }}" | |
- "{{ has_light_on }}" | |
sequence: | |
- service: scene.turn_on | |
data: | |
entity_id: !input "off_scene" | |
transition: 1 | |
# any state without scene | |
- conditions: | |
- "{{ (['off', 'standby', 'idle', 'paused']) | select('eq', trigger.to_state.state) | list | count > 0 }}" | |
- "{{ (['off', 'standby', 'idle', 'paused']) | select('eq', trigger.from_state.state) | list | count == 0 }}" | |
- "{{ not is_excluded_app }}" | |
- "{{ has_light_on }}" | |
- "{{ fallback_scene is not none }}" | |
- condition: template | |
value_template: > | |
{{ states["scene.media_scene_"+scene_main_lights_object_id+"_lights_previous"] == None}} | |
sequence: | |
- service: scene.turn_on | |
data: | |
entity_id: !input "fallback_scene" | |
transition: 1 | |
- conditions: | |
- "{{ (['off', 'standby', 'idle', 'paused']) | select('eq', trigger.to_state.state) | list | count > 0 }}" | |
- "{{ (['off', 'standby', 'idle', 'paused']) | select('eq', trigger.from_state.state) | list | count == 0 }}" | |
- "{{ not is_excluded_app }}" | |
- "{{ has_light_on }}" | |
sequence: | |
- service: scene.turn_on | |
data_template: | |
entity_id: "scene.media_scene_{{scene_main_lights_object_id}}_lights_previous" | |
transition: 1 | |
default: [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment