Creating a Lambda to Call Say (with extras)

I am attempting to setup a lambda to call the say command and then restore the volume afterwards. This is what I have

import org.eclipse.xtext.xbase.lib.Functions

val mySay= [ Dimmer playerVolume, String chromecastChannel, 
             String message, Number volume |
    var lastVolume = playerVolume.state

This doesn’t really save me a lot of time - the reason is that say requires a channel… It would be nice if I could somehow just pass in a Chromecast Item and have it get everything it needs from there. I tried extracting the channel from an item but couldn’t figure that out.

Is there a way to do this? Is there a better way than what I currently have?

Welcome to the openHAB forumđź‘‹

I can’t say if it works for your voice and audiosink, however this is the rule I am using with VoiceRSS and Sonos speakers ( it did work with a single chrome cast).

rule "SaySomething"

  Item SayCommand received update
  var String AudioSink
  switch AudioSink {
    case Lautsprecher.state.toString=="KĂĽche" : AudioSink="sonos:PLAY1:PlayKueche"
    case Lautsprecher.state.toString=="Wohnzimmer" : AudioSink="sonos:PLAY1:PlayWohnzimmer"
    case Lautsprecher.state.toString=="BĂĽro" : AudioSink= "sonos:PLAY1:PlayBuero"
    case Lautsprecher.state.toString=="Gästezimmer" : AudioSink= "sonos:PLAY1:PlayGaestezimmer"
  logInfo("SayCommand","Es ist alles gesagt!")

SayCommand is an item that holds the string to be spoken, AudioSink is an item that holds the human readable name of the to be selected Audiosink. Both are set on an HABPanel UI.
Note that using the Sonos binding resetting the volume is handled by the binding (thanks goto Lolodomo).


I can’t help you Anthony, but welcome to the OpenHAB community!

Thanks, that’s an interesting way of doing it, while it’s not what I was looking for it gives me some really interesting ideas for other stuff!