Command item State to NULL? - sendCommand(NULL) does not work postUpdate(NULL) does

Running OH 2.2.0 release build.

Dimmer testDimmer
String testString
...
testDimmer.postUpdate(NULL)
if (testDimmer.state == NULL) {
	testString.sendCommand("is NULL!")
} else {
	testString.sendCommand(testDimmer.state.toString)
}
...

When the above code is executed the if branch runs and “is NULL!” is set as the state of testString.

...
testDimmer.sendCommand(NULL)
...

The above code, Commanding the item to NULL, does not compile with error ‘cannot convert from UnDefType to String’

...
testDimmer.sendCommand(NULL.toString)
...

Results in a runtime error: Cannot convert 'NULL' to a command type which item 'testDimmer' accepts: [PercentType, OnOffType, IncreaseDecreaseType, RefreshType]

I need to be able to Command the item ‘testDimmer’ to NULL as I have code that I only want to run on ‘received command’ and then check if the receivedCommand == NULL vs a different command.
I am trying to use the state NULL as ‘not set’ and run one set of actions vs a different set of actions if the item is commanded to a ‘real’ value.

Why can a Dimmer Item be Updated to NULL but not Commanded to NULL?

I realise that NULL is akin to UnDef in previous builds of OH and things have changed in this area recently but really what I need is a way to Command the state of an item to the ‘undefined’ state.

Thanks

Edit: I also tried:
testDimmer.sendCommand(UnDefType.UNDEF.toString) but it results in the same runtime error: Cannot convert 'UNDEF'...

You simply can’t send NULL as a command.

sendCommand() is sent to a binding (when the item is linked to a binding), while postUpdate() will simply change the state of an item without sending a command.

So, it’s obvious that you can set a state to NULL, but can’t send a command NULL.

1 Like