241 lines
7.0 KiB
YAML
241 lines
7.0 KiB
YAML
- alias: Jukebox - Notify of Queued Song
|
|
description: Tells home assistant that someone has requested a song and to switch
|
|
the queueing mode for guests for further requests
|
|
triggers:
|
|
- trigger: webhook
|
|
allowed_methods:
|
|
- POST
|
|
- GET
|
|
local_only: false
|
|
webhook_id: < YOUR WEBHOOK ID HERE >
|
|
conditions: []
|
|
actions:
|
|
- action: input_boolean.turn_on
|
|
metadata: {}
|
|
data: {}
|
|
target:
|
|
entity_id: input_boolean.jukebox_queue
|
|
- alias: Jukebox - Set Default Playlist when Jukebox Queue is zero
|
|
description: Once the guests queued songs are all played, play the default party
|
|
playlist so the music doesnt stop
|
|
triggers:
|
|
- trigger: state
|
|
entity_id:
|
|
- input_number.jukebox_queue_length
|
|
to: '1.0'
|
|
conditions: []
|
|
actions:
|
|
- action: input_boolean.turn_off
|
|
metadata: {}
|
|
data: {}
|
|
target:
|
|
entity_id: input_boolean.jukebox_queue
|
|
- action: media_player.shuffle_set
|
|
metadata: {}
|
|
data:
|
|
shuffle: true
|
|
target:
|
|
entity_id: media_player.<YOUR MEDIA PLAYER HERE>
|
|
- action: music_assistant.play_media
|
|
metadata: {}
|
|
data:
|
|
enqueue: play
|
|
media_id: <YOUR DEFAULT PARTY PLAYLIST NAME HERE>
|
|
media_type: playlist
|
|
target:
|
|
entity_id: media_player.<YOUR MEDIA PLAYER HERE>
|
|
mode: single
|
|
- alias: Jukebox - Switch Jukebox Access on/off
|
|
description: Controls access to the jukebox by enableing the app and provisioning
|
|
an access token or disabling the app and revoking any active token
|
|
triggers:
|
|
- trigger: state
|
|
entity_id:
|
|
- input_boolean.songrequestaccess
|
|
from: 'off'
|
|
to: 'on'
|
|
- trigger: state
|
|
entity_id:
|
|
- input_boolean.songrequestaccess
|
|
from: 'on'
|
|
to: 'off'
|
|
conditions: []
|
|
actions:
|
|
- if:
|
|
- condition: state
|
|
entity_id: input_boolean.songrequestaccess
|
|
state: 'on'
|
|
then:
|
|
- action: shell_command.create_jukebox_token
|
|
metadata: {}
|
|
data: {}
|
|
- action: input_boolean.turn_off
|
|
metadata: {}
|
|
data: {}
|
|
target:
|
|
entity_id: input_boolean.jukebox_queue
|
|
else:
|
|
- action: shell_command.delete_jukebox_token
|
|
metadata: {}
|
|
data: {}
|
|
mode: single
|
|
- alias: Jukebox - Track Queue Size
|
|
description: Keeps track of the media player queue length and updates the Jukebox
|
|
Queue Length helper
|
|
triggers:
|
|
- trigger: state
|
|
entity_id:
|
|
- media_player.<YOUR MEDIA PLAYER HERE>
|
|
attribute: media_position_updated_at
|
|
conditions: []
|
|
actions:
|
|
- action: music_assistant.get_queue
|
|
metadata: {}
|
|
data: {}
|
|
target:
|
|
entity_id: media_player.<YOUR MEDIA PLAYER HERE>
|
|
response_variable: jukeboxqueuedetail
|
|
- variables:
|
|
speaker_data: '{{ jukeboxqueuedetail[''media_player.<YOUR MEDIA PLAYER HERE>'']
|
|
}}'
|
|
- variables:
|
|
items_count: '{% set matches = speaker_data | regex_findall("''items'': (\d+)")
|
|
%} {{ matches[0] if matches else 0 }}'
|
|
current_index: '{% set matches = speaker_data | regex_findall("''current_index'':
|
|
(\d+)") %} {{ matches[0] if matches else 0 }}'
|
|
remaining: '{{ (items_count | int) - (current_index | int) }}'
|
|
- action: input_number.set_value
|
|
target:
|
|
entity_id: input_number.jukebox_queue_length
|
|
data:
|
|
value: '{{ remaining | float }}'
|
|
mode: queued
|
|
max: 10
|
|
- alias: JukeBox Controller
|
|
description: "Keeps control of the jukebox\n\nInstructions:\nBefore use remember\
|
|
\ to change the media_player in the first trigger \nand put the defined variable\
|
|
\ media_player to the same player\nYou should also update the default playlist\
|
|
\ variable to the playlist you want to use\n\nWhat the automation does\n\n- Keeps\
|
|
\ the queue counter updated\n- Stops the playback when Access is disabled\n- Does\
|
|
\ something to the queue switch, but not sure what it is \n used for"
|
|
triggers:
|
|
- trigger: state
|
|
entity_id:
|
|
- media_player.tablet_stue
|
|
attribute: media_position_updated_at
|
|
id: Position Updated
|
|
- trigger: state
|
|
entity_id:
|
|
- switch.music_assistant_jukebox_jukebox_allow_access
|
|
from: 'off'
|
|
to: 'on'
|
|
id: Access enabled
|
|
- trigger: webhook
|
|
allowed_methods:
|
|
- POST
|
|
- PUT
|
|
local_only: true
|
|
webhook_id: -notify_queue_of_song
|
|
id: Webhook
|
|
- trigger: state
|
|
entity_id:
|
|
- number.music_assistant_jukebox_jukebox_queue_length
|
|
to: '0'
|
|
id: Playlist finished
|
|
- trigger: state
|
|
entity_id:
|
|
- switch.music_assistant_jukebox_jukebox_allow_access
|
|
from: 'on'
|
|
to: 'off'
|
|
id: Access disabled
|
|
conditions: []
|
|
actions:
|
|
- variables:
|
|
media_player: media_player.tablet_stue
|
|
default_playlist: Jukebox
|
|
- choose:
|
|
- conditions:
|
|
- condition: trigger
|
|
id:
|
|
- Position Updated
|
|
sequence:
|
|
- action: music_assistant.get_queue
|
|
metadata: {}
|
|
data: {}
|
|
target:
|
|
entity_id: media_player.tablet_stue
|
|
response_variable: jukeboxqueuedetail
|
|
- variables:
|
|
speaker_data: '{{ jukeboxqueuedetail[''media_player.tablet_stue''] }}'
|
|
- variables:
|
|
items_count: '{% set matches = speaker_data | regex_findall("''items'':
|
|
(\d+)") %} {{ matches[0] if matches else 0 }}'
|
|
current_index: '{% set matches = speaker_data | regex_findall("''current_index'':
|
|
(\d+)") %} {{ matches[0] if matches else 0 }}'
|
|
remaining: '{{ (items_count | int) - (current_index | int) }}'
|
|
- action: input_number.set_value
|
|
data:
|
|
value: '{{ remaining }}'
|
|
target:
|
|
entity_id: number.music_assistant_jukebox_jukebox_queue_length
|
|
- conditions:
|
|
- condition: trigger
|
|
id:
|
|
- Access enabled
|
|
sequence:
|
|
- action: switch.turn_off
|
|
metadata: {}
|
|
data: {}
|
|
target:
|
|
entity_id: switch.music_assistant_jukebox_jukebox_queue
|
|
- conditions:
|
|
- condition: trigger
|
|
id:
|
|
- Webhook
|
|
sequence:
|
|
- action: switch.turn_on
|
|
metadata: {}
|
|
data: {}
|
|
target:
|
|
entity_id: switch.music_assistant_jukebox_jukebox_queue
|
|
- conditions:
|
|
- condition: trigger
|
|
id:
|
|
- Playlist finished
|
|
- condition: state
|
|
entity_id: input_boolean.song_request_access
|
|
state: 'on'
|
|
sequence:
|
|
- action: switch.turn_off
|
|
metadata: {}
|
|
data: {}
|
|
target:
|
|
entity_id: switch.music_assistant_jukebox_jukebox_queue
|
|
- action: music_assistant.play_media
|
|
metadata: {}
|
|
data:
|
|
enqueue: replace
|
|
media_id: '{{ default_playlist }}'
|
|
media_type: playlist
|
|
target:
|
|
entity_id: '{{ media_player }}'
|
|
- conditions:
|
|
- condition: trigger
|
|
id:
|
|
- Access disabled
|
|
sequence:
|
|
- action: media_player.media_stop
|
|
metadata: {}
|
|
data: {}
|
|
target:
|
|
entity_id: '{{ media_player }}'
|
|
- action: switch.turn_off
|
|
metadata: {}
|
|
data: {}
|
|
target:
|
|
entity_id:
|
|
- switch.music_assistant_jukebox_jukebox_allow_access
|
|
- switch.music_assistant_jukebox_jukebox_queue
|
|
mode: queued
|
|
max: 10
|