Release Candidate and Support: Amazon Echo Control Binding

Thanks @michi - I use a motion sensor in the bathroom to play lounge music on my echo when something moves in the room. Unfortunately, I can no longer listen to my Flash briefing because the motion sensor always interferes when I don’t intercept it. So there is probably no way to solve the problem at the moment?

I use jython rules, but here’s how I do it to operate my fans by just saying “turn on (or off) the fan” from a room. It can be adapted pretty easily to do whatever you want based on the echo name and command, as is pretty simple so should be easily converted to old style rule syntax. My echo devices are all set up with this format:

String Echo_Bedroom_LastVoiceCommand              "Echo Bedroom Last Voice Command"                     (GAlexa_LastCommand)       {channel="amazonechocontrol:echo:echo_account:xxxxxxxxxx:lastVoiceCommand"}

and my fans like this:

Dimmer      Bedroom_Fan_Speed_Dimmer     "Bedroom Fan"                           {channel="isy:fanlinc:isy_ap:xxxxxx:load2"}

Here’s the actual rule:

@rule("Alexa Last Command")
@when("Member of GAlexa_LastCommand received update")
def alexaLastCommandEvent(event):
    #ignore groups
    if str(ir.getItem(event.itemName).type) == "Group":
        return
    #get "room" name, i.e. Echo_Bedroom_LastVoiceCommand becomes Bedroom
    echoName = event.itemName.replace("Echo_","").replace("_LastVoiceCommand","")
    echoCommand = event.itemState.toString()

    if echoCommand == "turn on the fan":
        events.sendCommand(echoName + "_Fan_Speed_Dimmer","100")
    elif echoCommand == "turn off the fan":
        events.sendCommand(echoName + "_Fan_Speed_Dimmer","OFF")

Edit:
I also needed to create dummy “turn on the fan” and “turn off the fan” routines so Alexa wouldn’t complain that it didn’t know what to do. Mine just have a switch called “AlexaDoNothing” that isn’t linked to anything that the routine just toggles on and off, but you can have it do anything you want like say something.

1 Like

Wow!
That’s just great!
I hope i will be able to adapt! I’ll give it a shot in the near future!
At the moment i have a CPU load issue i have to identify …

This looks very promising as I’ve been attempting to do this for a while.

I have the lastVoiceCommand in the Items files as shown in your example (obviously for my echo devices!) I.e:

String   Echo_Kitchen_LastVoiceCommand            "Last Voice Command"                                             (GAlexa_LastCommand)            { channel="amazonechocontrol:echo:account1:XXXXXXXXXXXXXXXX:lastVoiveCommand"}

also have added (for testing)

// Dummy Items so Alexa does not complain that it doesn't know what things are!
Switch Television "Dummy Television" [ "Switchable" ]

can you assist in how the following is ‘converted’ to a rule type code?

def alexaLastCommandEvent(event):
    #ignore groups
    if str(ir.getItem(event.itemName).type) == "Group":
        return
    #get "room" name, i.e. Echo_Bedroom_LastVoiceCommand becomes Bedroom
    echoName = event.itemName.replace("Echo_","").replace("_LastVoiceCommand","")
    echoCommand = event.itemState.toString()

Thank you.

Should have tried working it out really before asking the questions - was just being lazy!!

Here is the ‘converted’ code:

rule "Amazon Echo Last Command"
when
	Member of GAlexa_LastCommand received update	
then
	logInfo("amazonEcho.rules","Last Command triggered!" + triggeringItem.name)
	
    //get "room" name, i.e. Echo_Bedroom_LastVoiceCommand becomes Bedroom
    var echoName = triggeringItem.name.split("_").get(1)
    var echoCommand = triggeringItem.state.toString()

	logInfo("amazonEcho.rules","echoName: " + echoName + ", echoCommand: " + echoCommand)
end

have changed the .relace functions with .get as all my devices are set up as Echo_PlaceName_Command so .get(1) seems a bit easier to me than replacing the ‘Echo’ and the ‘Command’ parts.

Heads up. I made a working countdown timer for the next timer channel to display in HabPanel. I could use some help tidying up the rule. All the details are in this post: [Solved] Amazon Echo Binding: Next Timer Channel - Create a visual timer countdown for Habpanel like echo show

New beta version with new features: Preview and Beta: Amazon Echo Control
Best,
Michael

Love your work on this binding. One of the most useful bindings for me! Is there any news on when lists might become supported?

Be so awesome to be able to see items on your shopping list :grin:

1 Like

Is there already a solution for this problem? I get the error as well?

Testeted on amazon.es and work fine

In PaperUI remove the musicProviderId channel and see if that helps. You may need to restart OH as well.

You are using an old version of the binding (Maybe the 2.4 released one). The callstack shows, that the StateDescriptionProvider makes an REST call.
Please update to the version in this thread.

I am trying to configure the echo dot. I have amazon echo account configured. Through paper UI if I switch on the flash briefing and select the echo device it starts playing. However, there is a weird behaviour in terms of items and sitemap. I have never been able to get it working. Also my echo device does not show online at all below is the snapshot, before this my thing configuration

Bridge amazonechocontrol:account:accountMy “Amazon Account” @ “My Room”
{
Thing echo echo1 “Alexa” @ “Living Room” [serialNumber=“blahblahblah”]
Thing wha wha1 “Ground Floor Music Group” @ “Music Groups” [serialNumber=“blahblahblahblah”]
Thing flashbriefingprofile flashbriefing1 “Flash Briefing Technical” @ “Flash Briefings”
Thing flashbriefingprofile flashbriefing2 “Flash Briefing Life Style” @ “Flash Briefings”
}

As I said my paper UI works only for flash briefing and nothing else. Am I missing something.

I guess I was able to get this working after a reboot. It works now :stuck_out_tongue:

1 Like

Does this support echo auto? If so, what thing type id should be used?

I have all my echos (12) TTS in a group called gEchoTTS. When I want to send a TTS message to that group, I get:

2019-11-20 08:55:48.651 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.handleCommand()' on 'org.openhab.binding.amazonechocontrol.internal.handler.EchoHandler@ce4cab': POST url 'https://alexa.amazon.com/api/behaviors/preview' failed: Too Many Requests

org.openhab.binding.amazonechocontrol.internal.HttpException: POST url 'https://alexa.amazon.com/api/behaviors/preview' failed: Too Many Requests

	at org.openhab.binding.amazonechocontrol.internal.Connection.makeRequest(Connection.java:654) ~[?:?]

	at org.openhab.binding.amazonechocontrol.internal.Connection.executeSequenceNode(Connection.java:1472) ~[?:?]

	at org.openhab.binding.amazonechocontrol.internal.Connection.executeSequenceCommand(Connection.java:1457) ~[?:?]

	at org.openhab.binding.amazonechocontrol.internal.Connection.executeSequenceCommandWithVolume(Connection.java:1448) ~[?:?]

	at org.openhab.binding.amazonechocontrol.internal.Connection.textToSpeech(Connection.java:1421) ~[?:?]

	at org.openhab.binding.amazonechocontrol.internal.handler.EchoHandler.startTextToSpeech(EchoHandler.java:784) ~[?:?]

	at org.openhab.binding.amazonechocontrol.internal.handler.EchoHandler.handleCommand(EchoHandler.java:631) ~[?:?]

	at sun.reflect.GeneratedMethodAccessor94.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) [102:org.eclipse.smarthome.core:0.10.0.oh240]

	at org.eclipse.smarthome.core.internal.common.InvocationHandlerSync.invoke(InvocationHandlerSync.java:59) [102:org.eclipse.smarthome.core:0.10.0.oh240]

	at com.sun.proxy.$Proxy151.handleCommand(Unknown Source) [191:org.openhab.binding.amazonechocontrol:2.5.0.-2019-09-12]

	at org.eclipse.smarthome.core.thing.internal.profiles.ProfileCallbackImpl.handleCommand(ProfileCallbackImpl.java:75) [109:org.eclipse.smarthome.core.thing:0.10.0.oh240]

	at org.eclipse.smarthome.core.thing.internal.profiles.SystemDefaultProfile.onCommandFromItem(SystemDefaultProfile.java:49) [109:org.eclipse.smarthome.core.thing:0.10.0.oh240]

	at sun.reflect.GeneratedMethodAccessor93.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) [102:org.eclipse.smarthome.core:0.10.0.oh240]

	at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:53) [102:org.eclipse.smarthome.core:0.10.0.oh240]

	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) [?:?]

Is it possible to play a custom video/animation on the Echo Show screen via this binding?

If above is not possible. Is it possible to let the echo show show a countdown from 10 seconds?

No, and it can not supported. Only devices which you find in the routines configuration in the alexa app as as a selection option can be used.
Alexa Auto seem to be a “add-on” and not a real device.

This is a known issue. The amazon echo have a request limit. Do not use all devices for TTS at the same time.

No

Is a timer shown on echo show as countdown? If so, there would be a complicated possibility with an http call from a routine…