Release Candidate and Support: Amazon Echo Control Binding

I don´t understand why i should do this.
It´s still a workaround and doesn´t matter if i use a timer or Thread::sleep.

It´s working with Thread::sleep but not without, that´s the point

kind regards
Michael

For why it’s a bad idea, It’s worth reading this:

1 Like

Thanks for the link Scott and H102 for the hint!
I´m currently just using Thread::sleep in small Alexa rules that needs a pause between multiple commands.
It´s still a good idea to change this from sleep to timers.

Anyway it´s just workaround because the Amazon servers have trouble with too many commands :slight_smile:

kind regards
Michael

See the link that @scottk provided above. Thanks for that Scott.:+1:

I have no idea how many rules you have or how often they run but if your using thread sleep for something like TTS I hope it’s not many and not often.:wink:

I just had a look and only three out of 35 rules use Thread::sleep while only two are using a value greater 500ms.
Just to understand the timer…
In your example the timer waits one second before executing the next TTS, basically the same as a Thread::sleep(1000).
But the timer will terminate the rule thread for one second and then create another thread to run the rest of the rule?
I just want to understand what´s more “stress” for the system.
Work with one thread that´s in use for atleast 5 seconds or use atleast 4 threads that are only used for one or two seconds.

And things inside the timer will be executed after the timer is done?
Example, the TTS will be send 5 seconds after the rule started:

rule "Test"
when
	Item itmTestSwitch changed
then
        createTimer(now.plusSeconds(5),  [ |
	   echoKueche_TTS.sendCommand('Test Küche')
        ])
end

kind regards
Michael

Actually, the createTimer() examples won’t work as desired, they spin off threads that come from a different thread pool from that used by Thread::sleep() and immediately return, which is to say there is effectively no delay to the calling thread when createTimer() is called. Your rule could actually be coded something like this:

rule "Test"
when
    Item itmTestSwitch changed
then
    echoKueche_TTS.sendCommand('Test Küche')
    createTimer(now.plusSeconds(1), [|
        echoWohnen_TTS.sendCommand('Test Wohnzimmer')
        createTimer(now.plusSeconds(1), [|
            echoFlur_TTS.sendCommand('Test Flur')
            createTimer(now.plusSeconds(1), [|
                echoArbeit_TTS.sendCommand('Test Arbeitszimmer')
            ])
        ])
    ])
end

Warning, the above may have typos and is untested, but should serve to illustrate the use of createTimer() in your rule.

[Updated to correct missing right paren at each plusSeconds() method call. Thanks for spotting that, @H102! ]

2 Likes

@scottk I just realized that I left out the [ | lambda part on my post above.:roll_eyes: I edited the post to point to yours.:wink:

1 Like

Hi @schaze ,

Could you check it with the beta 2.5 (1). It should fix this problem.

Best,
Michael

No, there is not public API to control the echo. The binding is build on the API calls done from the alexa web site.

Hello michi,
do you now if there is a way to access the alexa alarm clock events? I would like to fire some actions when my alarm clock(echospot) is ringing…make coffee, start hue sunrise etc…
At the moment I’m looking for Echos Player changes when my Presence Mode is set to sleep,
but this not a very elegant way.

Regards,
Olli

Currently only with an REST call through the binding proxy.
The url must be build depending on your installation.

http(s)://<youropenhab>/amazonechocontrol/<youraccountid>/api/notifications

e.g. assuming the OH is running on localhost:8080 and the Amazon Account think have the Id “account1”:

http://localhost:8080/amazonechocontrol/account1/PROXY/api/notifications

This call will return a json. It should be possible to use this in a rule.

But I’am thinking already about a new channel to provide the next alarm, timer and reminder. But there is not yet a timeframe for this.

Best,
Michael

1 Like

Is there any plans to control items directly, not via routines? I would like to control a thing that has on and off as an option in the app but is a thermostat thing. When setting up a routine it only allows me to change the temp of the thing which doesn’t actually work and no on or off option. I’m talking to the developers to see if they can fix but if I could control the thing direct it would prevent a bunch of one step routines (and fix my problem and not rely on the vendor)

Not from my side, because I have no devices which are only controlled from alexa.

Good afternoon,
I’m using Version 2.5.0, but for some reasons the “Off” command for turning the Alexa Radio “off”
seems not to work. I’m getting the following errors:

2019-01-05 16:31:33.871 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.handleCommand()' on 'org.openhab.binding.amazonechocontrol.internal.handler.EchoHandler@176147c': POST url 'https://alexa.amazon.de/api/np/command?deviceSerialNumber=G090L91181820AT&deviceType=A3S5BH2HU6VA' failed: Not Found
org.openhab.binding.amazonechocontrol.internal.HttpException: POST url 'https://alexa.amazon.de/api/np/command?deviceSerialNumber=G090L91181820AT&deviceType=A3S5BH2HU6VA' failed: Not Found
	at org.openhab.binding.amazonechocontrol.internal.Connection.makeRequest(Connection.java:583) [237:org.openhab.binding.amazonechocontrol:2.5.0.Beta_01]
	at org.openhab.binding.amazonechocontrol.internal.Connection.command(Connection.java:901) [237:org.openhab.binding.amazonechocontrol:2.5.0.Beta_01]
	at org.openhab.binding.amazonechocontrol.internal.Connection.playRadio(Connection.java:965) [237:org.openhab.binding.amazonechocontrol:2.5.0.Beta_01]
	at org.openhab.binding.amazonechocontrol.internal.handler.EchoHandler.handleCommand(EchoHandler.java:494) [237:org.openhab.binding.amazonechocontrol:2.5.0.Beta_01]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:153) [101:org.eclipse.smarthome.core:0.10.0.oh230]
	at org.eclipse.smarthome.core.internal.common.InvocationHandlerSync.invoke(InvocationHandlerSync.java:59) [101:org.eclipse.smarthome.core:0.10.0.oh230]
	at com.sun.proxy.$Proxy166.handleCommand(Unknown Source) [237:org.openhab.binding.amazonechocontrol:2.5.0.Beta_01]
	at org.eclipse.smarthome.core.thing.internal.profiles.ProfileCallbackImpl.handleCommand(ProfileCallbackImpl.java:75) [108:org.eclipse.smarthome.core.thing:0.10.0.oh230]
	at org.eclipse.smarthome.core.thing.internal.profiles.SystemDefaultProfile.onCommandFromItem(SystemDefaultProfile.java:49) [108:org.eclipse.smarthome.core.thing:0.10.0.oh230]
	at sun.reflect.GeneratedMethodAccessor76.invoke(Unknown Source) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:153) [101:org.eclipse.smarthome.core:0.10.0.oh230]
	at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:53) [101:org.eclipse.smarthome.core:0.10.0.oh230]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]

I’m using the following code:

AlexaEcho_Radio.sendCommand(OFF)

Switch AlexaEcho_Radio "TuneIn Radio"   {channel="amazonechocontrol:echo:account:echo1:radio"}

Other functions like Text to Speech work fine.
Has anyone any ideas?
Many thanks!

Question: if I understand it right then that binding is not able to tts a value from an openhab item, isnt it?

What value are you wanting? Take a look at the lastVoiceCommand feature and tagging.

one case I want to use is to tts my temperature items. dont think that lastVoiceCommand helps for that, or I dont understand what the feature does / work.

what I tried to is:

rule "Read Temperature Living Room"
when
   Item TestSwitch changed from OFF to ON 
then
    var moep = TemperatureItem1.state
     EchoDotLR.sendCommand(moep)
end

but seems that the item object doesnt work with that tts feature :confused: a normal string does work.

Try this:

EchoDotLR.sendCommand("" + TemperatureItem1.state)

1 Like

Change the var to a string.:wink: or just use the [ “Temperature” ] tag on your item.

2 Likes

oh you are right. .toString solved it. thx a lot! [“Temperature”] Tag I will also try

edit: maybe one more question: is there a way to tts room temperature on keyword “alexa, what is my living room temperature” ? and what could be best code design for it?

1 Like