Description
A while back I made a notification to show the current song playing in Music Assistant and allow basic controls. I am pleased it attracted a little bit of attention but was far from perfect. I have now tried to fix some problems and recreate it as a blueprint - it is still incredibly basic given my complete lack of coding ability but hopefully others will find it to be of use!
Once a song starts playing, it should generate a silent notification with the current song artist/title, with previous, play/pause, next buttons. The notification will also disappear if the current player is turned off.
Future ideas?
I did try to allow easier selection of a mobile device via a drop down box, and include album art, but could not make either of these ideas successfully function.
I also do not have an Apple device to test on, so have no idea if it would work at all!
I also suspect the yaml could also be constructed in a much better fashion…
If anybody is interested enough to be able to suggest fixes or other features, I am all ears
blueprint:
name: Music Assistant Actionable Notifications
description: >
Sends an actionable notification to your phone when Music Assistant is playing.
domain: automation
input:
media_player_entity:
name: Music Assistant Player Entity
selector:
entity:
domain: media_player
mobile_app_service:
name: Mobile App Notification Service
description: The full notification service name for your mobile device, e.g. notify.mobile_app_your_device_name
default: notify.mobile_app_your_device_name
selector:
text:
music_assistant_dashboard_path:
name: Music Assistant Dashboard Path
description: The path to your Music Assistant dashboard in order to open it on clicking the notification.
default: /music_assistant
selector:
text:
mode: restart
triggers:
- entity_id: !input media_player_entity
id: musicon
to:
- playing
- paused
trigger: state
- entity_id: !input media_player_entity
to: "off"
id: musicoff
trigger: state
conditions: []
actions:
- variables:
action_previous: "{{ 'PREVIOUS_' ~ context.id }}"
action_play: "{{ 'PLAY_' ~ context.id }}"
action_next: "{{ 'NEXT_' ~ context.id }}"
- choose:
- conditions:
- condition: trigger
id:
- musicon
sequence:
- data:
title: Music Assistant
message: >-
{{ trigger.to_state.attributes.media_artist }} -
{{ trigger.to_state.attributes.media_title }}
data:
channel: Music Notifications
clickAction: !input music_assistant_dashboard_path
sticky: true
persistent: true
actions:
- action: "{{ action_previous }}"
title: Previous
- action: "{{ action_play }}"
title: Play/Pause
- action: "{{ action_next }}"
title: Next
notification_icon: mdi:audio-video
tag: musicon
action: !input mobile_app_service
- conditions:
- condition: trigger
id:
- musicoff
sequence:
- data:
message: clear_notification
data:
tag: musicon
action: !input mobile_app_service
- wait_for_trigger:
- event_type: mobile_app_notification_action
event_data:
action: "{{ action_previous }}"
trigger: event
- event_type: mobile_app_notification_action
event_data:
action: "{{ action_play }}"
trigger: event
- event_type: mobile_app_notification_action
event_data:
action: "{{ action_next }}"
trigger: event
- choose:
- conditions:
- condition: template
value_template: "{{ wait.trigger.event.data.action == action_previous }}"
sequence:
- target:
entity_id: !input media_player_entity
data: {}
action: media_player.media_previous_track
- conditions:
- condition: template
value_template: "{{ wait.trigger.event.data.action == action_play }}"
sequence:
- target:
entity_id: !input media_player_entity
data: {}
action: media_player.media_play_pause
- conditions:
- condition: template
value_template: "{{ wait.trigger.event.data.action == action_next }}"
sequence:
- target:
entity_id: !input media_player_entity
data: {}
action: media_player.media_next_track