[SOLVED] How to do double transformation for HTTP sensors?

Hi there,

I have a HTTP sensor which provides its value through a JSON, so I need a JSONPATH transformation to get the correct value. I want to map that sensor to a Switch item. The json has »0« and »1« as value, but for OpenHAB Switch item I neeed »OFF« and »ON« - so I would also need a MAP transformation.

So is it possible to do a double transformation? All my attempts failed (e.g. just appending a second transformation separated by colon) - and if possible I don’t want to write a separate rule or JavaScript transformation for that, I guess that would count as overkill.

My current code without the map:

Switch RelaisStatus "Status Relais [%s]" { http="<[RelaisStatusCache:1000:JSONPATH($.result.status)]" }

Thanks in adavance!

I believe not (currently):

Check: [SOLVED] Need help with REGEX transformations in the sitemap

Could you do like this?

Yeah I could do this, but then my configuration is split across several files, which reduces readability. As (luckily) JSON path doesn’t change across these sensors, I guess I might go this way.

(function(dataString) {
    var data = JSON.parse(dataString);
    var switchState = data.result.status;
    if(switchState)  return "ON";
    if(!switchState) return "OFF";
})(input)
2 Likes