> ## Documentation Index
> Fetch the complete documentation index at: https://extended-openai-conversation.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Native Functions

> Built-in functions provided by Extended OpenAI Conversation

Native functions are built-in capabilities provided directly by the Extended OpenAI Conversation component. These functions are implemented in Python and offer core functionality.

## Available Native Functions

### execute\_service

Call any Home Assistant service with specified parameters.

<ParamField path="domain" type="string" required>
  The domain of the service (e.g., `light`, `switch`, `climate`)
</ParamField>

<ParamField path="service" type="string" required>
  The service to call (e.g., `turn_on`, `turn_off`, `set_temperature`)
</ParamField>

<ParamField path="service_data" type="object" required>
  Service data object with the following properties:

  * `entity_id` (string): Target entity ID
  * `device_id` (string): Target device ID (optional)
  * `area_id` (string): Target area ID (optional)
</ParamField>

<Accordion title="Example Configuration">
  Control Home Assistant devices and services:

  ```yaml theme={null}
  - 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. It must start with domain, followed by dot character.
                  required:
                  - entity_id
              required:
              - domain
              - service
              - service_data
    function:
      type: native
      name: execute_service
  ```
</Accordion>

### add\_automation

Create Home Assistant automations dynamically through conversation.

<Warning>
  Before using this function, set up notifications for the `automation_registered_via_extended_openai_conversation` event. Automations can be created even if the conversation fails to get a response.
</Warning>

<ParamField path="automation_config" type="string" required>
  Automation configuration in valid YAML format. Newline characters should be `\n`.
</ParamField>

<Accordion title="Setup Recommendations">
  1. **Create a separate assistant** for automation creation to avoid accidental automation registration
  2. **Set up event notifications** to monitor created automations
  3. **Review automations** before enabling them in production

  <Columns cols={2}>
    <div>
      **Create Separate Assistant**

      <Frame>
        <img width="830" alt="Create Assistant" src="https://github.com/jekalmin/extended_openai_conversation/assets/2917984/b7030a46-9a4e-4ea8-a4ed-03d2eb3af0a9" />
      </Frame>
    </div>

    <div>
      **Notify on Created**

      <Frame>
        <img width="1116" alt="Notification Setup" src="https://github.com/jekalmin/extended_openai_conversation/assets/2917984/7afa3709-1c1d-41d0-8847-70f2102d824f" />
      </Frame>
    </div>
  </Columns>
</Accordion>

<Accordion title="Example Configuration">
  **English Configuration:**

  ```yaml theme={null}
  - spec:
      name: add_automation
      description: Use this function to add an automation in Home Assistant.
      parameters:
        type: object
        properties:
          automation_config:
            type: string
            description: A configuration for automation in a valid yaml format. Next line character should be \n. Use devices from the list.
        required:
        - automation_config
    function:
      type: native
      name: add_automation
  ```

  **Korean Configuration:**

  For Korean language, use `\\n` instead of `\n` for newline characters:

  ```yaml theme={null}
  - spec:
      name: add_automation
      description: Use this function to add an automation in Home Assistant.
      parameters:
        type: object
        properties:
          automation_config:
            type: string
            description: A configuration for automation in a valid yaml format. Next line character should be \\n, not \n. Use devices from the list.
        required:
        - automation_config
    function:
      type: native
      name: add_automation
  ```

  <Frame>
    <img width="300" alt="Automation Example" src="https://github.com/jekalmin/extended_openai_conversation/assets/2917984/55f5fe7e-b1fd-43c9-bce6-ac92e203598f" />
  </Frame>
</Accordion>

### get\_history

Retrieve historical state data for specified entities.

<ParamField path="entity_ids" type="array" required>
  List of entity IDs to retrieve history for
</ParamField>

<ParamField path="start_time" type="string">
  Start of the history period in `%Y-%m-%dT%H:%M:%S%z` format. Defaults to 1 day before the request time.
</ParamField>

<ParamField path="end_time" type="string">
  End of the history period in `%Y-%m-%dT%H:%M:%S%z` format. Defaults to current time.
</ParamField>

<ParamField path="minimal_response" type="boolean">
  Only return `last_changed` and `state` for non-first/last states. Default: `true`
</ParamField>

<ParamField path="no_attributes" type="boolean">
  Skip returning attributes from the database. Default: `true`
</ParamField>

<ParamField path="significant_changes_only" type="boolean">
  Only return significant state changes. Default: `true`
</ParamField>

<Accordion title="Example Configuration">
  Retrieve historical state data for entities. For advanced formatting with templates, see the [composite function example](/functions/composite#example-get-history-with-formatting).

  ```yaml theme={null}
  - spec:
      name: get_history
      description: Retrieve historical data of specified entities.
      parameters:
        type: object
        properties:
          entity_ids:
            type: array
            items:
              type: string
              description: The entity id to filter.
          start_time:
            type: string
            description: Start of the history period in "%Y-%m-%dT%H:%M:%S%z".
          end_time:
            type: string
            description: End of the history period in "%Y-%m-%dT%H:%M:%S%z".
          minimal_response:
            type: boolean
            description: Only return last_changed and state for non-first/last states.
          no_attributes:
            type: boolean
            description: Skip returning attributes from the database.
          significant_changes_only:
            type: boolean
            description: Only return significant state changes.
        required:
        - entity_ids
    function:
      type: native
      name: get_history
  ```

  <Frame>
    <img width="300" alt="History Example" src="https://github.com/jekalmin/extended_openai_conversation/assets/2917984/32217f3d-10fc-4001-9028-717b1683573b" />
  </Frame>
</Accordion>

### get\_energy

Retrieve energy configuration and preferences from Home Assistant's energy management system.

<Info>
  This function returns the energy dashboard configuration including solar, grid, battery, and gas sources. No parameters required.
</Info>

<Accordion title="Example Configuration">
  Retrieve energy management configuration:

  ```yaml theme={null}
  - spec:
      name: get_energy
      description: Retrieve energy management configuration and preferences.
      parameters:
        type: object
        properties: {}
    function:
      type: native
      name: get_energy
  ```
</Accordion>

### get\_statistics

Retrieve statistical data for specified entities over a time period.

<ParamField path="statistic_ids" type="array">
  List of statistic IDs to retrieve data for
</ParamField>

<ParamField path="start_time" type="string" required>
  Start of the statistics period in `%Y-%m-%dT%H:%M:%S%z` format
</ParamField>

<ParamField path="end_time" type="string" required>
  End of the statistics period in `%Y-%m-%dT%H:%M:%S%z` format
</ParamField>

<ParamField path="period" type="string">
  Aggregation period. Options: `5minute`, `hour`, `day`, `month`. Default: `day`
</ParamField>

<ParamField path="units" type="object">
  Unit conversion configuration (optional)
</ParamField>

<ParamField path="types" type="array">
  Types of statistics to return. Default: `["change"]`
</ParamField>

<Accordion title="Example Configuration">
  Retrieve statistical data for energy consumption or other long-term statistics:

  ```yaml theme={null}
  - spec:
      name: get_statistics
      description: Retrieve statistical data for specified entities over a time period.
      parameters:
        type: object
        properties:
          statistic_ids:
            type: array
            items:
              type: string
              description: The statistic id to retrieve data for.
          start_time:
            type: string
            description: Start of the statistics period in "%Y-%m-%dT%H:%M:%S%z".
          end_time:
            type: string
            description: End of the statistics period in "%Y-%m-%dT%H:%M:%S%z".
          period:
            type: string
            description: Aggregation period (5minute, hour, day, month).
          types:
            type: array
            items:
              type: string
            description: Types of statistics to return.
        required:
        - start_time
        - end_time
    function:
      type: native
      name: get_statistics
  ```
</Accordion>

## Use Cases

<CardGroup cols={2}>
  <Card title="Control Devices" icon="toggle-on">
    Use `execute_service` to control lights, switches, and other devices
  </Card>

  <Card title="Create Automations" icon="robot">
    Use `add_automation` to create automations through conversation
  </Card>

  <Card title="Analyze History" icon="clock-rotate-left">
    Use `get_history` to analyze entity state changes over time
  </Card>

  <Card title="Energy Monitoring" icon="bolt">
    Use `get_energy` to retrieve energy dashboard configuration
  </Card>

  <Card title="Statistical Analysis" icon="chart-line">
    Use `get_statistics` for long-term statistical data and trends
  </Card>

  <Card title="Monitor Events" icon="bell">
    Combine functions to create monitoring and notification workflows
  </Card>
</CardGroup>

## Next Steps

<CardGroup cols={3}>
  <Card title="Template Functions" icon="brackets-curly" href="/functions/template">
    Dynamic templates
  </Card>

  <Card title="Script Functions" icon="scroll" href="/functions/script">
    Service sequences
  </Card>

  <Card title="Composite Functions" icon="layer-group" href="/functions/composite">
    Chain functions
  </Card>
</CardGroup>
