Last active
February 5, 2026 19:47
-
-
Save narendraj9/5a1104785d32af03de58005107650fd2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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: Media Player Dependent Switch (Conditional) | |
| description: Turn switch ON when media plays (if conditions met), and OFF when idle. | |
| domain: automation | |
| input: | |
| target_switch: | |
| name: Controlled Switch | |
| selector: | |
| entity: | |
| domain: switch | |
| monitored_players: | |
| name: Media Players | |
| selector: | |
| entity: | |
| domain: media_player | |
| multiple: true | |
| idle_timeout: | |
| name: Idle Timeout | |
| default: "02:00:00" | |
| selector: | |
| duration: | |
| automations_conditions: | |
| name: Turn-On Conditions | |
| description: Extra checks (e.g., "Sun is down", "User at home") required to turn the switch ON. | |
| default: [] | |
| selector: | |
| condition: {} | |
| mode: restart | |
| max_exceeded: silent | |
| trigger: | |
| - platform: state | |
| entity_id: !input monitored_players | |
| to: "playing" | |
| id: "media_started" | |
| - platform: state | |
| entity_id: !input monitored_players | |
| from: "playing" | |
| for: !input idle_timeout | |
| id: "media_idle" | |
| action: | |
| - choose: | |
| # Logic: Turn ON | |
| - conditions: | |
| - condition: trigger | |
| id: "media_started" | |
| sequence: | |
| # Wrapper to handle the user-input list of conditions | |
| - condition: and | |
| conditions: !input automations_conditions | |
| - service: switch.turn_on | |
| target: | |
| entity_id: !input target_switch | |
| # Logic: Turn OFF | |
| - conditions: | |
| - condition: trigger | |
| id: "media_idle" | |
| - condition: template | |
| value_template: > | |
| {% set players = expand(state_attr(this.entity_id, 'source_entities')) %} | |
| {{ players | selectattr('state', 'eq', 'playing') | list | count == 0 }} | |
| sequence: | |
| - service: switch.turn_off | |
| target: | |
| entity_id: !input target_switch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment