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)
{
FamilyRoomAlexa_TextToSpeechVolume.sendCommand(0)
}
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
NULL
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)
{
FamilyRoomAlexa_TextToSpeechVolume.sendCommand(0)
} else {
Number savedVolume = FamilyRoomAlexa_TextToSpeechVolume.state as Number
}