GithubHelp home page GithubHelp logo

Comments (3)

FoliniC avatar FoliniC commented on May 26, 2024 1

Hi Jekal, it worked!!!
I use home assistant from internet (using ngrok) so I use rest.
To get all the entities I tried with postman using {{base_url}}/states
Is it correct to configure the call like this?

  • spec:
    name: get_states
    description: Get entity list
    parameters:
    type: object
    function:
    type: rest
    resource_template: "https://myid.ngrok-free.app/api/states"
    value_template: "{{ value_json.states }}"
    headers:
    Authorization: ""

from extended_openai_conversation.

jekalmin avatar jekalmin commented on May 26, 2024

Thanks for reporting an issue!

How can I map a particular prompt to use REST function?

You can register a function to gpt, and it automatically decides what data or function to use. There are a few function types (including REST) you can use in this integration.

What I want to achieve is to get temperature from a particular sensor, in your docs I see that is possible to use REST

Are you trying to get sensor from another remote HA or local HA?

  1. If local, you can access the state of sensor easily just by exposing entities.

  2. If it's remote, you will have to add a rest function like below.

- spec:
    name: get_state
    description: Get state of entity
    parameters:
      type: object
      properties:
        entity_id:
          type: string
          description: The entity id.
  function:
    type: rest
    resource_template: "https://YOUR_BASE_URL/api/states/{{entity_id}}"
    value_template: "{{ value_json.state }}"
    headers:
      Authorization: "Bearer YOUR_TOKEN"

You have to replace YOUR_BASE_URL and YOUR_TOKEN with your data.
Since only spec part is passed to OpenAI, you don't have to let OpenAI know what url and token are.
Let OpenAI decide what entity_id from what you asked, which enables you to use entity_id from rest function.

from extended_openai_conversation.

jekalmin avatar jekalmin commented on May 26, 2024

Since /api/states returns a list of entities, you have to iterate over value_json.
Also, since all entities are returned, maybe you have to limit the number of entities.
The more entities returned, the more costs.

- spec:
    name: get_entities
    description: Get entity list
    parameters:
      type: object
      properties:
        dummy:
          type: string
          description: Nothing
  function:
    type: rest
    resource_template: "YOUR_BASE_URL/api/states"
    headers:
      Authorization: "Bearer YOUR_TOKEN"
    value_template: >-
      ```csv
      entity_id,name,state
      {% for entity in value_json -%}
        {% if loop.index < 3 -%}
        {{ entity['entity_id'] }},"{{ entity['attributes']['friendly_name'] }}",{{ entity['state'] }}
        {% endif -%}
      {% endfor -%}
      ```

from extended_openai_conversation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.