jekalmin / extended_openai_conversation

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

Add area awareness #122

Closed jekalmin closed 8 months ago

jekalmin commented 8 months ago

Objective

Area awareness feature in Year of Voice Chapter 5

Changes

How to use

  1. Assign area to your ESP-S3-BOX or Atom echo.
  2. Copy and paste prompt below.
  3. Ask "turn on light", "turn off light"

Prompt

I want you to act as smart home manager of Home Assistant.
I will provide information of smart home along with a question, you will truthfully make correction or answer using information provided in one sentence in everyday language.

Current Time: {{now()}}
Current Area: {{area_id(current_device_id)}}

Available Devices:
```csv
entity_id,name,state,area_id,aliases
{% for entity in exposed_entities -%}
{{ entity.entity_id }},{{ entity.name }},{{ entity.state }},{{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 -%}

The current state of devices is provided in available devices. Use execute_services function only for requested action, not for current states. Do not execute service without user's confirmation. Do not restate or appreciate what user says, rather make a quick inquiry. Make decisions based on current area first.

LowKey88 commented 8 months ago

Tested and it's work perfectly on my Satellite.

Jan 29 08:38:38 satellite run[647]: DEBUG:root:Event(type='transcript', data={'text': 'Turn on fan.'}, payload=None) Jan 29 08:38:38 satellite run[647]: INFO:root:Waiting for wake word Jan 29 08:38:38 satellite run[647]: DEBUG:root:Connected to snd service Jan 29 08:38:43 satellite run[647]: DEBUG:root:Event(type='synthesize', data={'text': 'The fan in the Master Bedroom has been turned on.', 'voice': {'name': 'RyanNeural'}}, payload=None) Jan 29 08:38:44 satellite run[647]: DEBUG:root:Connected to snd service

jekalmin commented 8 months ago

Thanks for testing it!

I was considering about whether this should be included in default prompt or not. Also, I was looking for the way to reduce token size in prompt while everything works the same.

However, I will release this in beta(1.0.2-beta3) version first, so it can be installed easily.