[Custom Component] extended_openai_conversation: Let's control entities via ChatGPT

Hi there, Hi @sayanova ,
it works with this simplification:

- spec:
    name: play_music
    description: Play music.
    parameters:
      type: object
      properties:
        media_player_id:
          type: array
          items:
            type: string
          description: List of media player Entity IDs to play
        media_id:
          type: string
          description: Media identifier (URI)
        media_type:
          type: string
          optional: true
          enum: ["artist", "album", "playlist", "track", "radio"]
          description: Will be auto-determined if omitted
        enqueue:
          type: string
          enum: ["play", "replace", "next", "replace_next", "add"]
          optional: true
          description: How to enqueue the media
        announce:
          type: boolean
          optional: true
          description: Whether to make an announcement
        artist:
          type: string
          optional: true
          description: Specify the artist
        album:
          type: string
          optional: true
          description: Specify the album
        radio_mode:
          type: boolean
          optional: true
          description: Specify if it is a radio mode.
      required:
        - media_player_id
        - media_id
  function:
    type: script
    sequence:
      - service: mass.play_media
        target:
          entity_id: "{{ media_player_id }}"
        data:
          media_id: "{{ media_id }}"

Problem is the template data, but i donā€™t know how to format it

hi @jekalmin
there is still some problem,
Probably in retrieving the query to the script,
When I tell it to run album X for my player, it runs the script but without the text of the query,
(no error message appears in the log)
Thanks

You can use json and jinja2 template like this

      - service: mass.play_media
        target:
          entity_id: "{{ media_player_id }}"
        data: >
          {
            media_id: "{{ media_id }}"
            media_type: "{{ media_type }}"
            {% if enqueue is defined and enqueue %}
            enqueue: "{{ enqueue }}"
            {% endif %}
            {% if announce is defined and announce %}
            announce: "{{ announce }}"
            {% endif %}
            {% if artist is defined and artist %}
            artist: "{{ artist }}"
            {% endif %}
            {% if album is defined and album %}
            album: "{{ album }}"
            {% endif %}
            {% if radio_mode is defined and radio_mode %}
            radio_mode: "{{ radio_mode }}"
            {% endif %}
          }

I canā€™t get the template to work, I always get this error:

2023-12-19 09:25:09.439 ERROR (MainThread) [custom_components.extended_openai_conversation.helpers] extended_openai_conversation: Error executing script. Error for call_service at pos 1: Error rendering data template: Result is not a Dictionary

I know that you donā€™t have any speakers to test, so donā€™t worry :slight_smile:

@jekalmin
I updated the plugin to the latest version,
And it works great.

Thank you

1 Like

Happy to hear that!
I just released 0.0.9, and it will log when error occurs.
Please let me know if there are any issues.

Can you share a function you have so far?

yep!
This one is working:

- spec:
    name: play_music
    description: Play music.
    parameters:
      type: object
      properties:
        media_player_id:
          type: array
          items:
            type: string
          description: List of media player Entity IDs to play
        media_id:
          type: string
          description: Media identifier (URI)
        media_type:
          type: string
          optional: true
          enum: ["artist", "album", "playlist", "track", "radio"]
          description: Will be auto-determined if omitted
        enqueue:
          type: string
          enum: ["play", "replace", "next", "replace_next", "add"]
          optional: true
          description: How to enqueue the media
        announce:
          type: boolean
          optional: true
          description: Whether to make an announcement
        artist:
          type: string
          optional: true
          description: Specify the artist
        album:
          type: string
          optional: true
          description: Specify the album
        radio_mode:
          type: boolean
          optional: true
          description: Specify if it is a radio mode.
      required:
        - media_player_id
        - media_id
  function:
    type: script
    sequence:
      - service: mass.play_media    
        target:
          entity_id: "{{ media_player_id }}"
        data:
            media_id: "{{ media_id }}"
1 Like

Is there any way to integrate this with Alexa? I know itā€™s not specific to this integration but maybe someone has already done this.

Hi Everyone,

I donā€™t see this Custom Component in HACS. Are you guys manually installing it?

Hello everyone I am getting the following error

Sorry, I had a problem talking to OpenAI: Request too large for gpt-3.5-turbo in organization org-1mxR4GLwpDM6ylDJIQ0S1sgS on tokens_usage_based per min: Limit 60000, Requested 131729. Visit https://platform.openai.com/account/rate-limits to learn more.

Can anyone tell me what I should do?

You have to install
https://github.com/jekalmin/extended_openai_conversation
as custom repository in HACS (check the menu in the right upper corner.

Thanks @dodger for a reply.

As @dodger said, currently you have to add as a custom repository in HACS.
It will be added to HACS soon.

I will comment again when itā€™s added (Adds new integration [jekalmin/extended_openai_conversation] by jekalmin Ā· Pull Request #2254 Ā· hacs/default Ā· GitHub)

Unfortunately, itā€™s not working with Alexa.

Could you add logging and see how it is requested?

This might be caused by exposing too many entities.
Go to http://{your-home-assistant}/config/voice-assistants/expose and see how many entities are exposed.

1 Like

I tried but it says

It is not an addon of hassio, but a custom repository of HACS.
This youtube might help.

1 Like

Iā€™m trying to install in, both via hacs (open reposotory) and manually adding the files to the costom content folder. I have cleard the cashe but its not really working. Trough hacs after the restart its not there anymore and I cant find it in devices and servicesā€¦

When I tried just adding the folder direct, restart but still nothing in devises and servies. What am I duing wrong?

@stban1983 , you mentioned this code was working - which is exciting - but so far I have not figured out how to do so. What is required to get the media player to work with this component? So far it does not actually play the media for me.

So far I have installed and configured OpenAI Extended, connected it with ChatGPT, set it as default Voice Assistant, included the prompt provided by the developer, and have added many of the spec functions from his readme on github as well as from this forum thread including the one you have provided above. Iā€™ve installed and configured the Home Assistant Music Assistant integration through HACS, using the latest beta version (2.0.0b80) since Iā€™m on a more recent version of HASS (2024.1.2).
The Voice Assistant seems to understand my requests and tells me that music is playing on the requested media player, but no media plays. Iā€™ve tried this with various media on various players.

Iā€™ve been able to play this media through the HA Media Assistant GUI to the designated speakers without issue.
Thank you for any guidance on how to troubleshoot.
Ari

not simple to help youā€¦
First, test the service mass.play_media directly form the developper tools view.

  - service: mass.play_media    
    target:
      entity_id: media_player.xxxx
    data:
        media_id: MyFavoriteArtist

Does it play songs ?

1 Like