jekalmin / extended_openai_conversation

Home Assistant custom component of conversation agent. It uses OpenAI to control your devices.
834 stars 108 forks source link

Added device_id to script function arguments #172

Open DevelopIdeas opened 3 months ago

DevelopIdeas commented 3 months ago

Allows for use of device_id inside service / script functions Screenshot 2024-03-14 at 23 55 30

jekalmin commented 3 months ago

Thanks for your contribution!

I agree that it would be a nice feature to make device_id available to use in functions. However, it would override device_id if it's used in parameters of spec.

I think it would be better if we change two things:

  1. Create reserved word which contains any data, such as user_input or exposed_entities, needed for users. The reserved word can be something like _params, _args, or word starting with _, so that it reduces possibility of conflict. Then your function should look like this.

    - service: python_script.play_music
      data:
        device_id: '{{_params.user_input.device_id}}'
        ...
  2. Make it available not only to script function but also to any functions. (Probably move your code to here and here would work)