@Mat1: Great, that works! Thanks a lot. This way I could recover my old functionality.
I changed it to JavaScript and added the extraction of the Command. So if anybody is interested here is the code (see square brackets and comments to adjust to your needs). Let me know if things can be solved in a better way…
var lastCommand, serialNumber, echoName, echoMapping;
var HTTP = Java.type("org.openhab.core.model.script.actions.HTTP");
var url = "http://[yourIP]:8080/amazonechocontrol/[yourEchoBridgeName]/PROXY/api/activities?startTime=&size=1&offset=1";
var respJson = "" + HTTP.sendHttpGetRequest(url, 10000);
serialNumber = JSON.parse(respJson).activities[0].sourceDeviceIds[0].serialNumber
lastCommand = JSON.parse(JSON.parse(respJson).activities[0].description).summary
// replace those with your Echo-IDs and Names.
echoMapping = {'[serialOfEcho1]': '[NameOfEcho1]', '[serialOfEcho2]': '[NameOfEcho2]', '[serialOfEcho3]': '[NameOfEcho3]'};
echoName = String(echoMapping[serialNumber]) ;
// eliminate the alexa keyword
lastCommand = (lastCommand.toLowerCase()).replaceAll('alexa ','');
if (lastCommand == 'example command' || lastCommand == 'another command') {
...your code...
}
Please correct me if I’m not following the logic here. For now, we have a workaround (thanks @Mat1!) using a dummy routine and retrieving the last command via an API, but eventually this method in theory could be baked into the binding itself as the old method no longer works. Is that a possibility?
Also, does this workaround provide the device which received the command, as that’s crucial in my setup to do all sorts of things?
My LastVoiceCommand died also yesterday. The “special” version of the binding doesn’t work for me. So I implemented the workaround. It’s really nice and much better than nothing.
While testing, I recognized, that there is a problem with more than one amazon account. Only the first account which goes online works like expected. When the second account thing is started, I get this log entries:
2023-09-04 21:17:32.388 [WARN ] [trol.internal.handler.AccountHandler] - Failed to create account servlet
java.lang.IllegalStateException: ServletModel{id=ServletModel-76,name='org.smarthomej.binding.amazonechocontrol.internal.AccountServlet',alias='/amazonechocontrol/account2',urlPatterns=[/amazonechocontrol/account2/*],servlet=org.smarthomej.binding.amazonechocontrol.internal.AccountServlet@1f3696b,contexts=[{HS,OCM-69,default,/}]} can't be registered. ServletContextModel{id=ServletContextModel-2,contextPath='/'} already contains servlet named org.smarthomej.binding.amazonechocontrol.internal.AccountServlet: ServletModel{id=ServletModel-74,name='org.smarthomej.binding.amazonechocontrol.internal.AccountServlet',alias='/amazonechocontrol/account1',urlPatterns=[/amazonechocontrol/account1/*],servlet=org.smarthomej.binding.amazonechocontrol.internal.AccountServlet@1921684,contexts=[{HS,OCM-69,default,/}]}
at org.smarthomej.binding.amazonechocontrol.internal.AccountServlet.<init>(AccountServlet.java:97) ~[?:?]
at org.smarthomej.binding.amazonechocontrol.internal.handler.AccountHandler.initialize(AccountHandler.java:156) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
at org.openhab.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:147) ~[?:?]
at org.openhab.core.internal.common.Invocation.call(Invocation.java:52) ~[?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
at java.lang.Thread.run(Thread.java:833) ~[?:?]
I tested this with the original, the “normal” snapshot and the snapshot from this thread. Always the same behavior. @J-N-K You may have a look at it, but it is very less important.
That is exactly what I did too… Dummy Alexa routines that just say OK to suppress Alexa’s dumb responses with OH then handling the command. It worked very good or I should say did work very good. I have not upgraded to OH4 yet!
A short information about what‘s going on: we found that the activity is no longer reported via websockets but an HTTP/2 stream. We still have some issues with getting this stream initiated in the correct way, but it looks not so bad.
The ugly news is: openHAB 3.4 does not bundle Jetty support for HTTP/2, so it could be that the „solution“ will only work on OH4.
I figured I’d be better off just by checking my Echo through a bash script and post the result in OpenHAB - so there’s no need for an Alexa routine to trigger the whole thing. The only disadvantage (yet) is that if the same command is given twice after the other it doesn’t do anything. I’ll think about that, but it was just a quick and dirty fix for my problem so that Alexa at least listens (even though it doesn’t even speak anymore triggered from OH).
If you named the last voice command variable differently in your OpenHAB then replace Alexa_LastVoiceCommand with that.
Just copy-paste it and save it as a bash file eg. alexachecker.sh, make it executable.
Then you can start it inside a screen window so you can let it run in the background: sudo screen -dmS alexa-checker /[your path]/alexachecker.sh
#!/bin/bash
a=0
previouscommand="startroutine"
while a==0; do
variable=$(curl 'http://localhost:8080/amazonechocontrol/[your echos name]/PROXY/api/activities?startTime=&size=1&offset=1')
command=$(echo $variable | tr "," "\n" | tr '{' ' ' | tr "}" " " | grep "summary" | sed 's/.*:\\//g;s/\\//g;s/\"//g')
echo "Command: $command"
if [[ $command != $previouscommand && $previouscommand != "startroutine" ]]; then
echo $(date +%Y-%m-%d_%H:%M:%S)
echo "POST TO OPENHAB"
curl -m 2 -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "$command" "https://[your OpenHAB IP]:[your OpenHAB port]/rest/items/Alexa_LastVoiceCommand" -k --user [your OpenHAB username]:[your OpenHAB password]
previouscommand=$command
else
if [[ $previouscommand == "startroutine" ]]; then
previouscommand=$command
fi
sleep 10;
fi
done
I know it’s far from a perfect solution but it works without the need to Alexa routines triggering anything on OpenHAB - until the guys much better in coding create a new binding for us.
yes, that is a possibility, thank you!
For everybody failing to adapt this, the url is (at least for me) not “[your_echos_name]” but the account ID, that 10digit hexadecimal thing or how you have named your account.
Hi @J-N-K
First of all thank you for your work.
Do you think we have to wait for a soon official fix of the addon that you propose ?
Or me must use the ‘rule fix’ previously described meanwhile ?
Thanks
I am lacking time to fix it at the moment. Essentially the websocket connection needs to be removed and a new HTTP/2 stream hast to be added. There might also be changes needed to the login process. Similar changes can be found in ioBroker, so if someone wants to try, I can assist but currently I don’t have time to fully do it myself.
Unfortunately i don’t have the skill to help you.
I have just a feature request for who will try to fix the bindign.
Using the workaround i just realized that i can also check what my smartwhatch do:
Checking in http://myip:8080/amazonechocontrol/AlexaAccount
i can read this:
Alexa Bagno G**************M Online Alexa Bagno ECHO A************A A************O
Enrico's Verona 7******************************d Offline Not defined UNKNOWN A************6 A************O
Enrico’s Verona is the alexa of my Amazfit Gtr3 smartwhatch. but is from family unknown and cant be added.
Sorry is more work but this is one of the best bindigns for openhab!
If you have multiple accounts, you may also have to change “account1” to the appropriate account.
When I put that address in a browser I get something like this:
{“activities”:[{“_disambiguationId”:null,“activityStatus”:“SUCCESS”,“creationTimestamp”:1695313282996,“description”:"{"summary":" play music","firstUtteranceId":"A1…
so therefore just showing a link to the amazon account. I also tried varieties of the “accountx” part but that also doesn’t help. I have just one amazon account (as far as I can remember).
Amazonechocontrol binding is version 3.4.5.
What did I miss? Thanks
EDIT: Solved. Replacing “account1” with the account ID did the trick.
Thanks for this workaround. 2 Questions:
Can someone help me finding out the json for the last command? For the moment my thing is like that, but I only want the summary.
After a question to my echo I want an answer from this device I spoke. Is ist possible to generate a variable like.
when
Item Alexaaahttpcall3 changed
then
val neu = ""
if (Alexaaahttp.state == "G091MK08210703DG") neu = AlexaShowKlein_Ankundigung
if(was.toString.contains("test")){
sendCommand(neu, "Hallo")
}
end