Released: Openhab2 Amazon Echo Control Binding (controlling alexa from openhab2)

Tags: #<Tag:0x00007fd30fb7ae00> #<Tag:0x00007fd30fb7ac20> #<Tag:0x00007fd30fb7aae0>

(Thomas) #729

Are the streams synced when plying TTS?

They are not in sync.

The group is not created in the Alexa App. It is in the .items file.

(Yann) #730


I found a character pagecode issue: extended characters are not showing properly. For example, field Subtitle1 displays l’info whereas it should be l’info.

It seems to be a pagecode issue:

Is the problem coming from Amazon API or from the binding? Any way to handle this?

(Mark) #731

Thanks Thomas for the support.

I don’t have an items file. I am using PaperUI… I think you edited that bit out :slight_smile:

The 20secs delay is to allow time for the alarm volume to ramp. I tried setting the volume before the alarm but it still ramped and my TTS came during the volume ramp.

Thanks for the timer explanation. That’s very useful. I will consider using using that approach elsewhere in my rules file. I will research it some more.

I think I will start over again now I have it partially working.

(Mark) #732


It’s interesting that you found TTS to be unreliable. I’m experiencing intermittent/random TTS Voice, perhaps one missing TTS every thirty messages… snip…I’m envious that you fixed your TTS issue with just the volume command. I’m doing that too, plus several other things to help reduce the occurrence of missing TTS. I’ve made the TTS more reliable, but not 100%.

I am not sure if it was just the volume setting that helped with the reliability issues but maybe reliability problems were caused by trying to save the current volume into a variable and then using that to return the volume to its original state when it was in fact undefined from the start.

So, now I only save the current volume if the Echo is actually playing something and then volume definitely has a value. For all other situations I just send the volume for the TTS and not bother saving and returning to the previous volume.

So far, it seems to work more reliably that way.

(Mark) #733

Question: If a sleep is running in one rule are other rules that would have executed otherwise then queued until the sleep expires or do they just fail to run?

(Scott Rushworth) #734

They will be queued until there is another thread in the pool available.

(Thomas) #735

Yes, if the current Echo volume is undefined then saving it into a variable will cause TTS to fail. But that issue is clearly posted in the log file, so easy to identify. My randomly missing TTS voice problem has nothing in the log file to help solve the problem.

My latest theory is that a missing TTS might be due to a brief loss of the WiFi signal. I don’t think that there is any acknowledgement back to Openhab that the TTS Voice was received by the Echo and perhaps that is why nothing is posted in the logs. However, I’ve checked RSSI with the WiFi Analyzer App and it shows that all my Echo’s have sufficient signal strength from the router. So this theory is probably wrong.

  • Thomas

(Thomas) #736

I’m old school and I don’t create anything in PaperUI. Maybe PaperUI is involved in your problem.

For reference, I am only using Echo Dots. When they receive the Volume command they emit a beep sound (same beep I hear when I press the volume button on the unit) and immediately change volume. There is no delay on mine.

  • Thomas

(Mark) #737

I now have two versions working to give a nice chirrup just before the notification.

One using Sleep and the other using Timers. The timers is lot more complicated and more code. Can timers be used with msec for 0.5sec settings?

I don’t get a volume beep when adjusting the Echo volume by command and the alarm signal doesn’t drop in volume when Alexa speaks. It does beep if I adjust the volume directly on the Echo
I had to turn of the alarm volume ramp in the Alexa app.

Timer version

var Timer AlarmPlayTimer = null
var Timer SpeakTimer = null
var Timer AlarmStopTimer = null

if (AlarmPlayTimer === null) {
      AlarmPlayTimer = createTimer(now.plusSeconds(0)) [|
      AlarmPlayTimer = null
    if (AlarmStopTimer === null) {
      AlarmStopTimer = createTimer(now.plusSeconds(8)) [|
      AlarmStopTimer = null
    if (SpeakTimer === null) {
      SpeakTimer = createTimer(now.plusSeconds(10)) [|
      Echo_Speak.sendCommand('Snow mode is off')
      SpeakTimer = null

Sleep version

    Echo_Speak.sendCommand('Snow mode is set')


(Scott Rushworth) #738

Yes… now.plusSeconds(5).plusMillis(500) would be 5.5 seconds from now.

Come to think of it, you could just do now.plusMillis(5500) :slight_smile:

(Jay Jung) #739

I love this add-on and enjoying the Echo TTS.

I have a question though, is it possible to have a string item as a echo command instead of voice?

For example, send a command to ‘echo_command’ item to be ‘ask plex to play a movie’ instead of actually saying it to alexa.

I think this would open more options to customize my home automation :slight_smile:


(Bert Kaufmann) #740

Hi there,

this binding works like a charm with my echo’s. But I have also some Sonos One speakers, where Alex is also integrated.

Should it be possible to use this binding also with the Sonos One’s? They are recognized under “Amazon Echo Control - Amazon Account - Index” but I can’t get them working?

Does anyone have experience with it?

Best regards

(Mark) #741

Hi Thomas, or someone,

I tried to find out but failed… whats the difference between

Timer?.cancel() and Timer.cancel()

I see some people have the extra ‘?’ and some do not have it in their timer code. Is it regex?

I expect its a stupid question :slight_smile:

(Thomas) #742

The .?cancel is a macro that tests to see if the timer exists before terminating. That is to say, it is a shortcut way of executing:

if(TheTimer !== null) TheTimer.cancel

In the timer examples I provided earlier the “.? cancel” method could be written as “.cancel” because {in my examples} the declared timer would not be null. But I use the .?cancel method for code consistency and as a personal reminder to provide a graceful ending on all timers.

  • Thomas

(zolakk) #743

I’ve been narrowing down speed issues with my REST item calls taking forever (6000+ms) and it seems that for each of my four Echos, the following channels seem to add significant delays when the linked items are called. If I comment out the items attached to these channels my interface is nice and snappy but with them things take forever. Has anyone else ran into this?

AmazonPlayListId (adds about 300-400ms each)
PlayAlarmSound (adds about 400-600ms each)
PlayMusicProvider (adds about 800-1000ms each)

So I turned on debug logging on the binding, it seems that the delay I am experiencing is because every time something calls /rest/items with the above channels linked, the binding does a round trip to Amazon’s servers for each one. Has anyone else run into this and is there a way to use those channels without needing the call to Amazon for an item status call?

(Thomas) #744

Couple tips to share:

[1] I’m not sure if this has been discussed before, but I discovered that if a echo dot is offline (unplugged or dropped wifi), and a rule sets the volume, the entire .rule file will crash. Ugh!

I haven’t investigated further, but I suspect this issue would also affect any Echo Control command that is R/W (read/write). Fortunately it does not affect TTS because it is W only.

I use the volume command a lot and I want to prevent anything that could break/crash a rule file. My solution is to wrap the volume command with a test of the volume state. Like this:

//Near the top of your rule file:
val EchoVolumeKitchen = 60        // Volume Level, should be in steps of 10.

//Somewhere in your rule file:
if(Echo_Kitchen_Volume.state!=UNDEF && Echo_Kitchen_Volume.state!=NULL) {

A special rule to trap the device’s offline state needs to be created too, like this:

rule "Kitchen Echo Dot Online Status"
   Thing "amazonechocontrol:echo:accountTom:echoKitchen" changed
    var StatusEchoKitchen = ThingAction.getThingStatusInfo("amazonechocontrol:echo:accountTom:echoKitchen").getStatus()
    logInfo("AlexaTTS.rules" , 'Attention: Kitchen Echo Dot Status = ' + StatusEchoKitchen)

    if(StatusEchoKitchen.toString() == 'OFFLINE') {

[2] A useful volume control trick for saving and restoring the echo device’s default local volume is to use OpenHab’s storeStates() and restoreStates() functions. These are very clever functions that do all the work with little effort on our part. For full details see:

For example, before I change the volume (for a TTS announcement or PlayAlarmSound), I store the echo item’s current volume like this (two echo dots are shown in this example):

var VolumeStates = storeStates(Echo_Kitchen_Volume,Echo_Theater_Volume)

Then using a timer that executes after the TTS and/or alarm sound is finished, I do this:


When the volume states are restored, not only are their individual values refreshed with the saved values, the function also sends them (using the .items volume command) to all the affected echo devices for you. BTW, if an echo device is offline, and use the offline rule shown in Tip #1, these functions will gracefully ignore the offline device. Very cool!

  • Thomas

(Thomas) #745

Just an update: It’s been 10 days since changing the pollingIntervalInSeconds from 60 to 15 and the amazonechocontrol:account OFFLINE issue has not returned. I hope I haven’t jinxed my good fortune by saying this!

  • Thomas

(Thomas) #746

Yesterday’s brag of my good fortune with the “Offline” Amazon account bug appears to have angered the Bezos demons; Early this morning the problem returned.

I have a rule action that sends me an email whenever my Amazon account goes offline. When I woke up this morning I had an endless stream of emails waiting for me. It’s the same issue as reported by others, the Amazon account goes offline for a few seconds then goes back online. Rinse and repeat, every few seconds.

I visited the amazonechocontrol web page and it showed that my account and all echo devices were online. Many rapid page refreshes did not reveal any instances of being offline.

I modified my email alerts so that the Amazon account would need to be offline for at least 30 seconds before I got a notification. That provided an interesting observation. Along with the rapid online/offline dance, every five minutes the account would go offline for at least 30 secs.

I restarted Openhab (via PuTTY, systemctl restart openhab2.service), waited for the system to initialize, and then revisited the amazonechocontrol web page. It required an Amazon account login (without CAPTCHA). Now everything is working fine again.

I hope that someone finds a solution to this.

  • Thomas

(Andrew Pawelski) #747

Could you share your script for alerting when the account goes offline?

(Thomas) #748

Here’s the rule action, which will email the recipient when the Amazon Account is offline for more than 30 seconds.

// Near the top of your .rule file:
var Timer OfflineTimer = null
var DateTime ConnectionLostTime = null
val String emailRecipients = "" // Recipient email list. Separate multiple accounts with semicolon.

// Somewhere in your .rule file.
rule "Amazon Echo Account Online Status"
    Thing "amazonechocontrol:account:YOURACCOUNTNAME" changed
    var EchoThing = getThingStatusInfo("amazonechocontrol:account:YOURACCOUNTNAME").getStatus()
    logInfo("DeviceStatus.rules" , 'Amazon Account Status is ' + EchoThing)
    ConnectionLostTime = now
    if(EchoThing.toString() != 'ONLINE') {
        logInfo("DeviceStatus.rules" , 'Amazon Echo Account is now ' + EchoThing + '. Starting Offline Timer')
        if (OfflineTimer === null) {
            OfflineTimer = createTimer(now.plusSeconds(30)) [|
                OfflineTimer = null
                var AccountStatus = getThingStatusInfo("amazonechocontrol:account:YOURACCOUNTNAME").getStatus()
                if(AccountStatus.toString() == 'OFFLINE') {
                    logInfo("DeviceStatus.rules" , 'Amazon Echo Account offline too long. Sending email to ' + emailRecipients)
                    sendMail(emailRecipients, "Openhab Warning: Amazon Account is Offline!", "Openhab\'s Amazon Account Connection lost on " 
                    + ConnectionLostTime.toString('MM/dd/yy HH:mm a') + ".\r\n")
    else if(EchoThing.toString() == 'ONLINE') {
        logInfo("DeviceStatus.rules" , 'Amazon Echo Account is now ' + EchoThing + ', Canceled Offline Timer')
        OfflineTimer = null

Using OH2’s email rule requires that you setup the mail service per the published docs. The services/mail.cfg file will need your email provider’s details.

You can change the 30 second timer value to anything you wish, but shorter times may fill your email account with Account Offline messages!

  • Thomas