Hi,
The below code works but is there a way that this code can be optimized?
The script triggers if tv or tv_1 is in state (playing, paused, idle or unavailable). Only one of the tv will be playing at a given time.
Once the script is triggered,
-
It checks if tv or tv_1 is playing then it turns OFF the lights and sets input_boolean.movie_mode to “off” (its required for TTS in another script) and call the script to turn OFF the lights.
-
It checks if tv or tv_1 is paused, idle or unavailable then it turns ON the lights and sets input_boolean.movie_mode to “on” (its required for TTS in another script) and call the script to turn ON the lights.
alias: Movie
description: ""
trigger:
- platform: state
entity_id:
- media_player.tv
- media_player.tv_1
to:
- playing
- paused
- idle
- unavailable
condition: []
action:
- choose:
- conditions:
- condition: and
conditions:
- condition: or
conditions:
- condition: state
entity_id: media_player.tv
state: playing
- condition: state
entity_id: media_player.tv_1
state: playing
- condition: state
entity_id: input_boolean.movie_mode
state: "off"
sequence:
- service: script.turn_lights_on_off
data:
flag: true
- conditions:
- condition: and
conditions:
- condition: or
conditions:
- condition: state
entity_id: media_player.tv
state:
- paused
- idle
- unavailable
- condition: state
entity_id: media_player.tv_1
state:
- paused
- idle
- unavailable
- condition: state
entity_id: input_boolean.movie_mode
state: "on"
enabled: true
sequence:
- service: script.turn_lights_on_off
data:
flag: false
default: []
mode: single
trigger:
- platform: state
entity_id:
- media_player.tv
- media_player.tv_1
to:
- playing
- paused
- idle
- unavailable
a. Can this part be converted to a template which returns the entity_id of the tv that is playing ?
conditions:
- condition: or
conditions:
- condition: state
entity_id: media_player.tv
state: playing
- condition: state
entity_id: media_player.tv_1
state: playing
b. Can this part be converted to template which return the entity_id of the tv that is playing ?
C. Can the code be optimized?