Define mappings in item file?


I have the following item:

Switch  n1c0  "Pumpe"  <water> (gGF_irrigation01)  { channel="mysensors:light:gateway:n1c0:status" }

I need openhab to send the item state reverse. When switching it ON I need to send 0 and wenn switching it OFF i nedd to send 1.
I saw a example but this does not work in OH2:

mappings=[ON="An", OFF="Aus"]

after the label, but this does not work. Any suggestions?

If you receive numbers from the channel, you should use a Number item (that you can transform to a String for display purposes). If the channel provides a switch value, you should use that.

The mapping is used form display purposes. Do you need to transform values for display or do you actually need to send different values?

Could you be more specific to what you need? Perhaps you should describe your use case?

good morning :wink:

ok more specific: I want to switch a relay connected to an arduino. this relay is is aktive low, which means it powers on when receiving LOW (bool 0) and off when receiving HIGH (bool 1). This is what i want to archieve with this mapping: sending the needed values which are reverted from the “regular” logic on=1 and off=0.

The channel itself send On/Off so I need a mapping like ON=OFF, OFF=ON :confused:


I’m not sure if you can achieve this with mapping. My solution would be to use a rule that updates a second switch to hold the opposite value of the channel.


Switch  n1c0  "Pumpe"  <water> (gGF_irrigation01)  { channel="mysensors:light:gateway:n1c0:status" }
Switch  n1c0_reverse


rule "Revert Relay"
    Item n1c0 received command
    switch(receivedCommand) {
        case ON : n1c0_reverse.sendCommand(OFF)
        case OFF : n1c0_reverse.sendCommand(ON)

ok this might work too :wink: thanks :wink: