How to assemble say command

hi

I have a selection item to choose a specific squeezebox device. then I want to have that selection included in the say command. the following rule with a given device works fine:

rule "talk via openhab app"
    when 
        Item VoiceCommand received command
    then 
    	val device = transform("MAP", "squeezebox.map", ""+TalkToSqueezebox.state)
	logInfo("talk to openhab app", "device: "+device)
    	say (VoiceCommand.state.toString, "voicerss:deDE", "squeezebox:squeezeboxplayer:6f15899c:70f3950c8f11")
		
	end

but how can I include the val device in the say command? i tried various combinations without success. eg.

say (VoiceCommand.state.toString, "voicerss:deDE", device)
or
say (VoiceCommand.state.toString, "voicerss:deDE", ""+device)

any idea?

rule "talk via openhab app"
when 
    Item VoiceCommand received command
then 
    val String device = transform("MAP", "squeezebox.map", TalkToSqueezebox.state.toString)
    logInfo("talk to openhab app", "device: " + device)
    say (VoiceCommand.state.toString, "voicerss:deDE", device)
end

What does the log show?

the Log is clean, no errors but also no Events from squeezebox binding. it seems the say command does not even run.

What does the logInfo say?

it exactly reports device by it’s squeezeboxname: squeezebox:squeezeboxplayer:6f15899c:70f3950c8f11

I’m on a Business Trip that Week and can’t Access my Logfile remotely.

Ok, we’ll do some testing this week-end

I’m using hardcoded strings in order to set the device in my rule (see below). So I would say the use of the method .toString and the change to a Stgring type var should work!
You could check the device with a logInfo before sending the say command, that way you could check from elsewhere :wink:

rule "SagEtwas"

when 
  Item SayCommand received update
then
  logInfo ("SayCommand", "SayCommand ={}", SayCommand)
  var string AudioSink
  switch AudioSink {
    case Lautsprecher.state.toString=="Küche" : AudioSink="sonos:PLAY1:RINCON_xx1400"
    case Lautsprecher.state.toString=="Wohnzimmer" : AudioSink="sonos:PLAY1:RINCON_yy1400"
    case Lautsprecher.state.toString=="Gästezimmer" : AudioSink= "sonos:PLAY1:RINCON_zz1400"
    default:AudioSink="sonos:PLAY1:RINCON_xx1400"
    } 
  say(SayCommand.state.toString,"voicerss:deDE",AudioSink)
  logInfo("SayCommand","Es ist alles gesagt!")
end

thanks for your replies.
I tried @opus solution which I had to modify to get it work. instead of

say (VoiceCommand.state.toString, "voicerss:deDE", AudioSink)

I have to use

say (VoiceCommand.state.toString, "voicerss:deDE", ""+AudioSink)

that lead me to the idea to experiment with the “” inside the transformation file and var string instead of val. but still, I do not get my original code running.

the rule:

rule "talk via openhab app"
    when 
        Item VoiceCommand received command
    then 
    	        var AudioSink = transform("MAP", "squeezebox.map", ""+TalkToSqueezebox.state)
		logInfo("talk to openhab app", "device: "+AudioSink)
    	        say (VoiceCommand.state.toString, "voicerss:deDE", ""+AudioSink)	
    end

squeezebox.map:

1 ="squeezebox:squeezeboxplayer:6f32999c:0021ccd59076" 
2 ="squeezebox:squeezeboxplayer:6f32999c:70f3950c9d11" 
3 = "squeezebox:squeezeboxplayer:6f32999c:bda49be73f87" 
4 = "squeezebox:squeezeboxplayer:6f32999c:bda49be73xxx" 
5 = "squeezebox:squeezeboxplayer:6f32999c:bda49be73xxx" 

the log

2018-10-27 18:03:28.295 [ome.event.ItemCommandEvent] - Item 'VoiceCommand' received command Hallo Test
2018-10-27 18:03:33.207 [INFO ] [ome.model.script.talk to openhab app] - device: "squeezebox:squeezeboxplayer:6f32999c:0021ccd59076" 

and thats it, no more entries, no squeeze that sounds.

the rule that works:

rule "talk squeeze"
	when 
		Item VoiceCommand received command
	then
		var string AudioSink
  		switch AudioSink {
    		case TalkToSqueezebox.state == 1 : AudioSink = "squeezebox:squeezeboxplayer:6f32999c:0021ccd59076"
    		case TalkToSqueezebox.state == 2 : AudioSink = "squeezebox:squeezeboxplayer:6f32999c:70f3950c9d11"
    		case TalkToSqueezebox.state == 3 : AudioSink = "squeezebox:squeezeboxplayer:6f32999c:bda49be73f87" 
    		default:AudioSink = "squeezebox:squeezeboxplayer:6f32999c:0021ccd59076"
    	} 
  		say (VoiceCommand.state.toString, "voicerss:deDE", ""+AudioSink)
  		logInfo("talk to openhab app", "device: "+AudioSink)
  	end
2018-10-27 18:09:12.128 [ome.event.ItemCommandEvent] - Item 'VoiceCommand' received command howdy
2018-10-27 18:09:12.143 [vent.ItemStateChangedEvent] - VoiceCommand changed from Hallo to howdy
2018-10-27 18:09:17.940 [vent.ItemStateChangedEvent] - Player_homeserver changed from PAUSE to PLAY
2018-10-27 18:09:22.019 [vent.ItemStateChangedEvent] - Player_homeserver changed from PLAY to PAUSE
2018-10-27 18:09:22.031 [vent.ItemStateChangedEvent] - SqueezeboxVolume1 changed from 100 to 0
2018-10-27 18:09:23.622 [INFO ] [ome.model.script.talk to openhab app] - device: squeezebox:squeezeboxplayer:6f32999c:0021ccd59076

maybe it`s just a little thing I do not see…
thanks

I have no clue why it doesn’t work on your system the way it works for me.
I tried your logInfo line and do get this:

01:49.398 [INFO ] [ipse.smarthome.model.script.SayComand] - device: sonos:PLAY1:RINCON_949F3E7D2EF401400

Note the missing " around the device-string.
Again, I have no clue.