Say it with strings!

I am trying organise my different Chromecast devices so that I can direct the SAY command to the appropriate Google Home Mini speaker without having to type the device ID

I have assigned and populated strings to hold the following

1. **Message** = "Hello, how are you today?"
2. **Voice** = "voicerss:enUS"
3. **Lounge_Chromecast_ID** = "chromecast:chromecast:123456789"

The syntax is SAY (Object text, String voice, String sink)
E.g. say(“Hello world!”, “voicerss:enUS”, “sonos:PLAY5:kitchen”)

It works fine if I use:
say(message.state.toString, voice.state.toString, “chromecast:chromecast:123456789”)

It does not work when I do:
say(message.state.toString, voice.state.toString, Lounge_Chromecast_ID.state.toString)

What is it about the final part of the SAY command that I am getting wrong?

These are Items? Only Items have a .state.

Thanks for pointing me in the right direction.

I was using string .items to hold the ID of various AudioSink
Eg.

String    Lounge_AudioSink
String    Lounge_Voice
String    Bedroom_AudioSink
String    Bedroom_Voice

Then in an initial setup .rule I assigned the respective strings the AudioSink’s device name and the voice to use

String    Lounge_AudioSink = "Chromecast:chromecast:123456789"
String    Lounge_Voice= "pollytts:Amy"
String    Bedroom_AudioSink = "Chromecast:chromecast:987654321"
String    Bedroom_Voice = "pollytts:Brian"

Once I converted the item to a variable before using in my other .rules I was able to play the speech file

var String AudioSink
AudioSink = Lounge_AudioSink.state.toString

var String Voice
Voice = Lounge_Voice.state.toString

var String Message
Message = "Wake up you awesome individual!"

say (Message, Voice,  AudioSink )

All this just to give the kids the ability to chose the voice they want for their rooms!

Thanks again

I am using a a simple string item which is holding human (child) readable names which can be switched on a sitemap. In the rule I use a switch case like:

switch  (selectedSpeaker) {
    case "Kueche":
      AudioSink = "sonos:PLAY1:RINCON_B8E937E0C16201400";
      break;
    case "Wohnzimmer":
      AudioSink = "sonos:PLAY1:RINCON_B8E937BDEF0E01400";
      break;
    case "Buero":
      AudioSink = "sonos:PLAY1:RINCON_949F3E7D2EF401400";
      break;
    case "Gaestezimmer":
      AudioSink = "sonos:PLAY1:RINCON_B8E937E0C14201400";
      break;
    default:
      AudioSink = "sonos:PLAY1:RINCON_B8E937BDEF0E01400";
    }

That way the unreadable part is hardcoded in the rule only.

Ohhhh nice and tidy!

I have used this method in other places.
I never thought to use it in this situation.

Thanks for the example

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.