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

New Routine Service doesn’t work. #90

Closed
h4nc opened this issue Feb 24, 2019 · 25 comments · Fixed by #105
Closed

New Routine Service doesn’t work. #90

h4nc opened this issue Feb 24, 2019 · 25 comments · Fixed by #105
Assignees
Labels
alexapy Issue relates to the API bug Something isn't working

Comments

@h4nc
Copy link

h4nc commented Feb 24, 2019

Ok, so sequence works for me, but I don’t get routines working.

I have a routine called “test” and I tried it this way

{
“entity_id”: “media_player.myalexadevice”,
“media_content_id”: “test”,
“media_content_type”: “routine”
}

but it doesn’t work.

When I say “alexa, test” it works.

This is the error I get when I trigger a script with the data from above.

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/service.py", line 291, in _handle_service_platform_call
await func(entity, data)
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/alexa_media/media_player.py", line 536, in play_media
self.alexa_api.run_routine(media_id)
File "/config/deps/lib/python3.7/site-packages/alexapy/alexaapi.py", line 127, in run_routine
a_utterance = automation['triggers'][0]['payload']['utterance']
KeyError: 'utterance'

@alandtse
Copy link
Owner

Interesting. Can I see the result of going to this page? You may have to adjust the url for your region.
Please scrub out your customerId and any serialNumbers if you post it here.

@alandtse alandtse added the bug Something isn't working label Feb 24, 2019
@alandtse
Copy link
Owner

If it's not in the list, then the code won't be able to run it. It's odd though that it's in your app.

  • Did you use the .com url or did you change to the .de url?
  • Does this work with the remote control script (only if you have it, no need to get it set up if you don't)?
  • Can you using the Alexa app to create a different sequence and see if it appears in the automations url?
  • Do the other routines work? "Starte meinen Tag" and "Gute Nacht".

@alandtse
Copy link
Owner

As an FYI, I just fixed a bug in the API unrelated to what you're experiencing, but may cause your test routine to fail if it shows up in the automations list. For now, make sure all routines have 2 items in them. Single items will fail without the fix.

@h4nc
Copy link
Author

h4nc commented Feb 24, 2019

  • Did you use the .com url or did you change to the .de url?

Sry I used the .com url. It opened up and because of this I did not check .de
So there is a new much longer output now. See below

  • Does this work with the remote control script (only if you have it, no need to get it set up if you don't)?

Don't have it

  • Can you using the Alexa app to create a different sequence and see if it appears in the automations url?

I think you mean routine right? I will have a look at this

  • Do the other routines work? "Starte meinen Tag" and "Gute Nacht".

I tried to run "Gute Nacht" but that did not work to. However I did not look in the logfile when I triggered that. Will also have a look at this and come back

@alandtse
Copy link
Owner

I think you mean routine right? I will have a look at this

Correct, sorry, inside the API it's called a sequence so I switch between both.

Could de-AT be the issue?

No, that's not the cause of the log error. The log error you posted at the top of this is saying that the entire 'utterance' key is missing in the data it was scanning. That's happening before it gets to the test routine you found. I think this means there's something in the automation link data that I haven't seen before so I'm parsing it incorrectly. I'll need to see the whole file (scrubbed of course) to really know.

@alandtse
Copy link
Owner

You have an echo button. I think that's it. I'll need to make the changes to the alexaapi to fix this so you'll need to run a custom version of it once ready.

@h4nc
Copy link
Author

h4nc commented Feb 24, 2019

custom version of it once ready

So you mean, it will not be possible to to use one version for all usecases?

If so, would this mean you will upload und update two versions in your repository?

@alandtse Are you ok when I delete those commebts above with possible private information in it. Did you extract all necessary information from it. I am a little carefull with this kind of data.

@alandtse alandtse added the alexapy Issue relates to the API label Feb 24, 2019
@alandtse alandtse self-assigned this Feb 24, 2019
@alandtse
Copy link
Owner

alandtse commented Feb 24, 2019

Are you ok when I delete those commebts above with possible private information in it.

Yes, you can delete it. Thanks for providing them.
EDIT: I went ahead and deleted it given I'm linking to this issue on the wiki.

So you mean, it will not be possible to to use one version for all usecases?

If so, would this mean you will upload und update two versions in your repository?

The following fix should address everything you've reported, but of course let me know if it doesn't. I'm about to sleep so won't be responsive for a while.

To install the fix, you'll need to do the following pip install. This will pick up the next version of the alexapy library we're working on.
pip3 install --force git+https://gitlab.com/keatontaylor/alexapy.git@next

When we do the next version of this component we'll update the version number, I believe it will auto-update you. But if you have issues, you may have to uninstall it manually first.
pip3 uninstall alexapy.

Repository owner deleted a comment from h4nc Feb 24, 2019
@h4nc
Copy link
Author

h4nc commented Feb 24, 2019

The thing is I'm using hassio and I think I cannot do things like that with it.

@alandtse is it possible to change that in hassio too?

@alandtse
Copy link
Owner

is it possible to change that in hassio too?

I honestly don't know as I don't use hassio. My guess is probably not based off some quick googling. I'm preparing the next version but have one more issue I want to resolve before the next release.

@h4nc
Copy link
Author

h4nc commented Feb 25, 2019

Ok so I'll wait, could you post it here when the new version is ready fr hassio. After that I'll test if it works and come back.

This was referenced Mar 1, 2019
@h4nc
Copy link
Author

h4nc commented Mar 1, 2019

The new update works great for last_called issues.

But this issue about the routines is still not solved. Nothing in the logs when I try this

{
“entity_id”: “media_player.myalexadevice”,
“media_content_id”: “test”,
“media_content_type”: “routine”
}

I still have the routine "test" in my alexa app.

@alandtse
Copy link
Owner

alandtse commented Mar 2, 2019

Ok, can you please enable the alexapy logs so we can see what exactly is being sent to Amazon when you try to run the routine?

@alandtse alandtse reopened this Mar 2, 2019
@h4nc
Copy link
Author

h4nc commented Mar 2, 2019

Ok this is really strange.
It doesn't do anything in the logs when I try to run the routine.
{
"entity_id": "media_player.echo_dot",
"media_content_id": "test",
"media_content_type": "routine"
}

This never worked no matter how often I tried it. No output in the logs.

So I tried another Routine "Washingmachine" and "Dryer".

That one worked now for the first time, BUT it doesn't work reliable. So this how it could happen

  • call "Washingmachine" response
  • call "Washingmachine" no response
  • call "Dryer" no response
  • call "Dryer" response
  • call "Dryer" response

no response means alexa gives no answer, all of those routines fire a tts message

This is a the log of a response called routine
2019-03-02 07:55:37 DEBUG (SyncWorker_2) [alexapy.alexaapi] Running routine: Dryer with data: {"behaviorId": "amzn1.alexa.automation.***", "sequenceJson": "{\"@type\": \"com.amazon.alexa.behaviors.model.Sequence\", \"sequenceId\": \"amzn1.alexa.sequence.***\", \"startNode\": {\"@type\": \"com.amazon.alexa.behaviors.model.SerialNode\", \"name\": null, \"nodesToExecute\": [{\"@type\": \"com.amazon.alexa.behaviors.model.OpaquePayloadOperationNode\", \"type\": \"Alexa.SmartHome.Batch\", \"operationPayload\": {\"target\": \"***\", \"customerId\": \"***\", \"operations\": [{\"type\": \"turnOn\"}, {\"brightness\": 2, \"type\": \"setBrightness\"}], \"deviceType\": \"***\", \"deviceSerialNumber\": \"***\"}, \"name\": null}]}}", "status": "ENABLED"}

then followed by two entries that turn the volume to a certain level and then tts.

The no response log looks exactly the same, but is not followed by the volume set and tts. So I looked if it turns on my dummy bulb to two 2%. And in fact it does turn on the bulb.

So this is my automation. As I mentioned in another issue, maybe there is a timing issue here?

- alias: Alexa Routinen Trockner - 2
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: light.alexa_dummy
    to: 'on'
  condition:
    - condition: template
      value_template: '{{ states.light.alexa_dummy.attributes.brightness == (2 * 255)//100 }}'
  action:
    - service: alexa_media.update_last_called 
    - delay: "00:00:01"
    - service: homeassistant.turn_on
      data_template: 
        entity_id: >
          {% if is_state("binary_sensor.dryer_status", "on") %}
            script.alexa_routine_dry_on
          {% else %}
            script.alexa_routine_dry_off
          {% endif %}  
    - service: homeassistant.turn_off
      entity_id: light.alexa_dummy

script (only one, the other one is the same but off)

alexa_routine_dry_on:
  sequence:
    - service: media_player.volume_set
      data_template:
        entity_id: '{{ states.sensor.last_alexa.state }}' 
        volume_level: 0.3
    - delay:
        seconds: 0.5        
    - service: media_player.alexa_tts
      data_template:
        entity_id: '{{ states.sensor.last_alexa.state }}' 
        message: "Dryer is on"

Do I have to add a delay somewhere to give it more time to make it reliable?

There is still the question why the routine "test" doesn't work at all. It works when I do it by voice.
EDIT: I renamed "test" to "Test Number" and finally it worked. Renamed it back to "test" and also works now. Strange.

@alandtse
Copy link
Owner

alandtse commented Mar 2, 2019

So if I understand correctly, the issue appears to be a problem during an automation, but if your'e in a script it tends to work? Or are you referring to just running it as a service that it's inconsistent. I may be mixing up the two threads.

I guess my question is does this thread topic still seem to be a problem or does it look resolved? I get that it had some strangeness for you. If your'e not experiencing the problem anymore, it may be difficult for us to debug it so we may just want to close it until you get it again.

@h4nc
Copy link
Author

h4nc commented Mar 2, 2019

There way somethin wrong with the "test" routine, after renaming it, it worked reliable.

So the triggering of routines work fine. The logs say the same now, as the dummy bulb is turned on correctly.
So there is no issue with your component triggering routines (any more?).

But it still doesn't work reliable because sometimes after triggering the routine, the volume set and tts are not send to alexa. The automation works reliable (because it turns on the bulb) but tts doesn't get to it every time.

Maybe one more thing, that could point in the right direction.

I also had this issue with not responding (alltough automation works) before with triggering the routine by voice. This only happened with one of my 3 alexa devices (an echo dot gen 3). The others respond reliable.
The echo dot 3 (only have one of those) is the only alexa device that has echo buttons with routines connected.
So it could be the echo dot 3 or the echo buttons that make issues here? Thats the only differnece I see comparing it with my other devices.

In conclusion we can say, it makes no difference no if I trigger a routine by voice or with the component.
The thing that seems working unreliable is set volume and tts. Only for that one device.

So in fact this issue is closed, but there is still an issue somewhere.

@alandtse
Copy link
Owner

alandtse commented Mar 2, 2019

In conclusion we can say, it makes no difference no if I trigger a routine by voice or with the component.
The thing that seems working unreliable is set volume and tts. Only for that one device.

Is that dot in a place where wifi may be unreliable?
The volume and tts commands both require:

  1. alexa_media send a command to Amazon.
  2. Amazon sends the command back to the specific echo device.

The bulb on the other hand takes the specific echo device out of the equation.

  1. alexa_media sends the command to Amazon.
  2. Amazon sends the command to the bulb controller (either HA, a smart home controller, or the bulb itself).
  3. If it's a bulb controller in 2, bulb controller sends the command to the bulb.

If you wanted to test this, you may consider swapping dot locations to see it changes anything.

I'll go ahead and close this then.

@alandtse alandtse closed this as completed Mar 2, 2019
@h4nc
Copy link
Author

h4nc commented Mar 3, 2019

The dot has reliable internet and wifi connection. I don't think thats the issue.

I set up some delays to see if it gets more reliable in the next days. Will come back.

@h4nc
Copy link
Author

h4nc commented Mar 5, 2019

@alandtse I don't want to say I found the issue, but this is what I found out.

When I put the volume set and the tts command in one script with a one seconds delay and called this in an automation the one alexa device did work reliable.

Sometimes it worked (means volume and tts), sometimes it only worked partially (means volume set, but no tts).

Putting both (volume and tts) in different scripts and calling them in an automation after each other with a one seconds delay and it (strange!!) works reliable.

I don't understand why it behaves like this. It looks like a timing issue and it's an really unpleasant bug, because it's really hard to debug and as a user you will possible never find this (because to a user both codes make no difference). I found the solution by coincidence.

I also don't know who to question about this or where to share it that someone who is able might fix this. Maybe you could point someone with better knowledge here?

EDIT: Ok I was too fast, just now it tts also did not work at the first try at another alexa device. One of both always works (mostly volume set, as the white leds indicate, but sometimes even only tts works). This means last_alexa is fast enough to choose the right one.
When I try it a seconds time after tts did not work, it always worked. Don't know what else I could try. Maybe higher delays between volume set and tts?

@alandtse
Copy link
Owner

alandtse commented Mar 6, 2019

I think you may be running into a limitation of what the Alexa API allows. It's similar to some queries in the forum and for the script where people try to do multiple TTS to the same Alexa at near the same time and it doesn't do all of them.

We may be able to build a queuing process into the API to build a chain of sequences like an automation routine, but I'm not sure if the API will allow it to be built dynamically.

In my testing of the volume change, I always did it after something was playing like TTS. Does it help by flipping the order so the TTS happens first and then the TTS? It may result in some strangeness in the TTS, but I'd also be careful of scripting interactions that Amazon doesn't do with it's own automation routines. So for example, if an Automation routine always has some delay between the volume set and playback, I'd try to mimic that externally.

@h4nc
Copy link
Author

h4nc commented Mar 6, 2019

We may be able to build a queuing process into the API to build a chain of sequences like an automation routine, but I'm not sure if the API will allow it to be built dynamically.

If it is possible, this would be great.

Sending the volume command after the tts will (as you said) lead to weird tts messages. So I'd like to avoid that.

So for example, if an Automation routine always has some delay between the volume set and playback, I'd try to mimic that externally.

Is it like this? I don't know? Do they set a delay?
So are you askign me to set up a routine with volume set and a tts and than measure how long they wait between both commands?

@h4nc
Copy link
Author

h4nc commented Mar 6, 2019

@alandtse ok so I made a routine with volume set and tts within the app and than triggered that routine.

I worked reliable and there was not noticable delay between both comands.

Volume led goes on and millisecs after that tts (blue/green led ring) starts.

@h4nc
Copy link
Author

h4nc commented Mar 12, 2019

@alandtse with 1.2.0 tts works a 100% reliable now. Sometimes the volume set commands still gets missed, but I tried it about 20 times (switching alexa devices) and it always answered. However as I said the volume wasn't set everytime. Specially not when I switched from one to another device (but not a 100% failing rate here, sometimes with volumeset sometimes not).

@h4nc
Copy link
Author

h4nc commented Mar 29, 2019

@alandtse my routines still don't work a 100% reliable. Sometimes it doesn't work at the first try, but it does always at the second one.

@alandtse
Copy link
Owner

@h4nc Can you provide the script that's failing to #147; we'll take a closer look to see if it's reproduceable. Wasn't sure if it's the same as listed above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
alexapy Issue relates to the API bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants