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

development
binding
alexa
Tags: #<Tag:0x00007f014b6afdd0> #<Tag:0x00007f014b6afb00> #<Tag:0x00007f014b6af7e0>

(Oliver) #1335

Extactly;)

my rule with a dummy TV Item:

rule "Echo_LastCommand TV"
when
	Item TV_Room received command
then
	Thread::sleep(1500)
	var Number state = 0
	if(Echo_Current.state instanceof DecimalType) state = Echo_Current.state  as DecimalType 	
	
		switch(state){
			case 1:{
				Echo_Bedroom_TTS.sendCommand("im Schlafzimmer")
				TV_Bedroom.sendCommand(receivedCommand)
			}
			case 2:{
				Echo_Living_TTS.sendCommand("im Wohnzimmer")
				TV_Living.sendCommand(receivedCommand)
			}
			case 3:{
				Echo_Children_TTS.sendCommand("im Kinderzimmer ist kein Fernseher oder ich weiss nicht davon.")
			}

		}
	
end

1500ms are needed here to get the current echo.


(Michael) #1336

Or you could just put Echos and Lights in groups through the Alexa app.
With groups you´re able to tell Alexa “turn on the light” and only the light(s) in the same group are switched on.

Or use the solution from Paul see here.


(JustAProgrammer) #1337

I exposed the OH group until now and said something like “turn on the livingroomlights”, does the same but probably a bit less elegant :smiley:


(JustAProgrammer) #1338

Cool thing, will do this in Jython, when everythings set up!


(Mike Karantakis) #1339

Hi everyone,
I would like to thank everyone from my side for building those amazing things here.
I want to be quick and do not spent your valuable time.
I have read more than 1000 replies regarding this binding but I couldn’t have an answer, Is there any way or rule that you can ask alexa do something, lets say turn the light on (light is “item”) and do it without discover the device in the alexa app?
Thank you again.
Mike


(Scott Rushworth) #1340

You could use the lastVoiceCommand Channel, or a group of Items linked to them, as a trigger for a rule that parses the contents, and then does things based on the content.


(Mike Karantakis) #1341

Thank you @5iver ,
could you please give an example for a simple switch?
My point is that I don’t want to use [ Switchable ] notice.


(Scott Rushworth) #1342

I use this for the VoiceCommand Item, and use “Alert” as a command word for it (nothing to do with Alexa… just OH). This is in Jython, but I could dig for an archive if you can’t convert. This should be very similar to what you’d need for this type of rule. I forgot to mention, you’ll need to create a routine with a confirmation ‘OK’, or Alexa will always respond with that she doesn’t know what you’re talking about.

@rule("Alert: Voice command alert")
@when("Item VoiceCommand received command")
def voiceCommandAlert(event):
    log.debug("VoiceCommand received [{}]".format(event.itemCommand))
    if "alert " in str(event.itemCommand).lower():
        content = str(event.itemCommand).lower().replace("alert ", "")
        if len(content) > 0:
            events.sendCommand("Audio_Notification", content)

Found it…

rule "Alert: VoiceCommand"
when
    Item VoiceCommand received command
then
    logInfo("Rules","Alert: VoiceCommand received [{}]",VoiceCommand.state)
    if (triggeringItem.state.toString.toLowerCase.contains("alert ")) {
        val content = VoiceCommand.state.toString.toLowerCase.replace("alert ", "")
        if (content.length > 0) {
            Audio_Notification.sendCommand(content)
        }
    }
end

(Mike Karantakis) #1343

I think that’s helps a lot!!! Thank you, I’ll try and get back.
Really thank you for your time @5iver .


(Scott Rushworth) #1344

You’re very welcome! You actually got me thinking about this… and I’d wanted to play with it for a while, so here is what I got working. Happy holidays!


(Mike Karantakis) #1345

Update.
Finally I didn’t make it through with the above. I need to find way to trigger items without ask echo to discover the devices… so without adding [“Switchable”] or [“Lighting”].
Any ideas?

ps. what that “LastVoiceCommand” is doing?


(Thomas) #1346

I will answer my own question after some months :slight_smile:
Thanks to # idkpmiller [post 1213] I was able to write a rule which triggers according to the “alexa” keyword.

I have two echo dots.

items:

    Group gAlexa_voice
    String Echo_LastCommand_W       "Last Command"          (gAlexa_voice)  {channel="amazonechocontrol:echo:account1:echo2:lastVoiceCommand"}
    String Echo_LastCommand_K       "Last Command"          (gAlexa_voice)  {channel="amazonechocontrol:echo:account1:echo1:lastVoiceCommand"}

rule

rule "Get Alexa keyword"
when
 Member of gAlexa_voice changed to "alexa"
then
//do something
end

(Michael Geramb) #1347

BETA 2.5 (1) released:

This version implements a cache for the dynamic channel state descriptions. This results in a better performance for the REST calls and PaperUI.

Check the first post in this thread for the download link.

Best,
Michael


(Yann) #1348

Hello @michi . 2.4/2.5 updates still do not fix the character encoding issue I raised few months ago. I just installed OH 2.4 on a brand new Windows 10 PC and still these wrong encoding when accessing OH from localhost:8080 (tested on Edge and Chrome browsers).

How can I help to troubleshoot this? Is anyone else experiencing the same?

In PaperUI:
image

image

I really need this to be fixed to use that nice binding properly!


(Michael Geramb) #1349

Hi Yann,

you can do the following to provide more information:

check the special characters in the result. Send me the request and response headers from the network tab of the device-request

Do the same for the url http(s)://youropenhab/amazonechocontrol//PROXY/api/devices-v2/device (e.g.: http://localhost:8080/amazonechocontrol/account1/PROXY/api/devices-v2/device)

Best regards,
Michael


(Yann) #1350

@michi: Just replied by PM with the details of headers / contents requested :wink:


(Michael Geramb) #1352

This issue will be fixed in the next beta (will be released in the next days)


(Michael) #1353

@michi i´ve got two questions regarding the binding and Alexa in general.

Does it have any reason that i´m not able to trigger rules with the lastVoiceCommand when there´s no empty routine in the Alexa app?
openHAB sees every call to one of my Echos but the rules are only triggered when there´s an empty routine that stops Alexa from saying “sorry i may not understand you” (or something like that).
I made some tests and my rules are only triggered with this workaround.


Do you know if there´s an info who gave a command to Alexa?
Maybe this would be a nice idea for an additional channel to make rules more personal.
There´s an option to train Alexa to your voice and she´s able to say who started the radio station when continuing.

kind regards
Michael


(Udo Weber) #1354

Hi michi,

I realized that I got an exception short after the TTS Channel was triggered by a rule with the new beta. Currently I’m not able to reproduce that exception. I only see it sometimes.

Greets Udo

2019-01-01 17:22:36.597 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method ‘ThingHandler.handleCommand()’ on ‘org.openhab.binding.amazonechocontrol.internal.handler.EchoHandler@a9b412’: POST url ‘https://alexa.amazon.de/api/behaviors/preview’ failed: Bad Request

org.openhab.binding.amazonechocontrol.internal.HttpException: POST url ‘https://alexa.amazon.de/api/behaviors/preview’ failed: Bad Request

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

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

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

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

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

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

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]

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.$Proxy108.handleCommand(Unknown Source) [224:org.openhab.binding.amazonechocontrol:2.5.0.Beta_01]

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.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]

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


(Udo Weber) #1355

Thanks for your reply, got it working, except the part with TTS for the Sonos.
I will give it a try with Google TTS and the use of audio sinks, if I have a solution I will come back with it to you. :wink:

Happy new Year :slight_smile:

@Bredmich
I think you missed the part, that we are talking about Sonos speakers with integrated Alexa, not the Amazon Echo or dot itself. Or did you get TTS working for a Sonos One? :slight_smile:

Greets Udo