First of all, my decision to use switch item type for IO is exactly as @mstormi said: it may be used for in and out signals. However, if configured as input, it should also be possible to allow contact item type. Feel free to implement that
Concerning functionality, the contact item type is a subset of the switch item type, so you won’t gain features, your items would just be a bit more convenient.
One more thing regarding IO: if configured as input, the switch is inverted. I.e. if the physical contact is closed, the switch item is OFF. The reason is that the HUT has a pull-up resistor, not a pull-down resistor. (I hope I did not mix up the states, but it should be fairly easy to test this…)
If you still want a contact item type, add a (virtual) contact item without any binding and a rule that reacts on the switch change. Inside the rule, set the contact item depending I the switch item state. This way, you can also handle the inverted switch item state. Then use the contact item e.g. in your sitemaps.
Using the simple HUT relays for roller shutters is a bit more complicated because you have to add all the logic. I did it as follows, but there is still room for improvements.
- for each roller shutter, I have two relays and two physical pushdown buttons, one for up and one for down, respectively.
- I measured the total runtime X seconds for each roller shutter and in the HUT configuration, the relays are automatically switched off after X + 3 seconds (‘impuls’ setting, IIRC), so that there is no more power on the motor after it had completely moved up/down.
- in openhab, I had to ensure that both relays (for up and for down) are never enabled at the same time.
My items:
// actual relay items
Switch R_Rollo_Wohnen_up { anel=“anel1:F1”, autoupdate=“false” }
Switch R_Rollo_Wohnen_down { anel=“anel1:F2”, autoupdate=“false” }
Switch S_Rollo_Wohnen_up { anel=“anel1:IO1” }
Switch S_Rollo_Wohnen_down { anel=“anel1:IO2” }
// virtual item representing the roller shutter
Rollershutter R_Wohnen “Wohnzimmer” (gRollo)
Rules:
/*
- This set of rules controls the rollershutters.
- Please note that a timer is not needed in this rule because it is already set directly in the relays.
- E.g. for a long-running rollershutter: Impuls (an) für Zeit: 28s
*/
val org.eclipse.xtext.xbase.lib.Functions$Function2 rolloLogic = [
org.openhab.core.library.items.SwitchItem relayItem,
org.openhab.core.library.items.SwitchItem relayItemOpposite |
// if current state is off
if (relayItem.state != ON) {
// if opposite state is also off
if (relayItemOpposite.state != ON) {
// switch it on!
relayItem.sendCommand(ON)
} else { // opposite is on
// switch opposite off!
relayItemOpposite.sendCommand(OFF)
}
} else { // relay is on, so switch it off
// switch off!
relayItem.sendCommand(OFF)
}
]
rule "rollo Wohnen up"
when Item S_Rollo_Wohnen_up changed to OFF or Item R_Wohnen received command UP then
rolloLogic.apply(R_Rollo_Wohnen_up, R_Rollo_Wohnen_down)
end
rule "rollo Wohnen down"
when Item S_Rollo_Wohnen_down changed to OFF or Item R_Wohnen received command DOWN then
rolloLogic.apply(R_Rollo_Wohnen_down, R_Rollo_Wohnen_up)
end
rule "rollo wohnen stopp"
when Item R_Wohnen received command STOP then
R_Rollo_Wohnen_down.sendCommand(OFF)
try { Thread::sleep(100) } catch (InterruptedException e) { } // if commands are sent too fast, only one may be executed by anel device
R_Rollo_Wohnen_up.sendCommand(OFF)
end
Sitemap:
// group contains all roller shutters
Group item=gRollo
There is one feature that I did not yet implement: the actual state (e.g. in percent) of the roller shutter. This would require a timer that measures how long the up and down relays are on/off so that the state can be calculated from the total runtime and the recent state.
At least my configuration works well using physical switches as well as any openhab client. I thought adding logic to update the state in percent would be helpful but in practice, I don’t miss that feature: either I see it because I’m in that room or I simply move them up / down completely.
One more note: if openhab is not running, then it is not possible to control the roller shutters. Most of my lights, on the other hand, are directly controlled by the HUT and do not rely on openhab - still I can use openhab to also switch the lights and to check their states.
I hope this example helps to understand how roller shutters can be controlled with simple relays e.g. provided by the Anel devices.