Alexa skill error after switching to Lambda after deprecated api_password

I recently ported my Alexa skills over to using log-term tokens since the API password in HA has been deprecated.

I’m having problems with some of my skills. Sometimes, the skill will return the correct text to be spoken. But about 1/3 of the time, Alexa says “There was a problem with the requested skill’s response.”

The skill will still execute - I’m just not getting the correct spoken response. Any ideas?

Here’s the HA log associated with one error

2019-11-28 22:02:11 ERROR (MainThread) [homeassistant.components.alexa.intent] Error handling amzn1.ask.skill.XXX
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/intent.py", line 67, in async_handle
    result = await handler.async_handle(intent)
  File "/usr/src/homeassistant/homeassistant/components/intent_script/__init__.py", line 85, in async_handle
    await action.async_run(slots)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 162, in async_run
    await self._handle_action(action, variables, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 246, in _handle_action
    await self._actions[_determine_action(action)](action, variables, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 329, in _async_call_service
    context=context,
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 98, in async_call_from_config
    domain, service_name, service_data, blocking=blocking, context=context
  File "/usr/src/homeassistant/homeassistant/core.py", line 1234, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
concurrent.futures._base.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/alexa/intent.py", line 61, in post
    response = await async_handle_message(hass, message)
  File "/usr/src/homeassistant/homeassistant/components/alexa/intent.py", line 118, in async_handle_message
    return await handler(hass, message)
  File "/usr/src/homeassistant/homeassistant/components/alexa/intent.py", line 153, in async_handle_intent
    {key: {"value": value} for key, value in alexa_response.variables.items()},
  File "/usr/src/homeassistant/homeassistant/helpers/intent.py", line 75, in async_handle
    raise IntentUnexpectedError(f"Error handling {intent_type}") from err
homeassistant.helpers.intent.IntentUnexpectedError: Error handling amzn1.ask.skill.XXX

I moved to a Raspberry Pi 4 hoping that speed would help, but I still get this error pretty consistently.

Is there something weird about my setup? My skills are failing about ~1/3 of the time with:

“There was a problem with the requested skill’s response.”

These all worked fine using the api_password before switching to the new authentication scheme.

You should view the logs in your skill to see what error is being produced on the amazon side. It’s possible you have an error in your intent, or there’s a bug in home assistant, or alexa is hearing you wrong. Can’t know without seeing what is being sent.

I’m not really sure how to read the debug log. But with the sessions that generate a “there was a problem” response, I see two things that appear to be errors. The first:

2019-12-17T19:11:16.084Z c61b18f9-e023-4aba-8ebd-2a0e4d6074dc Task timed out after 3.00 seconds

Since I’d initially thought it could be something to do with timeouts, I had already bumped up the connection time of urllib3.Timeout in the Lambda function to 10 seconds (30 for completion), but that doesn’t appear to have an effect. Not sure where that 3 seconds comes from.

The other error is

[ERROR] JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Traceback (most recent call last):
  File "/var/task/lambda_function.py", line 57, in lambda_handler
    return json.loads(response.data.decode('utf-8'))
  File "/var/lang/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/var/lang/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/var/lang/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None

That looks to me like the lambda function got an unexpected result from HA.

I’m not sure you actually did what I asked. So…

  1. What are you running for your llambda function? Haaska or ASHS?
  2. In AWS, when you test your intents, what are you seeing as responses?

EDIT: I want to clarify, I’m not faulting you for this. The whole process for linking up Alexa to home assistant is confusing in general and debugging it can be a nightmare.

The endpoint for my Alexa skill is this lambda function, the one pointed-to from the docs.

The errors I posted above are what I’m seeing in my CloudWatch management console when I turn debug (set the DEBUG variable to “true”) on in the lambda management console.

Sometimes, the skills work just fine. Sometimes the same skill fails as described above.

Is there a place in the Alexa Developer’s Console that also logs errors? I can’t find that.

I just found the timeout setting in the basic settings of the Lambda function. I bumped that up to 7 seconds. I’ll report back if that did the trick.

Three seconds was the default.

That fixed most of my issues. But my “time for bed” skill is still running into problems. I set the lambda timeout to 7 seconds because Alexa has an 8 second timeout.

It looks like the Home Assistant skill waits until everything completes before returning a success code and the speech text. I can understand why this happens. I guess there’s really no way to tell Home Assistant to reply and not wait for successful completion of the skill’s actions. And there’ll be cases where you want to get some value from the skill’s actions to use in the reply, so HA can’t simply respond without waiting.

I guess it’d be great if there was an option for intents to say “respond right away”.

Are there any tricks to achieve this? Like put everything in a script instead of in the intent’s actions?

This skill/intent worked fine before I switched to using the lambda (so that I could ditch api_password).

how is your intent tailored? Is this an intent with a duration? If so, you can strip the whole intent out into a script. And make your intent fire the script. The intent should immediately finish while the script takes it’s time.

EDIT: Also, I would consider this a bug for intents if it produces an error

I just checked. I do have all of the intent’s actions in a script because I can also start the same action via a button-press. The script itself only turns off two booleans, but changing the booleans kicks off other actions that watch for their state change.

When I started “time for bed”, I watched the Alexa ring spin for ~7 seconds (the lambda timeout), then return “there was a problem…”

That’s odd, can you share the script/intent?

EDIT: I still think it’s a bug.

The intent just has one script as its action. The script just changes the values of 2 booleans.

It’s an intent_script (not in the alexa: block) because I can call it from a Google device, too.

It does not have a speech block. Doc’s say that block’s optional and I get a spoken confirmation from TTS.

Given, when the two booleans change (we’ve gone to bed), a lot of stuff happens - everything (lights, Harmony, etc) turns off, the alarm arms, etc.

Hmm, so it most likely takes longer than 8 seconds to execute. I would think that wrapping in a script separate from the intent would skip the duration it takes to execute. You could for testing purposes verify this by placing a voice response at the beginning and end of the intent.

The difficult thing about that is that there are other automations that react to the booleans changing. So I can put a TTS before and after setting them, but that doesn’t really book-end the actions that’ll take place.

I just added a speech response to the intent_script to see if that perhaps triggers HA to respond more quickly. It appears to work - I got the response instead of “there was an error…” - but the issue was a transient one, so it’s hard to say for sure.

The speech response didn’t help. I went ahead and opened an issue.

Yeah, not sure how that will be solved. It’s a very unique issue. Most people have a response in the first intent.

Just as a side note, I changed all my ‘intents’ to routines in alexa. Much better voice control imo.

I’m not sure I understand this sentence. Even if I include a response in the intent (it’s just one script and a speech: block), I get the timeout error.

I’ll take a look at routines - I’d been using intents so that I could have Google Assistant trigger the same code without building twice.

Oh, I thought you said it didn’t. Disregard then.

Just enable the script in alexa and have a routine run that script.