Switch Item linked with MQTT Transformation Data

Hello Guys,

I’m trying to create a new item link to a generic MQTT Thing. The payload comes from a PLC that sends all states from all lights on a unique message. I’m trying to split only the first value from the payload that is the state of the first light. For that I created a js Transform file. But it’s not working. On the transformation I’m passing the number of the light conct with the payload received from the plc. Inside de js transformation I’m trying to separate the light number from the original payload and return only the text “ON” or “OFF”.

Can any one help me. ps. Sorry for my english.





Switch Light_1 “Lâmpada 1” { channel = “mqtt:topic:941f7483:lights”[profile=“transform:JS”, function=“getLightState.js”, sourceFormat=“1 %s”] }

js Transformation (getLightState.js):

(function(i) {
var inputArray = i.split(" ");
var lightNr = inputArray[0];
var states = inputArray[1];
var state = states.substring(lightNr-1,lightNr)
if (state == “1”) {
return “ON”;;
} else {
return “OFF”;

  • 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: