Passthrough not mapped values

  • Platform information:
    • Hardware: RPI 3
    • OS: openhabian
    • Java Runtime Environment: (Zulu Embedded 8.25.0.76-linux-aarch32hf) (build 1.8.0_152-b76)
    • openHAB version: 2.4.0
  • Issue of the topic: I’m looking how to passthrough all the values that aren’t mapped, for e.g 1=ON, the state will be ON, however if the value is 5 then the state would just be 5
  • Please post configurations (if applicable):
1023=ON
1023.0=ON
0.0=OFF
0=OFF

  • If logs where generated please post these here using code fences:
2019-02-06 17:01:42.201 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '961.62' with the file 'pwmswitch.map' : Target value not found in map for '961.62'

2019-02-06 17:01:42.203 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'RGB_W2SW'

I do not think you can. Even using the new ‘default’ feature, which would give you a nonmatched default answer but not a pass-through.

You can use a JS transform instead, and have the javascript do whatever you want.

1 Like

I suppose it should look like this.

(function(i) {
    if(i==1023 || i==1023.0) {
    return ON
    } else if (i==0 || i==0.0){
    return OFF
    }
})(input)

Only solution I see is to change the Item to be a String item and do the mapping within a rule.
String Item cause you want to have ON and OFF schown as well.

I don’t want to have a rule for something simple like this.

Thanks to @rossko57 , for getting me on the right path. The code below ended up working fine using the JS Transformation.

(function(i) {
    if(i==1023 || i==1023.0) {
    var state = "ON";
    } else if (i==0 || i==0.0){
    var state = "OFF";
    } else {
    var state = "NULL";
    }
    return state;
})(input)

Switch RGB_W0SW {mqtt=">[broker:/led/PWM/5:command:ON:1023],>[broker:/led/PWM/5:command:OFF:0],<[broker:/led/PWM/5:state:JS(pwmswitch.js)]" }

But this is not reflecting your question. If the state is 5, you transform it to „NULL“.

1 Like

Like the man says, that’s not the pass through you asked for. A default in MAP would do the same as your script.

0=OFF
0.0=OFF
1023=ON
1023.0=ON
=UNDEF

I would use UNDEF rather than NULL because they have slightly different meanings in openHAB
NULL = hasn’t been set up yet
UNDEF = something wrong or unexpected

Passthrough transformation:

(function(i) {
    var state = ""
    var value = parseInt(i)
    if(value == 1023) {
    state = "ON";
    } else if (value == 0){
    state = "OFF";
    } else {
    state = value.toString;
    }
    return state;
})(input)