diff --git a/home-assistant.yml b/home-assistant.yml index 9711ca4..201aa51 100644 --- a/home-assistant.yml +++ b/home-assistant.yml @@ -35,6 +35,16 @@ name: Desk Lightbar - entityId: light.office name: Table lamp + - name: Build music button automations + delegate_to: localhost + template: + src: music-button.yaml.j2 + dest: './build/automations/music.yaml' + vars: + room: Bathroom + room_id: bathroom + device_id: ea9059ad2df037a012ab01a575108dc5 + player_entity_id: media_player.bathroom - name: Include ZHA vars include_vars: file: zha-devices.yml diff --git a/templates/music-button.yaml.j2 b/templates/music-button.yaml.j2 new file mode 100644 index 0000000..43dd62d --- /dev/null +++ b/templates/music-button.yaml.j2 @@ -0,0 +1,80 @@ +- id: {{ room_id }}_music_button + alias: "[{{ room }}] Music button" + mode: single + trigger: + - platform: event + event_type: zha_event + event_data: + device_id: {{ device_id }} + condition: [ ] + action: + - choose: + - conditions: +{% raw %} + - condition: template + value_template: "{{ trigger.event.data.command == 'toggle' }}" + - condition: template + value_template: "{{ trigger.event.data.cluster_id == 6 }}" + - condition: template + value_template: "{{ trigger.event.data.endpoint_id == 1 }}" +{% endraw %} + sequence: + - service: media_player.media_play_pause + target: + entity_id: {{ player_entity_id }} + - conditions: +{% raw %} + - condition: template + value_template: "{{ trigger.event.data.command == 'step' }}" + - condition: template + value_template: "{{ trigger.event.data.cluster_id == 8 }}" + - condition: template + value_template: "{{ trigger.event.data.endpoint_id == 1 }}" + - condition: template + value_template: "{{ trigger.event.data.params.step_mode == 0 }}" +{% endraw %} + sequence: + - service: media_player.media_next_track + entity_id: {{ player_entity_id }} + - conditions: +{% raw %} + - condition: template + value_template: "{{ trigger.event.data.command == 'step' }}" + - condition: template + value_template: "{{ trigger.event.data.cluster_id == 8 }}" + - condition: template + value_template: "{{ trigger.event.data.endpoint_id == 1 }}" + - condition: template + value_template: "{{ trigger.event.data.params.step_mode == 1 }}" +{% endraw %} + sequence: + - service: media_player.media_previous_track + entity_id: {{ player_entity_id }} + - conditions: +{% raw %} + - condition: template + value_template: "{{ trigger.event.data.command == 'move_with_on_off' }}" + - condition: template + value_template: "{{ trigger.event.data.cluster_id == 8 }}" + - condition: template + value_template: "{{ trigger.event.data.endpoint_id == 1 }}" + - condition: template + value_template: "{{ trigger.event.data.params.move_mode == 0}}" +{% endraw %} + sequence: + - service: media_player.volume_up + entity_id: {{ player_entity_id }} + - conditions: +{% raw %} + - condition: template + value_template: "{{ trigger.event.data.command == 'move_with_on_off' }}" + - condition: template + value_template: "{{ trigger.event.data.cluster_id == 8 }}" + - condition: template + value_template: "{{ trigger.event.data.endpoint_id == 1 }}" + - condition: template + value_template: "{{ trigger.event.data.params.move_mode == 1 }}" +{% endraw %} + sequence: + - service: media_player.volume_down + entity_id: {{ player_entity_id }}