github.com/e154/smart-home@v0.17.2-0.20240311175135-e530a6e5cd45/doc/content/en/docs/plugins/alexa.md (about)

     1  
     2  ---
     3  title: "Alexa"
     4  linkTitle: "alexa"
     5  date: 2021-10-20
     6  description: >
     7    
     8  ---
     9  
    10  {{< alert color="warning" >}}Incomplete article{{< /alert >}}
    11  
    12  In the **Smart Home** system, there is an Amazon Alexa plugin that provides integration with the Amazon Alexa voice assistant. This plugin allows you to control devices and perform various operations in your smart home using voice commands.
    13  
    14  The Amazon Alexa plugin offers the following functionality:
    15  
    16  1. Voice command recognition and processing: The plugin can receive voice commands from the user sent through the Amazon Alexa voice assistant. It recognizes the commands, analyzes them, and performs the corresponding actions in your smart home.
    17  
    18  2. Device control: The plugin enables you to control devices in your smart home using voice commands. For example, you can say "Alexa, turn on the lights in the living room" or "Alexa, set the temperature to 25 degrees."
    19  
    20  3. Integration with other system features: The Amazon Alexa plugin integrates with other features of the **Smart Home** system. For instance, you can use voice commands to trigger scenarios, control automated tasks, or obtain information about device status.
    21  
    22  To use the Amazon Alexa plugin in your **Smart Home** project, you need to set it up and connect it to your Amazon Alexa account. After that, you can configure voice commands and actions to control your smart home through the Amazon Alexa voice assistant.
    23  
    24  The Amazon Alexa plugin for the **Smart Home** system includes the following JavaScript handlers:
    25  
    26  1. `skillOnLaunch`: This handler is called when the skill is launched on an Amazon Alexa device. It is intended to handle the initial skill launch event. You can define logic or perform necessary actions when the skill is launched. Example usage:
    27  
    28  ```javascript
    29  skillOnLaunch = () => {
    30      // Logic for handling the skill launch event
    31  };
    32  ```
    33  
    34  2. `skillOnSessionEnd`: This handler is called when the session with the skill ends. It allows you to perform specific actions when the session with the user is terminated. For example, you can save state or perform final operations. Example usage:
    35  
    36  ```javascript
    37  skillOnSessionEnd = () => {
    38      // Logic for session end
    39  };
    40  ```
    41  
    42  3. `skillOnIntent`: This handler is called when the skill receives intents from the user. It is intended to handle different intents and perform corresponding actions. You can define logic for intent handling and interaction with your smart home. Example usage:
    43  
    44  ```javascript
    45  skillOnIntent = () => {
    46      // Logic for handling intents
    47  };
    48  ```
    49  
    50  These handlers provide the ability to handle skill launch events, session termination, and user intents within the context of the Amazon Alexa plugin. You can define your own logic and perform necessary actions in each of these handlers according to your project requirements.
    51  
    52  ### Code Example
    53  
    54  ```coffeescript
    55  skillOnLaunch = ->
    56  #print '---action onLaunch---'
    57    Done('skillOnLaunch')
    58  skillOnSessionEnd = ->
    59  #print '---action onSessionEnd---'
    60    Done('skillOnSessionEnd')
    61  skillOnIntent = ->
    62  #print '---action onIntent---'
    63    state = 'on'
    64    if Alexa.slots['state'] == 'off'
    65      state = 'off'
    66  
    67    place = Alexa.slots['place']
    68  
    69    Done("#{place}_#{state}")
    70  
    71    Alexa.sendMessage("#{place}_#{state}")
    72  ```