Alexa set TTS volume when null

I am using the Alexa binding and sometimes the TTS volume is not set or maybe that’s an outcome of an initial setup but either way, my presence detection is working but my check for null doesn’t seem to be. Think it was but won’t go there. Basically I do:

  if  (FamilyRoomAlexa_TextToSpeechVolume.state == null)
  var Number savedVolume = FamilyRoomAlexa_TextToSpeechVolume.state as Number

So if it’s null, I’m setting it to volume 0. Then either way I’m saving the prior value 0 or whatever it was. then upping it to 50


Is there something you can see wrong with my null check that would cause things not to trigger?



The .state of an Item that hasn’t been initialized yet (e.g. after system boot) is NULL
That’s different to the java style empty variable content of null

Thanks I’ll try. If I can reproduce it now. The only one I got to work originally was null but stopped. Plus it said null in the logs but will set to NULL.


Well, after you send a command to your Item, it will still have state NULL. Taking as Number of state NULL will give you null.
It takes time for commands, or even postUpdate to act.

Why not use if-else here?

  var Number savedVolume = 0
  if  (FamilyRoomAlexa_TextToSpeechVolume.state == NULL)
    } else {
       Number savedVolume = FamilyRoomAlexa_TextToSpeechVolume.state as Number

Any idea when I make this change I get:

This expression is not allowed in this context, since it doesn’t cause any side effects.



Surplus ‘Number’ in the else part