So recently I have gotten into using Music Assistant and enjoying it. The media player widget on my phone does a decent job to control but I thought I would try to emulate the lock screen widget of an android media player - to save time unlocking my phone etc.
The intended function is for it to appear once music is playing, and then go away once the MA player is turned off. Once working I thought it might be of use to others!
But there are two parts I just cannot figure out…
- how to get the title of the current song
- and more importantly, make the buttons work!
I’ve tried building the actionable part in several ways but none of them seem to register the button presses. The yaml as it is now is essentially copy/pasted from the most common templates on the web but no joy still… I scoured for dumb typos so many times but cannot see it, if it’s there! Any help would be appreciated
alias: Music Notifications
description: ""
trigger:
- platform: state
entity_id:
- media_player.denon_avr_ma
to: playing
id: musicon
- platform: state
entity_id:
- media_player.denon_avr_ma
to: "off"
id: musicoff
condition: []
action:
- choose:
- conditions:
- condition: trigger
id:
- musicon
sequence:
- variables:
action_previous: "{{ 'PREVIOUS_' ~ context.id }}"
action_play: "{{ 'PLAY_' ~ context.id }}"
action_next: "{{ 'NEXT_' ~ context.id }}"
- service: notify.mobile_app_galaxy_s20
data:
title: Music Assistant
message: Song
data:
channel: Music Notifications
clickAction: /d5369777_music_assistant_beta
sticky: true
persistent: true
notification_icon: mdi:audio-video
tag: musicon
actions:
- action: "{{ action_previous }}"
title: Previous
- action: "{{ action_play }}"
title: Play/Pause
- action: "{{ action_next }}"
title: Next
- conditions:
- condition: trigger
id:
- musicoff
sequence:
- service: notify.mobile_app_galaxy_s20
data:
message: clear_notification
data:
tag: musicon
- wait_for_trigger:
- platform: event
event_type: mobile_app_notification_action
event_data:
action: "{{ action_previous }}"
- platform: event
event_type: mobile_app_notification_action
event_data:
action: "{{ action_play }}"
- platform: event
event_type: mobile_app_notification_action
event_data:
action: "{{ action_next }}"
- choose:
- conditions: "{{ wait.trigger.event.data.action == action_previous }}"
sequence:
- service: media_player.media_previous_track
target:
entity_id: media_player.denon_avr_ma
data: {}
- conditions: "{{ wait.trigger.event.data.action == action_play }}"
sequence:
- service: media_player.media_play_pause
target:
entity_id: media_player.denon_avr_ma
data: {}
- conditions: "{{ wait.trigger.event.data.action == action_next }}"
sequence:
- service: media_player.media_next_track
target:
entity_id: media_player.denon_avr_ma
data: {}
mode: restart