Alexa Voice Command Room Awareness via OH

I like your post and will give this a try. Thanks for sharing it.

I am curious though how Alexa responds to “Alexa, turn on bedroom switch 1 for an hour”. I see how your code handles this but doesn’t the Echo device respond on it’s own first?

In testing I’ve done, Alexa tries to respond herself until openhab text arrives to override. The trick is finding a way to delay Alexa long enough for openhab to be the only response. Have you had success accomplishing this?

My use-case is related to room awareness feature. You won’t be able to use named device with my rule. As I mentioned before, the idea is that you setup a dummy Alexa activity item which will receive the command when calling it exactly by name such “turn on the lights” and therefore prevent the actual command from being sent to the actual device allowing the OH rule to handle it.

If you are looking to use named device, I guess you can use proxy items instead of being directly exposed to Alexa and control the actual device via rules similar to the one I mentioned.

As far as for response, you should just get an acknowledgement if you made the proper request. Keep in mind, this is a hack and there is not much control over delay and latency.

Thank you for pushing this idea into my head; I have been tracking presence based on HUE Motion sensors and now I’ve added talking to Alexa in a room as another data point for current motion identification in rooms.

Best, Jay

1 Like

Doing some testing and ran into a few errors. Appreciate any advice.
I believe the code for timers is missing needed group names.
Ran into error: The name ‘ScriptServiceUtil’ cannot be resolved to an item or type

You need to add the below line at the top of your rule file. It is actually part of the initial rule I posted above.

import org.eclipse.smarthome.model.script.ScriptServiceUtil

You will need to include this import at the top of the rule file…

import org.eclipse.smarthome.model.script.ScriptServiceUtil

More detail here…

1 Like

I was just trying to make use of this rule/script but I noticed that the LastVoiceCommand is not working for me on OH 3.2. Is it an issue from my openhab or is it releated to something else ?

That’s an issue with the Amazon Echo Control binding. I would suggest searching for that issue in the forum.

1 Like

Found it in the meantime, now using the latest binding jar file

I have a Dummy Switch I use so Alexa can tell me the current Gas Price (Question about Amazon Echo Control Speak Feature - #8 by J-N-K). Currently my rule is setup so if the Dummy Switch is triggered only on my living room alexa the answer will be said.

What I am to achieve now is to detect which Alexa Device has received the question, that triggered the dummy switch and have the same Device answering speaking the answer/current gas price.

I have 3 different Alexa devices, named this:
Livingroom
Bedroom
Kitchen

I am now having difficulties to understand how the scripts and rules exactly work to determine the alexa device that was triggered. May I ask you to elaborate how that would work. I seem to be to stupid to understand it how it is wirtten right now.

You could trigger your rule by a change to the lastVoiceCommand channel of your Echo and check if “gas price” is part of the command. If so, answer with the command, if not, do nothing.

Best Regards,

Jan

Here’s how I know which Alexa was spoken to OR last spoke.

This is pieces of my logic below. All my items for the Alexa are standardized for each room.

i.e. Echo_SourceRoom_ItemDesc

Member of AlexaCmds changed

var String sourceRoom = triggeringItem.name.split("").get(1)
var String TheRoom_TTS = "Echo
"+sourceRoom+"_TTS"

logInfo(“ECHO”,"TTS Device is " + TheRoom_TTS + “.”)
logInfo(“ECHO”,"Triggering Command is " + triggeringItem.state + “.”)

TheRoom_TTS.sendCommand(HouseAlarmMsg)

Best, Jay

3 Likes

Perfect. Thank you very much for this.
I solved it in the same way now!

Is it possible with the rule and scripts you @jeshab shared in your posts that alexa understands something like this correctly aswell ?

Alexa, turn on the lights for 10 minutes and 40 seconds ?

My rule fragment lines above is tied to a very long rule watching for last command and re-acting to it based on what is said. You’ll also have to create a rule in the Alexa app, so Alexa doesn’t try to react to what you said. I usually create a routine looking for those words and just have Alexa respond back either “Sure” or “Let me find out”.

Here’s just one example of it.

			if (systemStarted.state != ON && triggeringItem.state == 'loft temperature') { 
		
				logInfo("ECHO","Alexa Loft temperature Status via Voice has been triggered using " + triggeringItem.name)
					Thread::sleep(500)
				
				var String lofttemperature = '<speak><prosody rate="fast">Loft temperature, is unknown to me at this time.</prosody></speak>'
				if (systemStarted.state != ON && gLoftTemp.state !== null && gLoftTemp.state != NULL) {
					
					lofttemperature = '<speak>Loft temperature is, ' + gLoftTemp.state + ' degrees.</speak>'
				}
				
				TheRoom_TTS.sendCommand(lofttemperature)	
				return;
			}

Best, Jay

i don’t understand how to configure this…
i added a new thing →



and logged with my amazon account, after that it added all my echo devices/rooms/skills in things
now i have to edit the things and write the location of every echo? (it will be used as location var for the rule?)

after that from the item

Group gAlexaVoiceCommand "Alexa Voice Command"  <--- don't touch

String BedroomEchoDotLastVoiceCommand "Last Voice Command" (gAlexaVoiceCommand) {channel="CHANGETHISID?:lastVoiceCommand"} <-- change id 
String BedroomEchoDotTextToSpeech "Text to Speech" {channel="CHANGETHISID?:textToSpeech"}  <-- change id 

Switch BedroomFanPower "Bedroom Fan" {alexa="Switchable"} <--- useless just for example?

Switch AlexaActivityFan "Fan" {alexa="Activity", expire="1s"} <-- command that trigger the rule?

so when u say “alexa fan” the rule is triggered and follow the map config?

Correct. The activity item is a placeholder allowing a command to be received through the textToSpeech channel without returning a voice error and to trigger the rule.

and what about the strings? they need to be personalized?

Not sure to understand what you mean. Using the logic in the example above, you should be able to customize it for your use case.

i don’t understand the channel parameter :smiley: and the string value, is something u writed bc trigger some command of alexa?
bc i don’t see mentioned in the rules, so i don’t understand if is required stuff or is something else (u noticed the changes i made?)