mirror of
https://github.com/home-assistant/developers.home-assistant.git
synced 2025-04-19 10:57:14 +00:00
Tweaks to intent docs (#1618)
* Tweaks to intent docs * Move to core section * Update docs/intent_firing.md
This commit is contained in:
parent
84ce528485
commit
cae42c9fe3
@ -1,19 +0,0 @@
|
||||
---
|
||||
title: "Registering sentences"
|
||||
---
|
||||
|
||||
The conversation component handles incoming commands from the frontend and converts them to intents. It does this based on registered sentences.
|
||||
|
||||
As a component, you can register sentences with the conversation component to allow it to be remote controlled. Refer to named slots by putting the slot name between curly braces: `{item}`. Use square brackets around (partial) words to mark them as optional.
|
||||
|
||||
Example code:
|
||||
|
||||
```python
|
||||
async def async_setup(hass, config):
|
||||
hass.components.conversation.async_register(
|
||||
"MyCoolIntent",
|
||||
["I think that {object} is [very] cool", "Nothing is cooler than {object}"],
|
||||
)
|
||||
```
|
||||
|
||||
If a sentence like "I think that beer is cool" comes in, the conversation component will generate an intent of type `MyCoolIntent` and with 1 slot, named `object` and value `beer`.
|
@ -2,7 +2,24 @@
|
||||
title: "Firing intents"
|
||||
---
|
||||
|
||||
When you fire an intent, you will get a response back or an error will be raised. It is up to the component to return the result to the user.
|
||||
If your code matches the user's speech or text to intents, you can let the intent be handled by Home Assistant. This can be done from inside your own integration, or via the generic Intent handle API.
|
||||
|
||||
When you fire an intent, you will get a response back or an error will be raised. It is up to your code to return the result to the user.
|
||||
|
||||
## HTTP API
|
||||
|
||||
When the intent integration is loaded, an HTTP API endpoint is available at `/api/intent/handle`. You can POST JSON data to it containing an intent name and it's data:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "HassTurnOn",
|
||||
"data": {
|
||||
"name": "Kitchen Light"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Home Assistant integration
|
||||
|
||||
Example code to handle an intent in Home Assistant.
|
||||
|
||||
|
@ -7,7 +7,6 @@ Any component can register to handle intents. This allows a single component to
|
||||
A component has to register an intent handler for each type that it wants to handle. Intent handlers have to extend `homeassistant.helpers.intent.IntentHandler`
|
||||
|
||||
```python
|
||||
import asyncio
|
||||
from homeassistant.helpers import intent
|
||||
|
||||
DATA_KEY = "example_key"
|
||||
@ -32,10 +31,11 @@ class CountInvocationIntent(intent.IntentHandler):
|
||||
async def async_handle(self, intent_obj):
|
||||
"""Handle the intent."""
|
||||
intent_obj.hass.data[DATA_KEY] += 1
|
||||
count = intent_obj.hass.data[DATA_KEY]
|
||||
|
||||
response = intent_obj.create_response()
|
||||
response.async_set_speech(
|
||||
f"This intent has been invoked {intent_obj.hass.data[DATA_KEY]} times"
|
||||
f"This intent has been invoked {count} times"
|
||||
)
|
||||
return response
|
||||
```
|
||||
|
21
sidebars.js
21
sidebars.js
@ -88,7 +88,7 @@ module.exports = {
|
||||
"operating-system/debugging",
|
||||
"operating-system/partition",
|
||||
"operating-system/board-metadata",
|
||||
"operating-system/deployment"
|
||||
"operating-system/deployment",
|
||||
],
|
||||
Supervisor: ["supervisor", "supervisor/development", "supervisor/debugging"],
|
||||
// Old structure, still to move/migrate
|
||||
@ -122,7 +122,7 @@ module.exports = {
|
||||
"development_guidelines",
|
||||
"development_testing",
|
||||
"development_catching_up",
|
||||
"development_tips"
|
||||
"development_tips",
|
||||
],
|
||||
"Building Integrations": [
|
||||
"creating_component_index",
|
||||
@ -157,14 +157,14 @@ module.exports = {
|
||||
Entities: [
|
||||
"core/entity",
|
||||
{
|
||||
type: 'autogenerated',
|
||||
dirName: 'core/entity',
|
||||
type: "autogenerated",
|
||||
dirName: "core/entity",
|
||||
},
|
||||
],
|
||||
Platforms: [
|
||||
{
|
||||
type: 'autogenerated',
|
||||
dirName: 'core/platform',
|
||||
type: "autogenerated",
|
||||
dirName: "core/platform",
|
||||
},
|
||||
],
|
||||
Registries: [
|
||||
@ -180,18 +180,17 @@ module.exports = {
|
||||
"device_automation_condition",
|
||||
"device_automation_action",
|
||||
],
|
||||
Misc: ["development_validation", "development_typing", "instance_url"],
|
||||
},
|
||||
Misc: {
|
||||
Introduction: ["misc"],
|
||||
Intents: [
|
||||
"intent_index",
|
||||
"intent_firing",
|
||||
"intent_handling",
|
||||
"intent_conversation",
|
||||
"intent_builtin",
|
||||
"intent_conversation_api",
|
||||
],
|
||||
Misc: ["development_validation", "development_typing", "instance_url"],
|
||||
},
|
||||
Misc: {
|
||||
Introduction: ["misc"],
|
||||
"Building a Python library": [
|
||||
"api_lib_index",
|
||||
"api_lib_auth",
|
||||
|
Loading…
x
Reference in New Issue
Block a user