Adressing (TTS) Alexa Groups using ECMA-/Javascript

I have several Amazon-Echo devices on which I’d like to get speach-output (more or less) simultaneously. There seem to be ways with DSL but I don’t know that language. So I’d rather use Javascript which I’m by now at least slightly familiar with.
Of course I could use several commands such as: events.sendCommand(“Alexa1”,“Text to speak”);
This could be repeated with all Alexa Devices. But when one of them changes or if I’ll get another one, I’d have to change all rules …
So there should be a more general way, probably groups.

I could imagine things to work like this, but am quite unsure about the details:

  1. Define a group like “AlexaDevices”
  2. Have the AlexaDevices join that group. ← the entire device (Alexa1) or just the relevant item/channel such as Alexa1_TTS ?
  3. create the Javascript rule with events.sendCommand(XXX,“Text to speak”); ← what would xxx have to be to adress the correct Alexa_group items? something like xxx=AlexaDevices+"_TTS" ? But this doesn’t seem quite right and didn’t work …

Any ideas/hints?

  1. Yes. Realize that a Group isn’t all that special. It’s just an Item that has other Items as members. You can provide a type for the Group and an aggregation function but in this case I would assume you just need to define the Type to be String. I don’t know if sending a command to a Group without a type or a type that doesn’t match the type of its members will work.

  2. Just the relevant Item.

  3. A Group is an Item, just like any other. So XXX is the name of the Item to send the command to. In this case, the Item just happens to be a Group Item.

Hello Rich,
thanks for your help. But it still doesn’t work. Here’s what I did now:

  1. Define the group/item AlexaEG as string

  2. Have 2 (for now) items with the correct channels (_Sprich is the German channel for Speak or TTS), Looks like this:

  3. Send the text to the group item with this rule:

wiedergabedevice = "AlexaHolger_Sprich";
ausgabe = "Felix, fang bitte kein neues Spiel mehr an!";

events.sendCommand("AlexaHolger_SprichLautstarke","90");   <-- not relevant here, just to set the loudness
//events.sendCommand(wiedergabedevice,ausgabe);  <-- referring to the single Alexa from line 1 works

events.sendCommand("AlexaEG",ausgabe);   // this doesn't work

What happens is that the group gets the text, but not its members. So how do I tell OH to put the text to all of the group’s members?

First, AlexaEG should not be in the model. It’s not an Equipment. It’s not a Location. It’s a functional Group. At best, if it were to be put into the model, it belongs at the root of the Locations.

You might do well to review/rereview the Model and Items page of the getting started tutorial. Semantic Model | openHAB

Pay close attention to the restrictions:

  • A Location can only be the direct member of zero or one Location Group.
  • An Equipment can only be the direct member of zero or one Location, or the direct member of zero or one Equipment. Put another way, an Equipment can only be the direct member of one Group that has a semantic tag.
  • A Point can only be the direct member of zero or one Location, or the direct member of zero of one Equipment. Put another way, a Point can only be the direct member of one Group that has a Location or Equipment tag.

Because the model represents the physical, it makes no sense to deviate from these restrictions. An Equipment or Point cannot be in more than one location at the same time. A Point cannot be a part of more than one Equipment at the same time.

And later down

As discussed above, many Items and Groups are expected to be outside of the semantic model. Perhaps they are only supporting Items only used for Rules.

Look at Semantic Model | openHAB which shows how to create an Item outside the Model. You’ll choose Group for the type. Once you select that you’ll see a “Group members base type” option appear. Set that to String.

I can’t tell what you’ve defined the Group as in these screen shots. So I can’t tell. But review the instructions above for creating a Group outside the semantic model and go from there.

Just in that screen shot your model is going to need a lot of rework in order to properly generate the Overview Page and be used by HABot. If you are using neither, you shouldn’t bother with the model at all.

1 Like

Thank you, now I got it working (although there was no option to set the group item to string, just numbers and other types, so I left it)!

Actually I didn’t use the overview page so much (and have no idea what to do with HABot) so I didn’t notice there was a problem with my model. I used it to have some kind of structure/overview for myself when looking for items/equipment. But I’ll rethink that and maybe can make better use of the model then …