Created
April 30, 2022 21:11
-
-
Save S-Collison/cda4a5e8f7cd2595821684783a57ea8f 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 metadata | |
| blueprint: | |
| name: Hook - Media Player | |
| description: | | |
| # Hook - Media Player | |
| Hook automation which allows to control a media player. Supports volume setting, play/pause and track selection. Features may vary depending on the selected Controller. | |
| An automation created with this blueprint must be linked to a [Controller](https://epmatt.github.io/awesome-ha-blueprints/blueprints/controllers) automation. | |
| Controllers are blueprints which allow to easily integrate a wide range of controllers (wall switches, remotes, dimmers, etc.) and use them to run a set of actions when interacting with them. | |
| They expose an abstract interface used by Hooks to create controller-based automations. | |
| A list of controllers supported by this hook is available [here](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/hooks/media_player#supported-controllers). | |
| 📕 Full documentation regarding this blueprint is available [here](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/hooks/media_player). | |
| 🚀 This blueprint is part of the **[Awesome HA Blueprints](https://epmatt.github.io/awesome-ha-blueprints) project**. | |
| ℹ️ Version 2021.12.03 | |
| source_url: https://github.com/EPMatt/awesome-ha-blueprints/blob/main/blueprints/hooks/media_player/media_player.yaml | |
| domain: automation | |
| input: | |
| controller_device: | |
| name: (Required) Controller Device | |
| description: The controller device which will control the Media Player. Choose a value only if the integration used to connect the controller to Home Assistant exposes it as a Device. This value should match the one specified in the corresponding Controller automation. | |
| default: '' | |
| selector: | |
| device: | |
| controller_entity: | |
| name: (Required) Controller Entity | |
| description: The controller entity which will control the Media Player. Choose a value only if the integration used to connect the controller to Home Assistant exposes it as an Entity. This value should match the one specified in the corresponding Controller automation. | |
| default: '' | |
| selector: | |
| entity: | |
| domain: sensor | |
| controller_model: | |
| name: (Required) Controller model | |
| description: The model for the controller used in this automation. Choose a value from the list of supported controllers. | |
| selector: | |
| select: | |
| options: | |
| - IKEA E1524/E1810 TRÅDFRI Wireless 5-Button Remote | |
| - IKEA E1743 TRÅDFRI On/Off Switch & Dimmer | |
| - IKEA E1744 SYMFONISK Rotary Remote | |
| - IKEA E1766 TRÅDFRI Open/Close Remote | |
| - IKEA E1812 TRÅDFRI Shortcut button | |
| - IKEA E2001/E2002 STYRBAR Remote control | |
| - IKEA ICTC-G-1 TRÅDFRI wireless dimmer | |
| - OSRAM AC025XX00NJ SMART+ Switch Mini | |
| - Philips 324131092621 Hue Dimmer switch | |
| - Philips 8718699693985 Hue Smart Button | |
| - Philips 929002398602 Hue Dimmer switch v2 | |
| - Xiaomi WXCJKG11LM Aqara Opple 2 button remote | |
| - Xiaomi WXCJKG12LM Aqara Opple 4 button remote | |
| - Xiaomi WXCJKG12LM Aqara Opple 4 button remote (#2) | |
| - Xiaomi WXCJKG13LM Aqara Opple 6 button remote | |
| - Xiaomi WXCJKG13LM Aqara Opple 6 button remote (#2) | |
| - Xiaomi WXCJKG13LM Aqara Opple 6 button remote (#3) | |
| media_player: | |
| name: (Required) Media Player | |
| description: Media player which will be controlled with this automation. | |
| selector: | |
| entity: | |
| domain: media_player | |
| volume_steps_short: | |
| name: (Optional) Volume steps - short actions | |
| description: Number of steps from min to max volume when controlling volume with short actions (eg. button press), if the media player supports it. | |
| default: 10 | |
| selector: | |
| number: | |
| min: 1 | |
| max: 100 | |
| step: 1 | |
| unit_of_measurement: steps | |
| mode: box | |
| volume_steps_long: | |
| name: (Optional) Volume steps - long actions | |
| description: Number of steps from min to max volume when controlling volume with long actions (eg. button hold or controller rotation), if the media player supports it. | |
| default: 10 | |
| selector: | |
| number: | |
| min: 1 | |
| max: 100 | |
| step: 1 | |
| unit_of_measurement: steps | |
| mode: box | |
| # Automation schema | |
| variables: | |
| # convert blueprint inputs into variables to be used in templates | |
| controller_model: !input controller_model | |
| # supported controllers and mappings | |
| controller_mapping: | |
| IKEA E1524/E1810 TRÅDFRI Wireless 5-Button Remote: | |
| volume_up: button_up_short | |
| volume_up_repeat: button_up_long | |
| volume_down: button_down_short | |
| volume_down_repeat: button_down_long | |
| prev_track: button_left_short | |
| next_track: button_right_short | |
| play_pause: button_center_short | |
| stop: button_center_long | |
| IKEA E1743 TRÅDFRI On/Off Switch & Dimmer: | |
| volume_up: button_up_short | |
| volume_up_repeat: button_up_long | |
| next_track: button_up_double | |
| volume_down: button_down_long | |
| play_pause: button_down_double | |
| IKEA E1744 SYMFONISK Rotary Remote: | |
| volume_down_repeat: rotate_left | |
| volume_up_repeat: rotate_right | |
| play_pause: click_short | |
| next_track: click_double | |
| prev_track: click_triple | |
| IKEA E1766 TRÅDFRI Open/Close Remote: | |
| volume_up: button_up_short | |
| next_track: button_up_double | |
| volume_down: button_down_short | |
| play_pause: button_down_double | |
| IKEA E1812 TRÅDFRI Shortcut button: | |
| play_pause: button_short | |
| stop: button_long | |
| next_track: button_double | |
| IKEA E2001/E2002 STYRBAR Remote control: | |
| play_pause: button_up_short | |
| volume_up_repeat: button_up_long | |
| stop: button_down_short | |
| volume_down_repeat: button_down_long | |
| prev_track: button_left_short | |
| next_track: button_right_short | |
| IKEA ICTC-G-1 TRÅDFRI wireless dimmer: | |
| volume_down_repeat: rotate_left | |
| volume_up_repeat: rotate_right | |
| OSRAM AC025XX00NJ SMART+ Switch Mini: | |
| volume_up: button_up_short | |
| volume_up_repeat: button_up_long | |
| next_track: button_up_double | |
| volume_down: button_down_short | |
| volume_down_repeat: button_down_long | |
| prev_track: button_down_double | |
| play_pause: button_center_short | |
| toggle: button_center_long | |
| Philips 324131092621 Hue Dimmer switch: | |
| play_pause: button_on_short | |
| next_track: button_on_long | |
| stop: button_off_short | |
| prev_track: button_off_long | |
| volume_up: button_up_short | |
| volume_up_repeat: button_up_long | |
| volume_down: button_down_short | |
| volume_down_repeat: button_down_long | |
| Philips 8718699693985 Hue Smart Button: | |
| play_pause: button_short | |
| next_track: button_double | |
| Philips 929002398602 Hue Dimmer switch v2: | |
| play_pause: button_on_short | |
| next_track: button_on_long | |
| stop: button_off_short | |
| prev_track: button_off_long | |
| volume_up: button_up_short | |
| volume_up_repeat: button_up_long | |
| volume_down: button_down_short | |
| volume_down_repeat: button_down_long | |
| Xiaomi WXCJKG11LM Aqara Opple 2 button remote: | |
| volume_up: button_1_short | |
| volume_up_repeat: button_1_long | |
| next_track: button_1_double | |
| volume_down: button_2_long | |
| play_pause: button_2_double | |
| Xiaomi WXCJKG12LM Aqara Opple 4 button remote: | |
| volume_up: button_1_short | |
| volume_up_repeat: button_1_long | |
| next_track: button_1_double | |
| volume_down: button_2_long | |
| play_pause: button_2_double | |
| Xiaomi WXCJKG12LM Aqara Opple 4 button remote (#2): | |
| volume_up: button_3_short | |
| volume_up_repeat: button_3_long | |
| next_track: button_3_double | |
| volume_down: button_4_long | |
| play_pause: button_4_double | |
| Xiaomi WXCJKG13LM Aqara Opple 6 button remote: | |
| volume_up: button_1_short | |
| volume_up_repeat: button_1_long | |
| next_track: button_1_double | |
| volume_down: button_2_long | |
| play_pause: button_2_double | |
| Xiaomi WXCJKG13LM Aqara Opple 6 button remote (#2): | |
| volume_up: button_3_short | |
| volume_up_repeat: button_3_long | |
| next_track: button_3_double | |
| volume_down: button_4_long | |
| play_pause: button_4_double | |
| Xiaomi WXCJKG13LM Aqara Opple 6 button remote (#3): | |
| volume_up: button_5_short | |
| volume_up_repeat: button_5_long | |
| next_track: button_5_double | |
| volume_down: button_6_long | |
| play_pause: button_6_double | |
| # pre-choose actions for buttons based on configured controller | |
| # no need to perform this task at automation runtime | |
| volume_up: '{{ controller_mapping[controller_model]["volume_up"] | default(None) }}' | |
| volume_up_repeat: '{{ controller_mapping[controller_model]["volume_up_repeat"] | default(None) }}' | |
| volume_down: '{{ controller_mapping[controller_model]["volume_down"] | default(None) }}' | |
| volume_down_repeat: '{{ controller_mapping[controller_model]["volume_down_repeat"] | default(None) }}' | |
| next_track: '{{ controller_mapping[controller_model]["next_track"] | default(None) }}' | |
| prev_track: '{{ controller_mapping[controller_model]["prev_track"] | default(None) }}' | |
| stop: '{{ controller_mapping[controller_model]["stop"] | default(None) }}' | |
| play_pause: '{{ controller_mapping[controller_model]["play_pause"] | default(None) }}' | |
| toggle: '{{ controller_mapping[controller_model]["toggle"] | default(None) }}' | |
| volume_steps_short: !input volume_steps_short | |
| volume_steps_long: !input volume_steps_long | |
| media_player: !input media_player | |
| volume_step_value_short: '{{ 1/volume_steps_short }}' | |
| volume_step_value_long: '{{ 1/volume_steps_long }}' | |
| mode: restart | |
| max_exceeded: silent | |
| trigger: | |
| - platform: event | |
| event_type: ahb_controller_event | |
| event_data: | |
| controller: !input controller_device | |
| - platform: event | |
| event_type: ahb_controller_event | |
| event_data: | |
| controller: !input controller_entity | |
| condition: [] | |
| action: | |
| - variables: | |
| action: '{{ trigger.event.data.action }}' | |
| - choose: | |
| - conditions: '{{ action == play_pause }}' | |
| sequence: | |
| - service: media_player.media_play_pause | |
| entity_id: !input media_player | |
| - conditions: '{{ action == stop }}' | |
| sequence: | |
| - service: media_player.media_stop | |
| entity_id: !input media_player | |
| - conditions: '{{ action == next_track }}' | |
| sequence: | |
| - service: media_player.media_next_track | |
| entity_id: !input media_player | |
| - conditions: '{{ action == prev_track }}' | |
| sequence: | |
| - service: media_player.media_previous_track | |
| entity_id: !input media_player | |
| - conditions: '{{ action == toggle }}' | |
| sequence: | |
| - service: media_player.toggle | |
| entity_id: !input media_player | |
| - conditions: '{{ action == volume_up }}' | |
| sequence: | |
| - choose: | |
| # if the volume level can be read from the media player, increase the volume by the custom step value | |
| - conditions: '{{ state_attr(media_player, "volume_level") != None }}' | |
| sequence: | |
| - service: media_player.volume_set | |
| entity_id: !input media_player | |
| data: | |
| volume_level: '{{ [ state_attr(media_player, "volume_level")+volume_step_value_short, 1 ] | min }}' | |
| # if the volume level is not available, fallback to the media_player.volume_up service | |
| default: | |
| - service: media_player.volume_up | |
| entity_id: !input media_player | |
| - conditions: '{{ action == volume_down }}' | |
| sequence: | |
| - choose: | |
| # if the volume level can be read from the media player, decrease the volume by the custom step value | |
| - conditions: '{{ state_attr(media_player, "volume_level") != None }}' | |
| sequence: | |
| - service: media_player.volume_set | |
| entity_id: !input media_player | |
| data: | |
| volume_level: '{{ [ state_attr(media_player, "volume_level")-volume_step_value_short, 0 ] | max }}' | |
| # if the volume level is not available, fallback to the media_player.volume_down service | |
| default: | |
| - service: media_player.volume_down | |
| entity_id: !input media_player | |
| - conditions: '{{ action == volume_up_repeat }}' | |
| sequence: | |
| - repeat: | |
| while: '{{ true }}' | |
| sequence: | |
| - choose: | |
| # if the volume level can be read from the media player, increase the volume by the custom step value | |
| - conditions: '{{ state_attr(media_player, "volume_level") != None }}' | |
| sequence: | |
| - service: media_player.volume_set | |
| entity_id: !input media_player | |
| data: | |
| volume_level: '{{ [ state_attr(media_player, "volume_level")+volume_step_value_long, 1 ] | min }}' | |
| # if the volume level is not available, fallback to the media_player.volume_up service | |
| default: | |
| - service: media_player.volume_up | |
| entity_id: !input media_player | |
| - delay: | |
| milliseconds: 250 | |
| - conditions: '{{ action == volume_down_repeat }}' | |
| sequence: | |
| - repeat: | |
| while: '{{ true }}' | |
| sequence: | |
| - choose: | |
| # if the volume level can be read from the media player, decrease the volume by the custom step value | |
| - conditions: '{{ state_attr(media_player, "volume_level") != None }}' | |
| sequence: | |
| - service: media_player.volume_set | |
| entity_id: !input media_player | |
| data: | |
| volume_level: '{{ [ state_attr(media_player, "volume_level")-volume_step_value_long, 0 ] | max }}' | |
| # if the volume level is not available, fallback to the media_player.volume_down service | |
| default: | |
| - service: media_player.volume_down | |
| entity_id: !input media_player | |
| - delay: | |
| milliseconds: 250 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment