sendCommand to ContactItem issue

Hey, everybody!
I have encountered a strange behaviour of openhab.

I am trying to set the value of an item with type ContactItem using a rule

(function() {
 const { OPEN, CLOSED } = require("@runtime");

  items.contact_test.sendCommand(OPEN);
  items.contact_test.sendCommand(CLOSED);
  items.contact_test.sendCommand('OPEN');
  items.contact_test.sendCommand('CLOSED');

})()

However, in the console I get warning

2023-09-02 01:24:00.073 [WARN ] [rnal.defaultscope.ScriptBusEventImpl] - Command 'OPEN' cannot be parsed for item 'contact_test (Type=ContactItem, State=OPEN, Label=Contact test, Category=motion, Tags=[Point])'.
2023-09-02 01:24:00.075 [WARN ] [rnal.defaultscope.ScriptBusEventImpl] - Command 'CLOSED' cannot be parsed for item 'contact_test (Type=ContactItem, State=OPEN, Label=Contact test, Category=motion, Tags=[Point])'.
2023-09-02 01:24:00.077 [WARN ] [rnal.defaultscope.ScriptBusEventImpl] - Command 'OPEN' cannot be parsed for item 'contact_test (Type=ContactItem, State=OPEN, Label=Contact test, Category=motion, Tags=[Point])'.
2023-09-02 01:24:00.079 [WARN ] [rnal.defaultscope.ScriptBusEventImpl] - Command 'CLOSED' cannot be parsed for item 'contact_test (Type=ContactItem, State=OPEN, Label=Contact test, Category=motion, Tags=[Point])'.
  • Platform information:
    • Hardware: x86_64/4G RAM/storage 500G
    • OS: Debian 11 5.10.0-23-amd64
    • Java Runtime Environment: OpenJDK Runtime Environment Zulu17.44+15-CA (build 17.0.8+7-LTS)
    • openHAB version: 4.0.2

I think the type is just contact.

Try post update:

  items.contact_test.postUpdate("OPEN");

In fact, you can’t .sendCommand() to a Contact Item.

Please be aware that there is a fundamental difference between .sendCommand() and .postUpdate() (the former is to, well, send commands, the latter is to set the actual status of the Item.)
While in most cases the status will follow the sent command, it is not recommended to set the status of an Item with .sendCommand() as it’s… no command.
A sent command will result in triggering rules with the received command trigger as well as sending the command to all linked channels. openHAB will by default try to guess the most likely new status and will set the status of the Item accordingly to save some time. However, it will finally get the new status through the linked channels.
An update will result in an update of the status, nothing else.

As a contact Item is to refer to Contacts (at least by meaning), there is simply no command, a contact is not to be controlled from openHAB by definition.
If you have to, it’s simply no contact but a Switch (or a String).

I gave it as an example. Here’s my transformation that doesn’t work for the same reason. I get value from multiple sensors via zigbee getway and process the values using transforms. Here is an example of data from a motion sensor.

{"ZbReceived":{"kitchen_presence":{"Device":"0x286C","Name":"kitchen_presence","0500?00":"000000010000","ZoneStatusChange":0,"ZoneStatusChangeZone":1,"Occupancy":0,"Endpoint":1,"LinkQuality":55}}}

I need to get the value of “ZoneStatusChange”

 (function(input, name) {
  const { OPEN, CLOSED }  = require("@runtime");
  try {
    return JSON.parse(input)['ZbReceived'][name]['ZoneStatusChange'] == 1 ? OPEN : CLOSED;
  } catch(e) {}
  
})(input, name)

The code for this transformation causes the same error.
It’s a pity that it does.

Can you show us your items description?

How abut this it may help: