How to configure different ON/OFF Channel bindings for SWITCH Item

Hi,

I want to create a Switch with different Channel Bindings for ON of OFF.

Example:
I want to send Channel Command A when switch is off and Channel Command B when switch is OFF.

I Dont know how to achieve that.

Thx very much

Nip

  • Platform information:
    • Hardware: Raspberry PI2
    • OS: openhabian
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version: 2.3
  • Issue of the topic: please be detailed explaining your issue
  • 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:

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.

Two questions

  1. What binding are you usimg?
  2. Do you want both a and b on When switch is on and both a and b off when swit h is off?

This is very binding dependent.

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.

Reading from the docs, this is not binding specific and should be possible.


Scrolling down, You can find the chapter „Multi Binding/Channel Linkage with examples.

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.

MyItem { mqtt="<[broker:topic:command:ON:default]", http="<[http://myurl:5000:JS(myitem.js)]" }

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:

Switch switchBound1 {channel="a channel"}
Switch switchBound2 {channel="another channel"}
Switch switchCombined //no binding, no linking
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

As I’m not at home, I did not test this yet.

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.

It’s really going to help if you can admit which binding is involved, and perhaps show example of what e.g. Items you have so far

1 Like