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

development
binding
alexa
Tags: #<Tag:0x00007fd3133e6320> #<Tag:0x00007fd3133e6190> #<Tag:0x00007fd3133e5ee8>

(Yann) #709

Hello,

I have 5 Alexa Echo/EchoDot and 3 of them are reporting UNDEF as volume level. Volume cannot be set neither.

Any idea of what can be the cause? Any way I can log what is going on?

Thank you in advance


(Thomas) #710
  1. You have a type-o. Change the alarm name to ‘ECHO:system_alerts_repetitive_01’

  2. The [%s] seen in your alarm item’s state-format field is not used; Omit the [%s] .

  • Thomas

(Mark) #711

Were the Echo’s playing anything at the time?
This post might help understand the situation:


(Philipp) #712

@Thomas: Thanks for this hint but unfortunately it was not solving my problem. I also tried to trigger to the alarm via the PaperUI Control board but with no success. I noticed that the Remind function does not work in my case either. All other functions like TTS, Flashbriefing, Volume etc. work without problems (as long as the login remains valid).

It’s the alarm & remind function working for you?
Thanks for support!

Philipp


(Thomas) #713

@Philipp, I am using the binding’s alarm command on four echo dots and it works with 100% success. I don’t use the remind function so I cannot comment on it.

The allowed alarm sound values might vary on different echo devices. I suggest you revisit the amazonechocontrol page and click on the echo device(s) you are using for alarm testing. Then confirm the Channel playAlarmSound Value you are using matches exactly as shown on the listed allowed values.

  • Thomas

(zolakk) #714

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)


(Philipp) #715

@Thomas: I accidentally found the root cause :sunglasses:. Exactly 2 hours after the last post, all my Echo’s have played the alarm. To be honest, it was a bit spooky because it was so unexpected, especially for my wife;). However, I realized directly that my OH server has set the wrong time zone. And indeed, after both devices are running in the same time zone, there are no more problems.

Thanks for your help!
Philipp


(Thomas) #716

@Philipp, Glad to hear you got it working.

  • Thomas

(The Squid) #717

Our of curiosity - could I play an alert tone before a TTS event? I’d like to have an “attention signal” before an announcement is made.

Sid


(Yann) #718

You are right: once the connection to Amazon account is reset, the volume resets to UNDEF until some media is started on the Echo device.
Wouldn’t it be smart to have the binding to initialize the Echo device volume level?


(Thomas) #719

@KidSquid

Here is what I do: I start the alarm sound a few seconds before the TTS and then I stop the alarm a few seconds after the TTS. The alarm sound will automatically mute while the TTS is spoken. The result is a pleasant ALARM-VOICE-ALARM. I use a couple timers to schedule the action sequence.

  • Thomas

(The Squid) #720

Do you have any example code you wouldn’t mind sharing?

Thanks,

Squid


(Mark) #721

I would also like to see the code you used to create an attention tone. Thanks, Mark.


(Slavisa Lukic) #722

Hi did anybody managed to output amazon echo TTS to a group?


(Thomas) #723

@KidSquid, @m4rk:

Here’s an example of how I bookend spoken TTS with alarm tones. Comments:

  1. Two of my echo dots are used in this voice alert.
  2. The volume is set to a preferred value at the beginning and is restored to the previous level at the end.
  3. The action begins with a few seconds of a pleasant alert sound. Then the TTS voice is spoken (alert sound is automatically muted). After the TTS voice ends the alert sound is heard again for a short time.
  4. Getting the right balance of alert tone and voice is a matter of playing with the timers’ duration parameter.
  5. Please don’t tease me for the unnecessary “?.cancel()” I use in my code. I do this to remind myself that every timer needs a graceful end, even if it has already ended.

This example was copied directly from my files. Although I’ve stripped out some unrelated code, all my vars and echo device names are as-is, so be prepared to change them to match your project.

Somewhere in your .item file you need these declarations:

// Virtual Control
String Echo_Kitchen_PlayAlarmSound   "Play Alarm Sound"   (Alexa_Kitchen)   {channel="amazonechocontrol:echo:accountTom:echoKitchen:playAlarmSound"}
String Echo_Theater_PlayAlarmSound   "Play Alarm Sound"   (Alexa_Theater)   {channel="amazonechocontrol:echo:accountTom:echoTheater:playAlarmSound"}

// Volume Control
Dimmer Echo_Kitchen_Volume               "Volume [%.0f %%]" <soundvolume>    (Alexa_Kitchen)   {channel="amazonechocontrol:echo:accountTom:echoKitchen:volume"}
Dimmer Echo_Theater_Volume               "Volume [%.0f %%]" <soundvolume>    (Alexa_Theater)   {channel="amazonechocontrol:echo:accountTom:echoTheater:volume"}

Near the top of your .rules file you’ll need this:

var Timer WasherStopVolumeTimer = null
var Timer WasherStopAlarmTimer1 = null
var Timer WasherStopAlarmTimer2 = null

val EchoVolumeKitchen   = 75
val EchoVolumeTheater   = 80

Somewhere in your .rules file (within in your action’s rule) you’ll create the voice-alarm sound:

val Echo_Kitchen_current_volume = Echo_Kitchen_Volume.state as Number
logInfo("LaundryBuddyWasher.rules" , 'Current Kitchen Echo Dot Volume = ' + Echo_Kitchen_current_volume)
Echo_Kitchen_Volume.sendCommand(EchoVolumeKitchen)
                
val Echo_Theater_current_volume = Echo_Theater_Volume.state as Number
logInfo("LaundryBuddyWasher.rules" , 'Current Theater Echo Dot Volume = ' + Echo_Theater_current_volume)
Echo_Theater_Volume.sendCommand(EchoVolumeTheater)

if (WasherStopVolumeTimer === null) {
    WasherStopVolumeTimer = createTimer(now.plusSeconds(1)) [|
        Echo_Kitchen_PlayAlarmSound.sendCommand('ECHO:system_alerts_melodic_07')
        Echo_Theater_PlayAlarmSound.sendCommand('ECHO:system_alerts_melodic_07')
        WasherStopVolumeTimer?.cancel()
        WasherStopVolumeTimer = null
    ]
}

if (WasherStopAlarmTimer1 === null) {
    WasherStopAlarmTimer1 = createTimer(now.plusSeconds(7)) [|
        Echo_Kitchen_TTS.sendCommand('Hello, the washer has stopped and your laundry is ready. I Repeat, your laundry is ready.')
        Echo_Theater_TTS.sendCommand('Hello, the washer has stopped and your laundry is ready. I Repeat, your laundry is ready.')
        WasherStopAlarmTimer1?.cancel()
        WasherStopAlarmTimer1 = null
    ]
}
if (WasherStopAlarmTimer2 === null) {
    WasherStopAlarmTimer2 = createTimer(now.plusSeconds(15)) [|
        Echo_Kitchen_PlayAlarmSound.sendCommand('')
        Echo_Theater_PlayAlarmSound.sendCommand('')
        Echo_Kitchen_Volume.sendCommand(Echo_Kitchen_current_volume)
        Echo_Theater_Volume.sendCommand(Echo_Theater_current_volume)
        WasherStopAlarmTimer2?.cancel()
        WasherStopAlarmTimer2 = null
    ]
}

(Thomas) #724

@lukics:
I’m using groups with TTS and alarm sounds without any issues. There’s nothing special required, just declare the group and its channel devices in your .items file. Same syntax as any other group.

  • Thomas

(Thomas) #725

@m4rk:
It’s interesting that you found TTS to be unreliable. I’m experiencing intermittent/random TTS Voice, perhaps one missing TTS every thirty messages.

I don’t see this problem with alarm sounds or volume control. OpenHab’s logs show that everything is fine, which makes this a difficult issue to fix.

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%.

For those that use this binding’s TTS Voice a lot, I’d be interested in knowing if you are also experiencing intermittent missing TTS messages.

  • Thomas

(Mark) #726

I didn’t get your code to work and so I fiddled around, simplified and ended up with this:
AlarmSound worked but not PlayAlarmSound

    Echo_AlarmSound.sendCommand('ECHO:system_alerts_melodic_07')
    Thread::sleep(20000)
    Echo_AlarmSound.sendCommand('')
    Echo_Volume.sendCommand(35)
    Thread::sleep(2000)
    Echo_Speak.sendCommand('Snow mode is off')

It works but its slow to ramp in volume. Is there a way to get the volume high from the start of the alarm? I tried setting volume but gets ignored, Is all the timer complication doing something I do not understand?

PS I saw very similar code to yours at top of the binding description. Also using timer.


(Thomas) #727

@m4rk:

It works but its slow to ramp in volume. Is there a way to get the volume high from the start of the alarm?

  • Your current code delays the volume command for 20 secs. You need to move your Echo_Volume.sendCommand(35) to the top of the routine if you want to control volume at the beginning.

Is all the timer complication doing something I do not understand?

  • Timers avoid the code blocking caused by Thread::sleep. That is to say, a Thread::sleep stops all other rules [in the file] from running until it expires. Timers don’t do this. They are spawned into their own independent thread and do not suspend (block) all the other activity in the .rule file.

I know there are plenty of fans for Thread::sleep to delay openhab commands, but I’m not one of them. I rarely use it. But everyone is different and I’m not here to push my coding preferences.

  • Thomas

(Slavisa Lukic) #728

Are the streams synced when plying TTS?
I created a group in Alexa App, this group appeared in OH Inbox and I created a Thing. Though there is no TTS channel in this Thing.