OH3 - Change state of Contact Item Type

I want need to change a Contact item type state between OPEN <> CLOSED using a web link

http://<IP>/basicui/CMD?StatusFensterBadRechts=CLOSED
http://<IP>/basicui/CMD?StatusFensterBadRechts=OPEN

However it doesn’t work.
I change the item type from Contact to Switch for testing and this does work as expected.

http://<IP>/basicui/CMD?StatusFensterBadRechts=ON
http://<IP>/basicui/CMD?StatusFensterBadRechts=OFF

I also tried to change the Contact Item state using 2 Label-Cards with action Command, 1st with CLOSED and 2nd OPEN actionCommand.
However I cannot change the state :frowning:

Any clue what I do wrong?

component: oh-label-card
config:
  item: StatusFensterBadRechts
  action: command
  actionItem: StatusFensterBadRechts
  actionCommand: CLOSED
  title: CLOSED
slots: null

A contact item does not accept commands, simple as that.

And to elaborate a bit more, if you need to change these Items from a UI, you really should be using a Switch. Contacts are for binary sensors. A sensor doesn’t issue command nor does a sensor receive commands. That’s what Switches are for.

The UIs are all designed for controlling and viewing your home automation. Thus it only supports sending commands to Items, not updates. Consequently, you cannot change the state of a Contact through a UI.

The URLs you are trying to use to command this Contact are web UI URLs. This is an unofficial way to command Items through web calls and is not officially supported. However, openHAB does provide q very robust REST API that can be used to command and update Items through HTTP calls. But you have to use PUT and POST type calls, not GET type calls (e.g. the type of command that happens when you put a URL in your browser). Under Developer Tools there is a link to interactive docs that explain how to craft the calls to interact with OH through the REST API.

1 Like

Thanks a lot for the detailed explanation - much appreciated.
I will use the switch item in this case - it will work as well :slight_smile:

REST API doesn’t work unfortunately, as the source I sent the state from doesn’t support it.
The only solution is to use the UI URL.

Please keep in mind that this might stop working without announcement, as it is not officially supported…