Alexa Voice Command Room Awareness via OH

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?)

The channel metadata parameter should include your device thing id. This equivalent to linking an item to a given channel in the UI.

ok now it works… was missing the plugin for transform …


now i just need to do a bit of regex magic for my case :smiley:

in the end i just changed the texttospeech in textCommand and used this

>
  if (category === null) return;
  val deviceName = transform("MAP", "alexa.map", category.toUpperCase + "-" + location)
  if (deviceName == "") return;
  val command = triggeringItem.state.toString.replace(category,deviceName)
  sendCommand(triggeringItem.name.replace("LastVoiceCommand", "TextToSpeech"), command)

basically the map change from the generic name to the correct name and trigger again alexa with the “correct” command… only problem is that alexa answer 2 times, but in this way i can say something like “open curtain at 50%” and is triggered without handle all the special cases

hey everyone,

Where is “triggeringItem” being defined? I’m getting an error that is a null object. Same goes for systemStarted.

Based on the examples above, I believe OH cannot query triggeringItem.State or systemStarted.State without those items being defined somewhere.

Thanks! I’m using OH 3.4M1 and according to one of the posts above the import statement should be

//For OH 2.x, you’ll need this import…
//import org.eclipse.smarthome.model.script.ScriptServiceUtil
//For OH 3.x, this import instead…
import org.openhab.core.model.script.ScriptServiceUtil

If this is correct, Can someone update the original post above example to reflect the changes needed for OH3?

Hi,

I need a little more help. I’m running on OH3.4M1. I’m testing this with “Alexa turn [on|off] the Fan”.
alexa.items:

Switch AlexaActivityFAN "Fan" {alexa="Activity", expire="1s"}

When the rule executes this portion of the script:

  val activityState = ScriptServiceUtil.getItemRegistry.getItem("AlexaActivity" + category.toUpperCase).state.toString
  logInfo("AlexaRoomAwareness", "item is " + "AlexaActivity" + category.toUpperCase + " - activityState is " + activityState);

  // Exit if activity item not triggered (state not defined)
  if (activityState == "NULL" || activityState == "UNDEF") return;

I get this in the logs:

2022-08-24 16:25:13.805 [INFO ] [core.model.script.AlexaRoomAwareness] - item is AlexaActivityFAN - activityState is NULL

I verified that AlexaActivityFAN exists in the UI, but it never changes state. When I manually change it, it changes to UNDEF.

What am I missing?

I got it to work by removing all the devices from Alexa and running device discovery again.

1 Like

Alexa Last Voice Command doesn’t work anymore for me… they disabled it? (it doesn’t update anymore)