Forked from amrutprabhu/zha_moes_smart_knob_media_player_volume.yaml
Created
August 31, 2024 22:40
-
-
Save rm1138/aeb12b4f741d5d2353fbc8ae376c6249 to your computer and use it in GitHub Desktop.
ZHA - Moes Smart Knob for Media Player
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
blueprint: | |
name: ZHA - Moes Smart Knob for Media Player | |
description: 'Control Media Player with a Moes Smart Knob. You can set functions for a | |
single press. This allows you to assign, e.g., a scene or anything else. Rotating | |
left/right will change the volume smoothly of the selected media player. Not all | |
functionality of the device is available at time of writing, e.g. double press, | |
long press. | |
Original blueprint by seamus65 (https://gist.github.com/seamus65/939a147634942dd885c8704334627f93). | |
Improved by GonzaloAlbito (https://gist.github.com/gonzaloalbito/3dc06702e941e08298ea9bfade731731). | |
Further Updated by amrutprabhu(https://gist.github.com/amrutprabhu/5993ed706e4176013097574fc668cdaf). | |
Version 2023-12-02 ' | |
domain: automation | |
input: | |
remote: | |
name: Remote | |
description: Moes Knob to use | |
selector: | |
device: | |
integration: zha | |
model: TS004F | |
multiple: false | |
mediaplayer: | |
name: MediaPlayer | |
description: "The Media player(s) to control. \n\n Important Note: Please select only the entity. Device or Area does not work as of now" | |
selector: | |
target: | |
entity: | |
- domain: | |
- media_player | |
step_percent: | |
name: Volume step | |
description: Volume percent change for each knob step | |
selector: | |
number: | |
mode: slider | |
min: 0 | |
max: 100 | |
step: 1 | |
default: 10 | |
secondary_mediaplayer: | |
name: MediaPlayer | |
description: "The Media Player(s) to control for press and rotate. \n\n Important Note: Please select only the entity. Device or Area does not work as of now" | |
selector: | |
target: | |
entity: | |
- domain: | |
- media_player | |
secondary_step_percent: | |
name: Volume step | |
description: Volume percent change for each knob step for press and rotate | |
selector: | |
number: | |
mode: slider | |
min: 0 | |
max: 100 | |
step: 1 | |
default: 10 | |
single_press: | |
name: Single press | |
description: Action to run on single press | |
default: [] | |
selector: | |
action: {} | |
mode: restart | |
max_exceeded: silent | |
trigger: | |
- platform: event | |
event_type: zha_event | |
event_data: | |
device_id: !input remote | |
action: | |
- variables: | |
media_player_entity: !input mediaplayer | |
secondary_media_player_entity: !input secondary_mediaplayer | |
command: '{{ trigger.event.data.command }}' | |
cluster_id: '{{ trigger.event.data.cluster_id }}' | |
endpoint_id: '{{ trigger.event.data.endpoint_id }}' | |
mode: '{% if command != ''toggle'' %} {{ trigger.event.data.args[0] }} {% endif %}' | |
steps: '{% if command != ''toggle'' %} {{ (trigger.event.data.args[1] / 12.5 ) | int }} {% endif %}' | |
step_percent: !input step_percent | |
secondary_step_percent: !input secondary_step_percent | |
media_player_is_on: "{{ states(media_player_entity.entity_id) not in ['off', 'unavailable'] }}" | |
secondary_media_player_is_on: "{{ states(secondary_media_player_entity.entity_id) not in ['off', 'unavailable'] }}" | |
- choose: | |
- conditions: | |
- '{{ cluster_id == 6 }}' | |
- '{{ endpoint_id == 1 }}' | |
- '{{ command == ''toggle'' }}' | |
sequence: !input single_press | |
########## When turning right | |
- conditions: | |
- '{{ cluster_id == 8 }}' | |
- '{{ endpoint_id == 1 }}' | |
- '{{ command == ''step'' }}' | |
- '{{ mode == ''StepMode.Up'' }}' | |
- '{{ media_player_is_on }}' | |
sequence: | |
- repeat: | |
while: | |
- condition: template | |
value_template: '{{ repeat.index < 2 }}' | |
sequence: | |
- service_template: media_player.volume_set | |
target: !input mediaplayer | |
data_template: | |
volume_level: > | |
{% set current_volume = state_attr(media_player_entity.entity_id, 'volume_level') | float %} | |
{% set volume_increment = step_percent / 100 %} | |
{% set new_volume = current_volume + volume_increment %} | |
{% set new_volume = new_volume if 0 <= new_volume <= 1 else 0 if new_volume < 0 else 1 %} | |
{{ new_volume }} | |
######### When turning left | |
- conditions: | |
- '{{ cluster_id == 8 }}' | |
- '{{ endpoint_id == 1 }}' | |
- '{{ command == ''step'' }}' | |
- '{{ mode == ''StepMode.Down'' }}' | |
- '{{ media_player_is_on }}' | |
sequence: | |
- repeat: | |
while: | |
- condition: template | |
value_template: '{{ repeat.index < 2 }}' | |
sequence: | |
- service_template: media_player.volume_set | |
target: !input mediaplayer | |
data_template: | |
volume_level: > | |
{% set current_volume = state_attr(media_player_entity.entity_id, 'volume_level') | float %} | |
{% set volume_increment = step_percent / 100 %} | |
{% set new_volume = current_volume - volume_increment %} | |
{% set new_volume = new_volume if 0 <= new_volume <= 1 else 0 if new_volume < 0 else 1 %} | |
{{ new_volume }} | |
######## When pressed and turniung right | |
- conditions: | |
- '{{ cluster_id == 768 }}' | |
- '{{ endpoint_id == 1 }}' | |
- '{{ command == ''step_color_temp'' }}' | |
- '{{ mode == ''StepMode.Up'' }}' | |
- '{{ secondary_media_player_is_on }}' | |
sequence: | |
- repeat: | |
while: | |
- condition: template | |
value_template: '{{ repeat.index < 2 }}' | |
sequence: | |
- service_template: media_player.volume_set | |
target: !input secondary_mediaplayer | |
data_template: | |
volume_level: > | |
{% set current_volume = state_attr(secondary_media_player_entity.entity_id, 'volume_level') | float %} | |
{% set volume_increment = step_percent / 100 %} | |
{% set new_volume = current_volume + volume_increment %} | |
{% set new_volume = new_volume if 0 <= new_volume <= 1 else 0 if new_volume < 0 else 1 %} | |
{{ new_volume }} | |
####### When pressed and turniung left | |
- conditions: | |
- '{{ cluster_id == 768 }}' | |
- '{{ endpoint_id == 1 }}' | |
- '{{ command == ''step_color_temp'' }}' | |
- '{{ mode == ''StepMode.Down'' }}' | |
- '{{ secondary_media_player_is_on }}' | |
sequence: | |
- repeat: | |
while: | |
- condition: template | |
value_template: '{{ repeat.index < 2 }}' | |
sequence: | |
- service_template: media_player.volume_set | |
target: !input secondary_mediaplayer | |
data_template: | |
volume_level: > | |
{% set current_volume = state_attr(secondary_media_player_entity.entity_id, 'volume_level') | float %} | |
{% set volume_increment = step_percent / 100 %} | |
{% set new_volume = current_volume - volume_increment %} | |
{% set new_volume = new_volume if 0 <= new_volume <= 1 else 0 if new_volume < 0 else 1 %} | |
{{ new_volume }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment