Hello Friends,
I have three media_players configured in HA.
media_player.mp1
media_player.mp2
media_player.mp3
Only one of them would be playing at a given time. The below script will store the entity_id of that media_player.
- variables:
media_players: >
{% set media_players = [
states.media_player.mp1,
states.media_player.mp2,
states.media_player.mp3
] %}
{{ media_players | selectattr('state','eq','playing') |
map(attribute ='entity_id') | join()}}
A: In the below part I want to check if any one of the players or all are in off, idle, paused state then turn the boolean ON or OFF accordingly
- service_template: |-
{% if states('media_player.mp1') and states('media_player.mp2') and states('media_player.mp3') in ['off','idle','paused'] %}
input_boolean.turn_off
{% else %}
input_boolean.turn_on
{% endif %}
entity_id: input_boolean.is_playing
B: In this part I want to check if any one of the player is playing it should get paused. How do I use the varibale media_players here ?
- service_template: |-
{% if states('media_player.mp1') in ['off','idle'] %}
media_player.media_stop
{% else %}
media_player.media_pause
{% endif %}
entity_id: media_player.mp1
C: In this part I want to start the playback on that media_player that was paused in step B. How do I use the varibale media_players here ?
- if:
- condition: state
entity_id: input_boolean.is_playing
state: "on"
then:
- service: media_player.media_play
data: {}
target:
entity_id: media_player.mp1
Kindly help me fix this code or kindly suggest a better alternative.
Thanks in advance