IFTTT payload conversion to show door status?

Hello, my name is Oliver, i am quite new about TTN.
I just got my Dragino LDS01 and doing my first steps.
With IFTTT webhooks i am sending some push messages to my Telegram messenger.

The payload of the door sensor is described here.

My problem is now, that the message at Telegram is telling me only, that the sensor sent data.
There is no difference like “door open” or “door close”.

My question is now, where i have to make changes in the code?

The important line in the payload may be:
var door_open_status=bytes[0]&0x80?1:0;//1:open,0:close

I tried even at the webhooks section to send me the value “1” and “0”, which even worked.

But where can i convert “0” to text “Door closed” and “1” to “Door open” ?
I want the status of the door as text, not as binary number.

Do i have to change the payload decoder at TTN? Or add any code converter at IFTTT webhooks?
I dont know the place and what to edit.

Thanks and greets, Oliver

Either will work.

You can change the decoder at TTN by replacing the 1 & the 0 with the text you want.

Thanks for your answer! I will try soon. I thought the payload can only send numbers or hex values. I did not know that text is possible.

I will let you know next days!

Not sure, if i can do this in the encoder.

// Add MOD3

function Decoder(bytes, port) {
  // Decode an uplink message from a buffer
  // (array) of bytes to an object of fields.
  var value=(bytes[0]<<8 | bytes[1])&0x3FFF;
  var bat=value/1000;//Battery,units:V
  
  var door_open_status=bytes[0]&0x80?1:0;//1:open,0:close
  var water_leak_status=bytes[0]&0x40?1:0;
  
  var mod=bytes[2];
  
  if(mod==1){
    var open_times=bytes[3]<<16 | bytes[4]<<8 | bytes[5];
    var open_duration=bytes[6]<<16 | bytes[7]<<8 | bytes[8];//units:min
    return {
      BAT_V:bat,
      MOD:mod,
      DOOR_OPEN_STATUS:door_open_status,
      DOOR_OPEN_TIMES:open_times,
      LAST_DOOR_OPEN_DURATION:open_duration
    };
  }
  else if(mod==2)
  {
  var leak_times=bytes[3]<<16 | bytes[4]<<8 | bytes[5];
  var leak_duration=bytes[6]<<16 | bytes[7]<<8 | bytes[8];//units:min
  return {
      BAT_V:bat,
      MOD:mod,
      WATER_LEAK_STATUS:water_leak_status,
      WATER_LEAK_TIMES:leak_times,
      LAST_WATER_LEAK_DURATION:leak_duration
  };
  }
  else if(mod==3)
  {
  return {
      BAT_V:bat,
      MOD:mod,
      DOOR_OPEN_STATUS:door_open_status,
      WATER_LEAK_STATUS:water_leak_status
  };
  }
  else{
  return {
      BAT_V:bat,
      MOD:mod,
  };
  }
}

Door status is declared as bytes, not sure if i can change this to text ?!

Aside: please see How do I format my forum post? [HowTo] Thanks.

Where in the code is it declared? There is no such thing in JavaScript as type declarations.

var door_open_status = bytes[0]&0x80 ? “open” : “close”;

1 Like

Is possibly NodeRed the way to go?

Then connect to TTN with MQTT --> retrieve payload --> change payload --> webhook to IFTTT.

This may be a solution. I am just a beginner yet, but planning to set up a node red server soon. I think this sounds promising.
The problem at the moment is maybe in IFTTT. I am not yet sure, what “value” means at webhooks. If “value” is limited to numbers only, then i cannot send text messages to webhooks like “door open”