Created
August 18, 2023 19:29
-
-
Save jfparis/393c5d25f204ce4fc35908bee2472183 to your computer and use it in GitHub Desktop.
Turn off all media players
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
alias: Everybody left | |
description: "" | |
trigger: | |
- platform: state | |
entity_id: binary_sensor.anyone_home | |
to: "off" | |
for: | |
hours: 0 | |
minutes: 2 | |
seconds: 0 | |
condition: | |
- condition: state | |
entity_id: input_boolean.guest_mode | |
state: "off" | |
action: | |
- service: light.turn_off | |
data: | |
entity_id: > | |
{% for each in states.light %}{% if "bertie" not in each.entity_id %}{% | |
if not(loop.changed(True)) %}, {% endif %}{{each.entity_id}}{% endif | |
%}{% endfor %} | |
- if: | |
- condition: template | |
value_template: >- | |
{% set players = namespace(entity_id=[]) %} | |
{% for item in | |
states.media_player|selectattr('state','in',['on','playing']) %} | |
{% if item.attributes.supported_features|bitwise_and(1) and | |
"all_speakers" not in | |
item.entity_id and "spotify" not in item.entity_id and "plex" not in | |
item.entity_id %} | |
{% set players.entity_id = players.entity_id + [item.entity_id] %} | |
{% endif %} | |
{% endfor %} | |
{{players.entity_id|count > 0}} | |
then: | |
- service: media_player.media_pause | |
data: | |
entity_id: > | |
{% set players = namespace(entity_id=[]) %} {% for item in | |
states.media_player|selectattr('state','in',['on','playing']) %} {% | |
if item.attributes.supported_features|bitwise_and(1) and | |
"all_speakers" not in item.entity_id and "spotify" not in | |
item.entity_id and "plex" not in item.entity_id %} {% set | |
players.entity_id = players.entity_id + [item.entity_id] %} {% endif | |
%} {% endfor %} {% for each in players.entity_id %}{% if | |
not(loop.changed(True)) %}, {% endif %}{{each}}{% endfor %} | |
enabled: true | |
- if: | |
- condition: template | |
value_template: >- | |
{% set players = namespace(entity_id=[]) %} | |
{% for item in | |
states.media_player|selectattr('state','in',['on','home','playing','paused']) | |
%} | |
{% if item.attributes.supported_features|bitwise_and(256) %} | |
{% set players.entity_id = players.entity_id + [item.entity_id] %} | |
{% endif %} | |
{% endfor %} | |
{{players.entity_id|count > 0}} | |
then: | |
- service: media_player.turn_off | |
data: | |
entity_id: > | |
{% set players = namespace(entity_id=[]) %} {% for item in | |
states.media_player|selectattr('state','in',['on','home','playing','paused']) | |
%} {% if item.attributes.supported_features|bitwise_and(256) %} {% | |
set players.entity_id = players.entity_id + [item.entity_id] %} {% | |
endif %} {% endfor %} {% for each in players.entity_id %}{% if | |
not(loop.changed(True)) %}, {% endif %}{{each}}{% endfor %} | |
enabled: true | |
mode: single |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment