It all depends on what binding you are using. Since you are talking about Channels that implies you are using 2.x version bindings. I don’t know of any 2.x bindings that would support this. So you would have to use a proxy Switch Item and a Rule that triggers when the Items that get linked to the Channels you want to use the events from and issue the ON and OFF commands to the Proxy Switch.
The new OH2 Modbus binding does support quite complex manipulations for example (because Modbus is such a greatly abused protocol).
Channel writes can have a transform applied, which allows things like a simple inversion of a binary value.
Or the transform script can get quite complicated e.g. a command X to be transformed into ZZ and sent to register 1, while command Y is transformed to WW and sent to register 2 and ALSO to VV sent to register 3.
So let’s take a concrete example. Let’s say I want to set a Switch to ON if a Zwave motion sensor’s alarm Channel goes to OPEN and set the Switch to OFF if a the Weather binding’s condition changes to “RAIN”. It’s a contrived example but it illustrates the problem.
Both are 2.x bindings so all I have is the ability to link to Channels.
There is no way I can link these two separate Channels to my Item and have events from one of the channels only change the Item to ON and events from the other only change the Item to OFF. For one neither Channel is compatible with Switch Items. For another, there is no way to segregate the events.
Now, if we are using the MQTT, HTTP, Exec 1.x, TCP/UDP (I think) bindings, then we can set something like this.
So it really depends on the binding. Honestly, I think this would probably only ever work with MQTT now that I’m looking at it.
It is true that you can line multiple Channels to one Item, as long as the Item type and the Channel are compatible. But there is no way to say “This Channel only sets the Item to ON and that Channel only sets the Item to OFF”.
I agree with @rlkoshak. There are some circumstances, where this would work, for example if using an item to switch on/off a vdr system, you would have to use something like this:
Switch vdr1 "My vdr [%s]" {wol="aa:bb:cc:dd:ee:ff",vdr="vdr1:poweroff",autoupdate="false"}
so to switch on via wol binding and switch off via vdr binding, but in fact openHAB will send both messages, no matter if switching on or off. This does only work as intended, because if the computer is off, the poweroff command is not received by vdr. If vdr is on, the magic packet to wake up the computer will be received, but as the computer is on anyway, this won’t have any impact.
I’m pretty sure you have to use different items and a rule:
rule "switch combined"
when
Item switchBound1 received command ON or
Item switchBound2 received command OFF
then
if(triggeringItem.name == "switchBound1") switchCombined.sendCommand(ON)
if(triggeringItem.name == "switchBound2") switchCombined.sendCommand(OFF)
end
What im trying to do is that a want to create a switch that sends the Channel command for ON to my TV when the switch is ON and the Channel command for OFF to my TV when the switch is off. ON and OFF are different Channels. Theres ist also a toggle on/off channel. but when i use that the tv only is off when toggle switch is again on ON.
also i like to use the switch item for homekit with the (switchable) tag.