Switch Item status to mirror that of a Contact Item

  • Platform information:
    • Hardware: rpi 4
    • OS: openhabian
    • Java Runtime Environment:
    • openHAB version: 4.2
  • Issue of the topic:
    I have a Switch item that commands an Arduino relay (through MQTT, either 0 or 1 = ON or OFF), that relay acts as a button for a garage door, each press OPENS / STOPS / CLOSES the door.
    The door has a Zwave contact sensor linked to a Contact Item in Openhab.

So far, for years I have had 2 items, one Switch to either OPEN/CLOSE and one Contact Item which chows the real state of the door. Either closed or not. Sometimes both get unsynced when the physical button at the door is pressed, showing the Contac a closed door, but the cwitch an open one.

This is my third iteration in trying to use one single Item that reliably acts as a Switch (commands the door) and shows the true value of the Contact sensor. After extense reseach on the Community I have tried through a Rule:

// rule “Unir Switch Puerta GAR”
// when
// Item ZWaveNode004ZWA008DoorSensorPSGARCoches_DoorSensor received update
// then
// if (ZWaveNode004ZWA008DoorSensorPSGARCoches_DoorSensor.state == OPEN) {
// GenericMQTTThingPuertaGaraje_SwitchPuertaGaraje.sendCommand(ON)
// }
// if (ZWaveNode004ZWA008DoorSensorPSGARCoches_DoorSensor.state == CLOSED) {
// GenericMQTTThingPuertaGaraje_SwitchPuertaGaraje.sendCommand(OFF)
// }
// end

I have also tried the rule with postUpdate instead of sendCommand, but when you send the command the door beeps twice (as it had received 2 commands, one to open and a second on (either through postUpdate and/or sendCommand) and moves a couple of cms and stops.

I have tried with another solution offered by @rlkoshak in HERE “playing” with the vissibility of the Item depending on Contact status, but the Contact status does not udpate the Item status.

All in all, I am banging my head against the wall so decided to cry for help!

Thanks in advance!
Javi G.

  • Please post configurations (if applicable):
    • Items configuration related to the issue
    • Sitemap configuration related to the issue
    • Rules code related to the issue
    • Services configuration related to the issue
  • If logs where generated please post these here using code fences:

I’m pretty sure that one contact (and/or one switch) is not sufficient. To get full control, you’ll have to have two or three switch inputs (two: open/stop/open and close/stop/close; three: open, stop and close as different buttons) and at least two contacts (fully closed, fully open), better four (motor active, opening/closing).

The very least to add would be an additional contact, so one contact for fully closed, the other for fully opened. This way you could synchronize at least when reaching one of the end positions.

Of course at least when the door is closed, you can sync the button:

rule "Unir Switch Puerta GAR"
    Item ZWaveNode004ZWA008DoorSensorPSGARCoches_DoorSensor changed to CLOSED

so if the door was closed, set the button (without sending a command!) to OFF.
Please be aware of the difference between postUpdate() and sendCommand():
postUpdate() will only update the state of the Item,
sendCommand() will send a command to all linked channels.
If a postUpdate() results in real commands, then there is an issue in your implementation.

Another point: the one relay will be a momentary switch, right?
So four short pushes:

  1. start motor in one direction
  2. stop motor
  3. start motor in opposite directio,
  4. stop motor

So regardless if switching from ON to OFF or from OFF to ON, the relay will trigger a short impulse to the garage door motor control.
Does Arduino this part or is it a rule in openHAB? If openHAB rule, please show the rule. Please use code fences :slight_smile:

If your device does not report back to OH when it changes then you can’t get there from here.

I think this is the key. The Item that represents the button to control the garage door opener doesn’t really have a meaningful state. It’s sole purpose is to generate an event to tell the relay to toggle on and then off, simulating a button press. You are running into trouble because you are trying to force a state into an Item where there isn’t enough information available to show and maintain the state.

In short, unless you have some third sensor to tell OH whether the door is moving and in which direction it’s moving, you have no way to reliably represent the control as OPEN/STOP/CLOSE. The best you can do is if the contact says the door is OPEN, have the button read “CLOSE” and when it says the door is CLOSED have the button read “OPEN”. But you can never know when the door is actually moving all the time so you can’t reliably show “STOP”.