Files
spotify-voice-assistant/examples/extended_openai_functions.yaml
Chad Auld 3c4d9891e1 Fix template syntax in control_playback function
Use shorthand template syntax for conditions in Extended OpenAI Conversation function scripts instead of verbose condition: template format.
2025-11-22 12:34:56 -07:00

189 lines
6.5 KiB
YAML

# Extended OpenAI Conversation Function Configuration
# Add these to your existing Extended OpenAI Conversation integration function configuration.
# NOTE: Ensure that the native function 'execute_service' is defined in your Home Assistant instance.
# If so, skip this one and just grab the other functions below to add.
- spec:
name: execute_services
description: Use this function to execute service of devices in Home Assistant.
parameters:
type: object
properties:
list:
type: array
items:
type: object
properties:
domain:
type: string
description: The domain of the service
service:
type: string
description: The service to be called
service_data:
type: object
description: The service data object to indicate what to control.
properties:
entity_id:
type: string
description: The entity_id retrieved from available devices.
required:
- entity_id
required:
- domain
- service
- service_data
function:
type: native
name: execute_service
# Spotify Music Control Functions
- spec:
name: search_spotify
description: Search Spotify for an artist, album, track, or playlist and return the Spotify URI. Use this before playing music to get the URI.
parameters:
type: object
properties:
query:
type: string
description: Artist, album, track, or playlist name to search for (e.g., "Coldplay", "Parachutes", "Yellow", "Today's Top Hits")
type:
type: string
enum: [artist, album, track, playlist]
description: Type of content to search for. Playlist searches check your personal playlists first, then fall back to public Spotify playlists.
required:
- query
- type
function:
type: script
sequence:
- service: spotify_voice_assistant.search
response_variable: _function_result
data:
query: "{{ query }}"
type: "{{ type }}"
- spec:
name: play_music
description: Play music immediately on a Spotify Connect device using a Spotify URI, replacing current playback. You must first call search_spotify to get the URI. Use this when user says "play".
parameters:
type: object
properties:
spotify_uri:
type: string
description: Spotify URI from search_spotify (e.g., "spotify:artist:4gzpq5DPGxSnKTe4SA8HAU")
media_player:
type: string
description: Entity ID of Spotify Connect media player (e.g., "media_player.kitchen_speaker")
required:
- spotify_uri
- media_player
function:
type: script
sequence:
- service: media_player.play_media
target:
entity_id: "{{ media_player }}"
data:
media_content_id: "{{ spotify_uri }}"
media_content_type: "music"
enqueue: replace
- spec:
name: queue_music
description: Add music to the queue on a Spotify Connect device using a Spotify URI, without interrupting current playback. You must first call search_spotify to get the URI. Use this when user says "queue" or "add to queue".
parameters:
type: object
properties:
spotify_uri:
type: string
description: Spotify URI from search_spotify (e.g., "spotify:artist:4gzpq5DPGxSnKTe4SA8HAU")
media_player:
type: string
description: Entity ID of Spotify Connect media player (e.g., "media_player.kitchen_speaker")
required:
- spotify_uri
- media_player
function:
type: script
sequence:
- service: media_player.play_media
target:
entity_id: "{{ media_player }}"
data:
media_content_id: "{{ spotify_uri }}"
media_content_type: "music"
enqueue: add
- spec:
name: control_playback
description: Control music playback (pause, resume, stop, next track, previous track, set volume, shuffle)
parameters:
type: object
properties:
action:
type: string
enum: [pause, play, stop, next_track, previous_track, volume_set, shuffle_on, shuffle_off]
description: Playback control action
media_player:
type: string
description: Entity ID of media player
volume_level:
type: number
description: Volume level (0-100) for volume_set action only
required:
- action
- media_player
function:
type: script
sequence:
- choose:
- conditions: "{{ action == 'pause' }}"
sequence:
- service: media_player.media_pause
target:
entity_id: "{{ media_player }}"
- conditions: "{{ action == 'play' }}"
sequence:
- service: media_player.media_play
target:
entity_id: "{{ media_player }}"
- conditions: "{{ action == 'stop' }}"
sequence:
- service: media_player.media_stop
target:
entity_id: "{{ media_player }}"
- conditions: "{{ action == 'next_track' }}"
sequence:
- service: media_player.media_next_track
target:
entity_id: "{{ media_player }}"
- conditions: "{{ action == 'previous_track' }}"
sequence:
- service: media_player.media_previous_track
target:
entity_id: "{{ media_player }}"
- conditions: "{{ action == 'volume_set' }}"
sequence:
- service: media_player.volume_set
target:
entity_id: "{{ media_player }}"
data:
volume_level: "{{ volume_level / 100 }}"
- conditions: "{{ action == 'shuffle_on' }}"
sequence:
- service: media_player.shuffle_set
target:
entity_id: "{{ media_player }}"
data:
shuffle: true
- conditions: "{{ action == 'shuffle_off' }}"
sequence:
- service: media_player.shuffle_set
target:
entity_id: "{{ media_player }}"
data:
shuffle: false