Contact Items Broken?

Hi Folks,

I have an OpenHAB 2.1 installation on Debian from the stable repo, and it seems to have an issue with Contact items.

I have items set like this:

Contact MS4_Door "MultiSensor 4 Door Contact [%s]" <door> (gMS0) {mqtt="<[MQTT:sensors-out/14/0/1/0/2:command:MAP(]"}

With the transformation map like this:


Which when the MQTT broker receives a message from the sensor on the correct topic with a payload of 0 or 1, produces a log message like this:

2017-08-15 18:09:13.777 [WARN ] [] - given command is NULL, couldn't post command for 'MS4_Door'

Trying to debug using the console produces this:

openhab> smarthome:send MS4_Door OPEN
Error: Command 'OPEN' is not valid for item 'MS4_Door'
Valid command types are:
  RefreshType: REFRESH

Yet when I create a rule like this:

rule "Test"
	Item TestPoint changed
	if(TestPoint.state == ON) {
	} else {

…and activate it using the “TestPoint” switch on my sitemap, it seems to work fine:

2017-08-15 18:15:21.651 [ItemCommandEvent          ] - Item 'TestPoint' received command ON
2017-08-15 18:15:21.658 [ItemStateChangedEvent     ] - TestPoint changed from OFF to ON
2017-08-15 18:15:21.664 [ItemCommandEvent          ] - Item 'MS4_Door' received command OPEN
2017-08-15 18:15:21.668 [ItemStateChangedEvent     ] - MS4_Door changed from NULL to OPEN

I don’t understand why a rule can interact correctly with this item but neither the console nor the MQTT binding seem to be able to. Am I missing something or is this a bug?

Use state. It makes no sense to command a contact. That is one of the big difference between switch and contact. Contacts are intended to be strictly a value and never to be used to control devices.

Okay so changing the binding config from “command” to “state” made it work. Thanks!

However, the reason I wanted to use “command” there was so that the rules that I have for recording the last change of state can trigger on “received command”. This way the “LastChange” items only change on actual MQTT messages and not on other things like being restored on startup, or when the items files change.

Is there another way to have a DateTime item record the last time a Contact changed, without it recording all the spurious changes on startup or file reload?

Use a Switch instead.

Or use

Item MyItem changed from OPEN to CLOSED or 
Item MyItem changed from CLOSED to OPEN
1 Like