extended_openai_conversation
extended_openai_conversation copied to clipboard
Add floor and label examples for new HA (Dev) features
HA Dev introduces labels and floors. E.g. you can add labels to your devices (e.g. "printer" to all printers.) With this, you may ask where the printers are. It seems to be impossible to get a complete list of all devices - but you can get a list of devices by label and all entities by device ID and it seems to work pretty well even with GPT 3.5. Be careful and don't call entities "devices" and vice versa in your prompt.
I addes this to my prompt:
Available entities:
entity_id,name,area,aliases
{% for entity in exposed_entities -%}
{{ entity.entity_id }},{{ entity.name }},{{ area_id(entity.entity_id) }},{{ entity.aliases | join('/') }}
{% endfor -%}
Areas:
area_id,name
{% for area_id in areas() -%}
{{ area_id }},{{ area_name(area_id) }}
{% endfor -%}
Floors:
floor_id,name,floor_areas
{% for floor_id in floors() -%}
{{ floor_id }},{{ floor_name(floor_id) }},{{ floor_areas(floor_id) | join('/') }}
{% endfor -%}
Labels:
label_id,name
{% for label_id in labels() -%}
{{ label_id }},{{ label_name(label_id) }}
{% endfor -%}
Then I added this to my functions:
- spec:
name: get_area_id_by_lookup
description: Returns the area ID for a given area name, device ID, or entity ID.
parameters:
type: object
properties:
lookup_value:
type: string
description: The area name, device ID, or entity ID to retrieve the area ID for.
required:
- lookup_value
function:
type: template
value_template: >
{{ area_id(lookup_value) }}
- spec:
name: get_areas_by_label_id
description: Returns a list of area IDs associated with the given label ID.
parameters:
type: object
properties:
label_id:
type: string
description: The label ID to look up areas for.
required:
- label_id
function:
type: template
value_template: >
{% set area_ids = label_areas(label_id) %}
{{ area_ids | tojson }}
- spec:
name: get_device_ids_and_names_by_label
description: Returns a JSON list of objects with device IDs and names associated with the given label ID or name.
parameters:
type: object
properties:
label_id_or_name:
type: string
description: The label ID or name to look up devices for.
required:
- label_id_or_name
function:
type: template
value_template: >
[{% set devices = label_devices(label_id_or_name) %}
{% for device_id in devices %}
{% set name_by_user = device_attr(device_id, "name_by_user") %}
{% set device_name = name_by_user if name_by_user else device_attr(device_id, "name") %}
{% if not loop.first %},{% endif %}
{"device_id": "{{ device_id }}", "device_name": "{{ device_name | default('unknown device') }}"}
{% endfor %}]
- spec:
name: get_device_ids_and_names_by_area
description: Returns a JSON list of objects, each containing a device ID and its name, for devices associated with a given area ID or name.
parameters:
type: object
properties:
area_id_or_name:
type: string
description: The area ID or name to retrieve device information for.
required:
- area_id_or_name
function:
type: template
value_template: >
[
{% set devices = area_devices(area_id_or_name) %}
{% for device_id in devices %}
{% set device_name = device_attr(device_id, "name_by_user") | default(device_attr(device_id, "name"), true) | default('unknown device') %}
{% if not loop.first %},{% endif %}
{"device_id": "{{ device_id }}", "device_name": "{{ device_name }}"}
{% endfor %}
]
- spec:
name: get_entities_and_names_by_label
description: Returns a list of entities, including both entity IDs and their friendly names, associated with the given label ID or name.
parameters:
type: object
properties:
label_id_or_name:
type: string
description: The label ID or name to look up entities for.
required:
- label_id_or_name
function:
type: template
value_template: >
{% set entity_ids = label_entities(label_id_or_name) %}
{{ entity_ids | tojson }}
- spec:
name: get_entities_by_device_id
description: Returns a list of entity IDs associated with the given device ID.
parameters:
type: object
properties:
device_id:
type: string
description: The device ID to look up entities for.
required:
- device_id
function:
type: template
value_template: >
{{ device_entities(device_id) | tojson }}