Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UserResponse using FirstName slot + StringResponse using Intents slot to pass to HA Assist #228

Closed
wants to merge 8 commits into from

Conversation

foxymichelle
Copy link

First, this is my first pull request. Not realizing exactly how this work, I created a fork and updated the commit notes and README with explanations for you.

Second, I did this a week ago and all is working well. Hopefully I was thorough and didn't miss anything going back to create all of this for sharing.

My goals were:

  1. Perfect sending a user's name back to HA as a response and hopefully get less "other" words. I discovered that AMAZON.Person is for full names of real/fictional people while AMAZON.FirstName is for common first names. Maybe it doesn't matter, but I'm getting better results using this. I also created a UserResponse category to capture those slots instead of getting it through StringResponse.
  2. I am now using StringResponse solely to initiate a request. I did originally have this set up as the previous {Strings} using the .Person slots would send whatever was said to HA, but it seems that Alexa has gotten stricter with intents matching slots, so I was getting errors. I created a custom "Intents" slot, then used that slot as the {Strings} utterances. Now the skill will pass the most common requests back to HA.
  3. Rather than creating an automation triggered by the StringResponse with "Choose" looking for specific words in the response, I thought it would be way more efficient to utilize the Year of Voice by passing the request on to Assist, then have Assist pass its response back, playing that as an announcement. So now I can say, "Alexa, ask actionable notifications where Son is", the request will be passed to Assist, then the Assist response will be announced using Alexa Media Player ("Son is as school."). Now all the built-in stuff just works; custom sentences and responses can be added to Assist instead of to the Alexa Intent automation (although I have not done that yet, so my sample first looks for "find" and "user" to trigger finding the user's phone or defaults to passing the message on to Assist).
  4. The only caveat with this is that I have to choose a single Alexa for all the responses, but we do have a central Alexa that works fine in most cases. I may add more to the automation so that I can add the device name to my request (... on kitchen dot), have it parse that out to use as the device_id and pass only the request to Assist so it understands.
  5. Finally, I wanted quick and easy troubleshooting, so I added 2 more text_input helpers - one that saves the incoming message from the skill and another that saves the Assist response. Now if an actionable notification doesn't do what was expected, I can go back and see what was "heard" without having to use the event listener and hope to repeat the error. The helpers history is also helpful for troubleshooting.

Added code to create a User Response (RESPONSE_USER, UserIntentHandler, and added to list of processes).
Added RESPONSE_USER
Deleted slot: AMAZON.Person (full name of real and fictional people)

Added slot: AMAZON.FirstName (Thousands of popular first names commonly used by speakers in the United States.  This slot type recognizes both formal names and nicknames. The name sent to your service matches the value spoken by the user...)

NOTE: There are (as of 1/2024) 3 other first name slots - one for German names (AMAZON.DE_FIRST_NAME), UK names (AMAZON.GB_FIRST_NAME), and a second US option (AMAZON.US_FIRST_NAME).

Added Slot: Intents (custom slot). This slot has all of the intents Assist understands built-in (as of 1/2024).

Added intent: Users with sample utternance {Users}, which is listening for the AMAZON.FirstName slot.

Edited Intent: String with sample utternance {Strings), which was edited to listen for the new Invokes slot.
Created 2 additional input_text helpers:
 
alexa_actionalble_response - used in an automation that saves the incoming message from the skill. While you can use the Events tab in Developer Tools to listen to events and troubleshoot, I've found it more efficient to simply refer to the this to see the history.

assist_to_alexa_response - again, a great placeholder to troubleshooting the response assist returns

Created a new input_boolean

alexa_action_in_progress - a toggle that can be helpful when you want to identify if there's an active action.

Edited the notification script:

Added turn on input_boolean.alexa_action_in_progress.
Created 3 additional automations:

1. Turns off input_boolean.alexa_action_in_progress if it's been on for a minute.

2. Saves the incoming message from the skill to the new input_text.alexa_actionable_response

3. Incoming request with intent trigger with custom responses and default response that passes the request to Assist and announces the response from Assist.
Update Details
Deleted slot: AMAZON.Person (full name of real and fictional people)

Added slot: AMAZON.FirstName (Thousands of popular first names commonly used by speakers in the United States.  This slot type recognizes both formal names and nicknames. The name sent to your service matches the value spoken by the user...)

NOTE: There are (as of 1/2024) 3 other first name slots - one for German names (AMAZON.DE_FIRST_NAME), UK names (AMAZON.GB_FIRST_NAME), and a second US option (AMAZON.US_FIRST_NAME).

Added Slot: Intents (custom slot). This slot has all of the intents Assist understands built-in (as of 1/2024).

Added intent: Users with sample utternance {Users}, which is listening for the AMAZON.FirstName slot.

Edited Intent: String with sample utternances {Strings) and {Strings}{Users}, which was edited to listen for the new Invokes slot.
Comment on lines +3 to +27
## This fork was updated with the following (see commit notes for more details):
- EN-US.json
- AMAZON.Person slot was deleted and replaced with AMAZON.FirstName with "User1Name" and "User2Name" (with nickname) as samples. **NOTE: Update with your user names/nicknames.
- New "Intents" slot was created with common intent triggers, including current (1/2024) Assist intents. **NOTE: Update to add your own intents.
- New "UserIntent" created that listens for {Users} listed in the AMAZON.FirstName slot.
- "StringIntent" edited to listen for {Strings} based on the new Intent slot.

- const.py and lambda_function.py
- Edited to include "UserResponse" event type.

- configuration.yaml
- Added input_text helpers to save the skill's incoming data and data that is returned by Assist.
- Added input_boolean helper to determine if there is an Alexa Actionable Notification event in progress or not.
- Edited the script to include turning on the input_boolean. **NOTE: You need to add turning it off at the end of your response automations.

- new_automations.yaml (NEW)
- Added automation that turns off the input_boolean after one minute. This is a catch-all, just in case your response automation fails or you forget to include turning it off.
- Added automation that saves the incoming event data to the new input_text helper.
- Added automation that listens for user-initiated incoming requests. There is a sample that uses Choose to create a custom response. The default action is to pass the message to Assist and announce the Assist response (plus save response in the new input_text helper).

About the custom response:
My sample triggers finding a users phone by looking for "find", then "userName", then turning on a find_userName_phone toggle. [Check this out](https://github.com/foxymichelle/Home-Assistant-Find-Phone/tree/main) for my Find Phone automations, including triggering an Alexa Actionable Notification if the user is not home, asking if you'd like to proceed, then completing the action based on your response.

## ----- Original Content -----

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't belong here. Either do documentation to include the changes but changelog is not the purpose of README.md

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a newbie to pull requests, so lessons will be learned! I'll get this sorted as as I tack each of your notes this week.

home-assistant/configuration.yaml Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use an appropriate name for the automation instead of new_automation.yaml

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure you include in docs how this works and how to use it.

variables:
response_type: "{{ trigger.event.data.event_response_type }}"
response: "{{ trigger.event.data.event_response }}"
device: media_player.your_alexa_device
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this value dynamic?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is dynamic, but the media_player needs to be updated. I'll separate the automations into different files with relevent names and include how it works/how to use in docs.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong formatting. Make sure you use double quotes. Use black and ruff for formatting and linting

Copy link

github-actions bot commented Apr 1, 2024

Stale pull request message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants