Release Candidate and Support: Amazon Echo Control Binding

no matter which jar file i add to addons. my echo dot remains offline. all i get is below lines in openhab logs

2018-05-19 17:22:47.658 [hingStatusInfoChangedEvent] - 'amazonechocontrol:echo:account1:G090L9117XXXX' changed from OFFLINE to ONLINE
2018-05-19 17:22:48.141 [hingStatusInfoChangedEvent] - 'amazonechocontrol:echo:account1:G090L9117XXXX' changed from ONLINE to OFFLINE
2018-05-19 17:23:49.406 [hingStatusInfoChangedEvent] - 'amazonechocontrol:echo:account1:G090L9117XXXX' changed from OFFLINE to ONLINE
2018-05-19 17:23:49.831 [hingStatusInfoChangedEvent] - 'amazonechocontrol:echo:account1:G090L9117XXXX' changed from ONLINE to OFFLINE
2018-05-19 17:24:51.177 [hingStatusInfoChangedEvent] - 'amazonechocontrol:echo:account1:G090L9117XXXX' changed from OFFLINE to ONLINE
2018-05-19 17:24:51.535 [hingStatusInfoChangedEvent] - 'amazonechocontrol:echo:account1:G090L9117XXXX' changed from ONLINE to OFFLINE
2018-05-19 17:25:52.796 [hingStatusInfoChangedEvent] - 'amazonechocontrol:echo:account1:G090L9117XXXX' changed from OFFLINE to ONLINE
2018-05-19 17:25:53.177 [hingStatusInfoChangedEvent] - 'amazonechocontrol:echo:account1:G090L9117XXXX' changed from ONLINE to OFFLINE

echo
i tried
org.openhab.binding.amazonechocontrol_2.2.1.201805122332.jar
openhab version 2.2

Any permissions issue/missing?

I am using Raspberry Pi 3 B

i think i found a little bug, everytime OH is restarted an new FlashBriefing 1 is added to the inbox
not a big problem, since normally OH don’t need to be restarted often

i’m using openHAB 2.3.0~20180518082719-1 (Build #1281)

any timeline how long it will be until this RC is officially released? reeeeally looking forward to the TTS feature

I’ve set up a few:

"What's on today"

This tells me which bins need taking out (garden waste, general waste etc) which is not the same every week and other stuff such as whether the kids need to take sports gear to school or whether the snake needs feeding.
I had all the information already in openHAB so it was a five minute exercise.
There’s also

"What's on tomorrow"

And:

"Are there any windows open"

Again, I already have this information in openHAB.

Hi Tom. How did you get this Information in openhab?
Geräts,
Markus

Hi Michi,

thought about and worked on a solution that is “network based”. Works for me with 5 Amazon echo devices quite well:

This approach sniffs for network traffic and identifies the active echo device. With the key word “Alexa”, echo is starting to send 1400 byte packets through the web. I do then identify the MAC address of the device and set a StringItem in openHAB for the corresponding “active” echo device. This is then be used for the TTS command.

Works in general ok. Problem still is that also inactive echos do also send those packages from time to time. It does not happen to often, therefore the chance to have the “right” active device is good.

My python script looks like this:

#!/usr/bin/python3
# -*- coding: utf-8 -*-
from scapy.all import sniff, Ether
from datetime import datetime, timedelta
import os

#THIS HELPS TO AVOID SPAM OF STATUS UPDATES AND LIMITS
#STATUS UPDATES TO 1 PER 3 SECONDS PER DEVICE. MODIFY TO YOUR CONVENIENCE.
last_detect1 = datetime.now() - timedelta(seconds=3)
last_detect2 = datetime.now() - timedelta(seconds=3)


def pack_received(packet):
   #UNCOMMENT THE FOLLOWING TO TRACE PACKETS
   #packet.show() # debug statement

   #DEFINE YOUR MAC OF THE ALEXA DEVICE HERE AND BELOW IN FILTER
   if packet[Ether].src == 'xx:xx:xx:xx:xx:xx':         # This is the MAC of the first Alexa device
      global last_detect1
      now = datetime.now()
      if last_detect1 + timedelta(seconds=3) <= now:
         last_detect1 = now
         #SET IP AND PORT OF YOUR OPENHAB SYSTEM
         os.system('curl --max-time 2 --connect-timeout 2 --header "Content-Type: text/plain" --request POST --data "Echo_Falk_TTS" http://[IP:PORT]/rest/items/TTS_activeDevice >/dev/null 2>&1')

   if packet[Ether].src == 'xx:xx:xx:xx:xx:xx':         # This is the MAC of the second Alexa device
      global last_detect2
      now = datetime.now()
      if last_detect2 + timedelta(seconds=3) <= now:
         last_detect2 = now
         #SET IP AND PORT OF YOUR OPENHAB SYSTEM
         os.system('curl --max-time 2 --connect-timeout 2 --header "Content-Type: text/plain" --request POST --data "Echo_Bad_TTS" http://[IP:PORT]/rest/items/TTS_activeDevice >/dev/null 2>&1')

if __name__ == "__main__":
    #DEFINE YOUR MAC ADRESSES HERE AS WELL SINCE CPU LOAD MIGHT GO UP.
    #IT IS GOOD TO HAVE FILTER SORTED OUT MOST OF THE PACKETS.
    sniff(prn=pack_received, iface="br0", filter="ip[2:2] = 1400 and (ether src xx:xx:xx:xx:xx:xx or ether src xx:xx:xx:xx:xx:xx)", store=0, count=0)

This triggers a rule which is

var StringItem activeTTS = null

rule "Aktualisiere TTS_activeDevice"
    when
        Item TTS_activeDevice received command
    then
        activeTTS =  gAlexa_TTS.members.findFirst[name.equals(receivedCommand.toString)] as StringItem
end

I do all of this to get the location of family members as spoken answer from Alexa.
Command for the echo device is e.g.:

Alexa, search for Falk
Alexa, where is Falk

This is possible though the “routine” function within the Alexa app. It allows to define a phrase and link it to a smarthome item as provided by the openHAB Alexa skill.

Alexas answers to these questions are then like

Falk is at home
Falk is nearby [SOME STREET], [SOME CITY]

I have realized this by locating the iPhone with the iCloud binding, translating the coordinates into a real address through Google’s map API and send it as TTS to the active echo device.

Even though my approach still has room for improvement, I hope that helps to identify even more use cases for your great binding!

1 Like

Hi cadbures,
its definitely no permission issue. But there is an issues in my binding, which causes that the echos goes for a moment to the ONLINE state, if the are reported as OFFLINE.
But this is not help for you. Maybe you have used the wrong amazon domain?
Have you defined your devices manually or did you use the discover feature?

This is no problem. I use the binding by myself on a Raspberrry Pi

Kind regards,
Michael

Hi Falk,

Wow! This is a very interesting idea. And it brought me to a new idea. I could read the history to get the information what was spoken to which device.
But I have not a good idea in the moment, how can I bring this in the structure of a channel. Maybe I can provide a function which can be called from a rule.
Any suggestions for a better possibility are welcome!

Best regards,
Michael

Maybe a DateTime channel with the most recently spoken command time stamp?

The problem with a channel would be, that I get no active notification for a history change. And polling is to slow for such a function.

Hi michi,

I purchased this device in India.
I used amazon.in domain
when i defined manually. result, echo dot going ONLINE/OFFLINE
when i added it through discover feature, same result echo dot going ONLINE/OFFLINE
In both the ways result is same

Kind regards,
Cadbures

Perfect, works like a charm. The TTS thing is what I have been missing desperately with Echo.
A big hug to Amazon and to you, @michi !

Hi Michael.
All is online but get this error:

2018-05-20 20:24:45.421 [INFO ] [mazonechocontrol.internal.Connection] - Login failed: Login fails. Check your credentials and try to login with your webbrowser to http(s)://<youropenhab:yourport>/amazonechocontrol/...

2018-05-20 20:24:45.421 [ERROR] [onechocontrol.handler.AccountHandler] - check login fails {}

org.openhab.binding.amazonechocontrol.internal.ConnectionException: Login fails. Check your credentials and try to login with your webbrowser to http(s)://<youropenhab:yourport>/amazonechocontrol/...

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

	at org.openhab.binding.amazonechocontrol.handler.AccountHandler.checkLogin(AccountHandler.java:300) ~[?:?]

	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]

	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]

	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:?]

	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:?]

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

Any idea?
Thanks, Markus

Okay, after reboot the system, all is offline. :frowning:

It’s nothing clever - it’s all in rules.

The refuse collection stuff comes to us in paper format so I put it directly in a rule with switch-case for the special dates (holidays etc).
It’s one rule I have to edit once a year. There are better ways of doing it!

Coming from an older build? Then you need to:

Hi sihui.
No, it’s the newest. Running a couple of days and then this error.
Now with configure parameter = amazon.com the account goes online and flashbriefing too. But all echos are offline. But found by a thing.
But its a amazon.de account.
With amazon.de nothing will be found and the account is offline.

Yes, but if you did use a beta before you need to delete all things and readd them.

Yes, i have done so before. It’s the second time this error.
I deleted all things, remove the binding, starts OH again and installed the binding again. The only thing are my items. They are all the time in my home.items. Is this okay?
And why does it run then a couple of days?
Can i remove/delete something like a cache or update folder with old informations?

Yes, as long as the channel does not change it’s fine.

You could try deleting cache and tmp folder. Search the forum, lot’s of posts how to do it.

Have a folder amazonechocontrol in /var/lib/openhab2 with all the old trys to install the binding. But can not remove it after deinstalling the binding. Permission denied.
Use: rmdir “/var/lib/openhab2/amazonechocontrol”