[SOLVED] Reversing a Switch

Couldn’t really find what I was looking and imagine this has happened to others.

I have a WaterCop Water Shutoff Valve. Was able to get it connected and found in the z-wave database.I added it as a simple switch. Here’s where it gets a little weird.

When you switch the valve ON it actually is closing the valve. When you switch the valve OFF it opens the valve. Not a huge deal as I can just switch things around in a rule but in the sitemap it shows as “ON” when closed and “OFF” when open.

Can this be changed in the binding? Is there something you add to a switch to change the on/off?

Thanks!

Maybe use the mapping feature in the sitemap?

mappings=[ON="Closed", OFF="Open"]

More info is here: https://www.openhab.org/docs/configuration/sitemaps.html#mappings

1 Like

That will work in the sitemap but not for rules.
You’ll need to create another item switch and a rule to invert the switch.

Hi all!

I have a similar problem, where I would need some help.

I’m using a MCP23017 as outputs to drive a relay board. It’s a low trigger board - so a low level output will close and trigger the relay. It’s working fine but due to this, it’s working reverse.

So I created a second switch and a rule to get the inverse result, e.g:

Switch Output1 … = the switch I will work in my openhab environment
Switch InvertedOutput1 … = the switch which works with the MCP23017 and the relay board

My switches with the correct output (= Output1: switch closed --> relay closed) are in a group, e.g. gOutputs. My rule reacts to changed of this group.

With triggeringItem.name and triggeringItem.state I get the values and would like to forward the opposite reaction to my corresponding switch InvertedOutputX

But I would like to create only one rule for all the members of this group.
For this I would like to add a String in front of the Switch item in my rule.
So I tried to use SendCommand(“Inverted”+triggeringItem.name, OFF/ON), but it’s not working.

Does anyone have a hint for me?

Thanks and best regards!

What does happen, though? SendCommand should be sendCommand

Some bindings support transform on channels. many don’t. If that’s available it allows you to do inversion at the binding<->Item level, and avoid proxy Items.

Methods to acces Items given a name string only

Hi Rossko!

Yes, you’re absolutely right - sendCommand is correct - but that’t not my fault.

I don’t really have more information about the binding - like mentioned is it a binding for the I2C Port Expander MCP23017 working on Raspberry Pi3.

Here is my rule:

rule “MCP23017 Switch Ausgänge invertieren”
when
Member of gAusgaenge changed
then
if(triggeringItem.state == ON)
{
sendCommand(“Invert”+triggeringItem.name, OFF)
}
else
{
sendCommand(“Invert”+triggeringItem.name, ON)
}
end

My Items-file:

Switch InvertAusgangIC0PinB0 “Ausgang IC0 B0: [MAP(de.map):%s]” {channel=“mcp23017:mcp23017:chipA:output#B0”}
Switch AusgangIC0PinB0 “Ausgang IC0 B0: [MAP(de.map):%s]” (ExpanderIC0, gAusgaenge)

In the log I see the following problem:

2019-02-04 19:23:57.043 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘MCP23017 Switch Ausgänge invertieren’: An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(java.lang.String,java.lang.String) on instance: null

Thank you very much!!
Best regards,
strizl

It seems that only this kind of code works:

InvertAusgangIC0PinB0.sendCommand(OFF)

But how can I add here a String in the front of the items name?

“Invert”+triggeringItem.name.sendCommand(OFF)

doesn’t work

Any ideas?

Thanks a lot!

You can’t.
But as already hinted, in this design pattern you will find methods to “get hold” of an Item, if you have the Item’s name as a string.

Got it!
Thank you very much @rossko57 - your link was the solution!!

Best regards,
strizl