Release Candidate and Support: Amazon Echo Control Binding

I’m experiencing the same. I did get it to work for a little while. Probably time to get an issue created to track this one (my hands are full at the moment).

Alexa SmartHome Devices:

Is it possible to control Alexa’s SmartHome Devices that are predefined within Alexa?

This rule tied to a virtual switch isn’t working so maybe its my syntax or maybe it’s not possible yet?

rule “Alexa Turns Fans ON”
when
Item All_Fans changed to ON
then
Echo_Living_Room_StartCommand.sendCommand(‘Fans On’)
Thread::sleep(3000) // 3 second wait
Echo_Living_Room_StartCommand.sendCommand(‘Fans On’)
end

Any help would be appreciated.

Best, Jay

@bezibaerchen,

Which version of Java are you using. if i can reproduce your issue on my device
I use
java version “1.8.0_171”
openhab2 Snapshot 2.3.0 installed via apt-get
It works well with the above setup

Regards
Cadbures

If you want Alexa make an announcement for testing then isn’t Speak channel the way to do it. Or I misunderstood your problem.

Anyway maybe the following is useful to you or someone else…

I found Alexa TTS unreliable if the play volume is undefined, which is often the case if Alexa wasn’t playing anything. Also, if Alexa is already playing something I return the volume setting to where is was before the fixed volume TTS announcement. Log info command is useful for debugging. So I did it like this:

Maybe if would be better if the rule started with when ‘Item’ changed from Off to On instead of just On as below.

rule 'Cistern pump On'
when
  Item CisternPump_Switch changed to ON
then
if (Echo_Player.state == PLAY) {
    val current_volume_echo = Echo_Volume.state as Number
    logInfo("Alexa" , 'Player state '+ Echo_Player.state + ' volume '+ Echo_Volume.state)
    Echo_Player.sendCommand(PAUSE)
    Thread::sleep(2000)
    Echo_Volume.sendCommand(35)
    Thread::sleep(2000)
    Echo_Speak.sendCommand('The cistern pump is on')
    Thread::sleep(4000)
    Echo_Volume.sendCommand(current_volume_echo)
    Thread::sleep(2000)
    Echo_Player.sendCommand(PLAY)
  }
  else {
    logInfo("Alexa" , 'Player state '+ Echo_Player.state + ' volume '+ Echo_Volume.state)
    Echo_Volume.sendCommand(35)
    Thread::sleep(2000)
    Echo_Speak.sendCommand('The cistern pump is on')
  } 
end

It’s definitely a tough one as I believe I tried everything without luck. Thanks for your tests.
Amazon account looks fine.

Java information:

dpkg -l | grep java
ii  java-common                             0.56ubuntu2                                all          Base package for Java runtimes
ii  javascript-common                       11                                         all          Base support for JavaScript library packages
ii  nodejs                                  4.2.6~dfsg-1ubuntu4.1                      amd64        evented I/O for V8 javascript
ii  nodejs-dev                              4.2.6~dfsg-1ubuntu4.1                      amd64        evented I/O for V8 javascript (development files)
ii  oracle-java8-installer                  8u171-1~webupd8~0                          all          Oracle Java(TM) Development Kit (JDK) 8
ii  oracle-java8-set-default                8u171-1~webupd8~0                          all          Set Oracle JDK 8 as default Java

java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)

Openhab version information:

dpkg -l | grep openhab
ii  openhab2                                2.3.0-1                                    all          openhab2

I must admit I am unsure whether snapshot might improve things.
Currently using:

deb http://dl.bintray.com/openhab/apt-repo2 stable main

Hi bezibaerchen,

Did you try with older addons, manually adding them to addons folder.
org.openhab.binding.amazonechocontrol-2.3.0_RC3.jar
org.openhab.binding.amazonechocontrol-2.3.0-SNAPSHOT.jar

Regards
Cadbures

I tried org.openhab.binding.amazonechocontrol-2.3.0_RC3.jar

Where could I get hold of SNAPSHOT?

Hi bezibaerchen,

get it from here

Regards
Cadbures

Thanks for sharing. No luck with them either :frowning:

Only Difference i see is in your Java Version
Java HotSpot™ 64-Bit Server VM (build 25.171-b11, mixed mode)

Mine is java version “1.8.0_171”
Java™ SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot™ Client VM (build 25.171-b11, mixed mode)

Regards
Cadbures

I now went to OH 2.4 Snapshot with 2.4 version of binding. Same issues…

Hi Mark,

Thanks for your reply; I did learn some things from your post about setting volume from what it was set to and pausing the player first. Good stuff . . .

What I’m looking for is actually how to send commands to Alexa via OH2 which intern controls Alexa connected devices.

My example is I say to Alexa, “turn on fans” which means it will turn on all the fans in the house.

I want to send this command to Alexa and it actually executes the command (not necessary speaks it, but actually does the command as if I asked it to).

Best, Jay

@jwiseman: Here’s a couple ways to do it.

Method 1. Create “Routines” using the Amazon Alexa Mobile app.

Following your example, you would name a routine that turns on the fans and another that turns them off. Any devices registered in your Amazon account would be available to the routine, so each routine can control multiple fans.

Along with naming the routines in the mobile app, you also need to define the echo devices in your .items file and add the control actions to your .rules file. In your rules file you would use the Alexa Binding’s “startRoutine” command.

Method 2. Use the Hue Emulation Binding.
The Hue Emulation binding will allow you to use Alexa to control your devices. It’s what I use – Works great, very flexible, and not difficult to implement. The OpenHab2 docs has all the details.

  • Thomas

Hi Thomas,

Thank you very much for this! I choose Method 1 and here’s the final product:

rule “Alexa Turns Fans ON”
when
Item All_Fans_Switch changed from OFF to ON
then
logInfo(“Status”, “ALEXA: Sets All Fans to ON”)
// Sets Echo Volume
val current_volume_echo = Echo_Living_Room_Volume.state as Number
Echo_Living_Room_Volume.sendCommand(current_volume_echo)

    Echo_Living_Room_StartRoutine.sendCommand('turn routine fans on')
	Thread::sleep(2000)  // 2 second wait

	// Set individual fan states
	Office_Fan_Switch.postUpdate(ON)
	Parker_Fan_Switch.postUpdate(ON)
	Ryan_Fan_Switch.postUpdate(ON)
	Guest_Fan_Switch.postUpdate(ON)
	Bedroom_Fan_Switch.postUpdate(ON)

end

Thank you again!

You are welcome! It’s great to know it is working.

  • Thomas

Monitoring Amazon Connection?

Has anybody wrote a script to monitor if the Amazon connection is connected OK to the binding?

it would be nice to get an email knowing that we need to log back into your Amazon account after a reboot or cleanup of the cache/tmp directories.

Monitoring = http://openhab:8080/amazonechocontrol/account1

Best, Jay

Fantastic work! I’ve been using this binding for a few days now and I’m just thrilled.:grinning:

However, I have a problem with the PlayAlarmSound feature. No alarms are played. I have already tried several devices, but to no avail. An error message is not displayed in the logs.

Could you please give me a hint how to identify this problem?

Cheers,
Philipp

@Philipp

Check PaperUI->Configuration->items and confirm that all your declared Play Alarm Sound items are present.

Also check PaperUI->Configuration->Things and confirm all echo devices and the Amazon account are online.

For further help I suggest you post your .item and .rule code statements for the Play Alarm Sound items.

  • Thomas

@Thomas: Thanks for your support! Here is my configuration:

OpenHAB Version:                 2.4.0 Build #1305
AmazonEchoControl Version:       2.4.0.SNAPSHOT

echo.things

Bridge amazonechocontrol:account:account1 "Amazon Account" @ "Accounts" [amazonSite="amazon.de", email="philipp@test.de", password="Secret", pollingIntervalInSeconds=30]
{
    Thing echo                  LR_Echo             "Alexa"                     @ "Living Room"     [serialNumber="ABC"]
    Thing echo                  OF_Echo             "Alexa"                     @ "Office"          [serialNumber="DEF"]
    Thing echo                  BD_Echo             "Alexa"                     @ "Bedroom"         [serialNumber="GHI"]
    Thing echo                  BA_Echo             "Alexa"                     @ "Bathroom"        [serialNumber="JKL"]
    Thing wha                   APT_EchoMusicGroup  "Ground Floor Music Group"  @ "Music Groups"    [serialNumber="MNO"]
    Thing flashbriefingprofile  flashbriefing1      "Flash Briefing"            @ "Flash Briefings"
}

echo.items

/*...*/
String  LR_EchoLivingRoom_PlayAlarmSound  "LR Echo Living Room Play Alarm Sound [%s]"  <siren> (gLR_Echo) {channel="amazonechocontrol:echo:account1:LR_Echo:playAlarmSound"} 
/*...*/
String  OF_EchoOffice_PlayAlarmSound      "OF Echo Office Play Alarm Sound [%s]"       <siren> (gOF_Echo) {channel="amazonechocontrol:echo:account1:OF_Echo:playAlarmSound"}

test.rules

rule "Test Alarm"
when
    Item LR_MotionSensor changed to ON
then
    OF_EchoOffice_PlayAlarmSound.sendCommand('ECHO:system_alerts_repetitive01')
    logWarn("test", "play alarm")
end

logs:

2018-07-01 22:10:41.190 [WARN ] [.eclipse.smarthome.model.script.test] - play alarm
2018-07-01 22:10:41.189 [ome.event.ItemCommandEvent] - Item 'OF_EchoOffice_PlayAlarmSound' received command ECHO:system_alerts_repetitive01
2018-07-01 22:10:41.207 [vent.ItemStateChangedEvent] - OF_EchoOffice_PlayAlarmSound changed from  to ECHO:system_alerts_repetitive01

As I said, I get no error message and the echo remains silent :no_mouth:. Other features like TTS work fine. So the account setup seems to be ok. The internal login page (https://hab:8080/amazonechocontrol/account1) confirms that. Also the PaperUI status for all echo things and items looks fine.

Any ideas?