OH configuration for Alexa devices

I’m migrating from NodeRed to OH and almost everything is already operational.

I have a question about controlling Alexa devices.

In NodeRed I can configure a command as a single set.

See below:

return {
    "payload": {
        "type": "speakAtVolume",
        "payload": {
            "type": 'regular',
            "volume": '40',
            "devices": ['Echo Dot de Ricardo'],
            "text": msg.m_payload
        }
    }
}

When I use OH it seems that it is necessary to do each step of the configuration separately.

Example: adjust the volume and then send the message.

Is there a way to send the entire configuration in a single command?

No because the way OH communicates with devices is through commands to Items. If you don’t have a single Item that represents all those settings, you have to send separate commands to each Item individually.

However, Amazon Echo Control - Bindings | openHAB talks about a proxy to the Alexa API so maybe you can use sendHttpXRequest actions to interact with the API directly instead of through the Items.

Thank you for your help.

Maybe I’m doing something wrong.
Maybe the Amazon API and the OH documentation are no longer in sync.
I can’t use a json formatted string to control sound and volume in a single command.
I have an Echo Dot 4 with clock.
What’s working here is:

items.Echo_Dot_Speak_Volume.sendCommand(40)
items.Echo_Dot_Speak.sendCommand('Say something)

I hope someone else can double-check this setup and tell me what happens on their end with other Amazon devices.

I also don’t know how NodeRed does the trick of sending parameters in just one command.

 items.Echo_Dot_Speak.sendCommand('Say something')

You are missing the close quote. You should be seeing errors in the log.

Thank you. It was a typo in the copy and paste. There is a missing quote.

In the documentation https://www.openhab.org/addons/bindings/amazonechocontrol/#show-an-announcement-on-the-echo-show-or-echo-spot

I quote here:


Expert:

You can use a json formatted string to control title, sound and volume:

{"sound": true, "speak":"<Speak>", "title": "<Title>", "body": "<Body Text>", "volume": 20}

The combination of sound=true and speak in SSML syntax is not allowed. Not all properties need to be specified. The value for volume can be between 0 and 100 to set the volume. A volume value smaller then 0 means that the current alexa volume should be used. No specification uses the volume from the textToSpeechVolume channel.


Note that this is a command to be sent to the item linked to the announcement channel, not the TTS channel.

This is new to me too, so thanks for the question!

I am still looking for a local TTS engine that sounds as nice as Amazon’s or Google’s. If there’s one, we can play it on an audio sink like google home.

Amazon Polly (Echo) sounds nice but it has a bit of a delay.

Hi jimtng !

Which Amazon device do you have?

Mine is an Echo Dot 4th with clock and there is no TTS channel only Speak channel.

I tried the example:

{"sound": true, "speak":"<Speak>", "title": "<Title>", "body": "<Body Text>", "volume": 20}

Without success.

The only way I can make my Echo “speaks” is:

items.Echo_Dot_Sala_Speak_Volume.sendCommand(40)
items.Echo_Dot_Sala_Speak.sendCommand('Say something')

Using NodeRed I can send all parameters together, but in OH I must send the volume and then the message.

Can you provide an example of your Amazon device setup in OH?

You need the announcement channel.

I tried it on Echo Pop (2024) and Echo Dot (not sure which generation, but it’s at least 2-3 years old).

Oh yes… don’t use angle brackets in the text. This is the exact command I used in Karaf:

openhab> send StudyRoom_Echo_Announcement '{"sound": true, "speak":"Speak", "title": "Title", "body": "Body Text", "volume": 100}'

This is the Channel for that item:
amazonechocontrol:echo:account1:studyroom:announcement (String)

Here’s an example of how to command your item using JRuby:

require "json"

StudyRoom_Echo_Announcement << { speak: "Hello, World!", volume: 100 }.to_json

You can probably also use SSML in there.

I had a look around and found that there’s already one supported by openhab: PiperTTS. I like “English (US)” “hfc_female” voice, so I downloaded the onnx file. A brief test shows that it works very well and the voice is quite nice, i.e. not robotic.

Once set up, to make it work (using JRuby)

Voice.say "Hello, World!", volume: 100 # plays to the default sink
Voice.say "Hello, World!", sink: LivingRoom_GH_Player.thing.uid, volume: 100

This is my “Amazon Thing” configuration:

What about yours?

Mine is “Direct and over Alexa Skill”

Bridge amazonechocontrol:account:account1 "Amazon Account" @ "Accounts" [discoverSmartHome=2, pollingIntervalSmartHomeAlexa=10, pollingIntervalSmartSkills=120]

Thank you. Here I have no skills installed. Maybe I need one of them.

Do you have OH Alexa skill installed?

This is what I did:

items.Echo_Dot_Sala_Announcement.sendCommand('{speak: "Say something", volume: 80}')

As my Echo Dot has a display, I can see the volume level.

When I use Json it first change the volume to the one configured, returns to the previous volume and then “say something”.

If I use two step configuration I mean, first set the volume and them send the message, the message uses the volume I set.

I also don’t know how NodeRed works but I know it sets the correct volume even when I use all the paramaters in the same command.

Maybe NodeRed splits comands!

I had a look in the openhab amazonecho binding code. This json syntax is a made up syntax by the binding, so it’s very much specific to openhab only. Amazon doesn’t know anything about it.

The binding absolutely splits it into a separate sets of commands. So it’s a matter of inserting a delay.

The echo binding is currently undergoing a merge from smarthome/j. Once that’s merged, I want to add an extra parameter or setting to specify a custom delay between volume setting and announcement, if that’s possible.

I opened an issue to keep track / remind us of it. [amazonechocontrol] Add a customizable delay setting to wait between volume setting and speaking · Issue #18085 · openhab/openhab-addons · GitHub

I think this issue also applies to google home.

Hi jimtng !

Thank you so much for your help.