Conditional action


I have a specific need, I want to make a kind of logical OR to trigger analysis or actions (it depend on your reply :wink: ) between two sensors.

Actually I have a variable attached to a first sensor which call “presenceSensor1” and a second variable attached to a second sensor which call “presenceSensor4” and both increment a global variable which call “globalPresence” so I want to perform a OR on the actions or analysis which linked with theses sensors.

The issue is when the sensors send datas exactly at the same time.

To be more clear:
I want increment this global variable only one time even if the sensors speak exactly at the same time because if not the global varaible will be incremented two time whereas I monitor the same things.

Is adding datas processing to the analysis is the only solution?

Thank you for your help.

Hi @julien.terrier3,
Yes, data processing can only be done using Analysis.

1 Like

Thank you so much for your reply.

Could you help me plz to make the good payload parser - decoder in order to recover a moment.

const timeObject = payload.find(item => item.variable === "rxInfo");

  if (timeObject) {
  const rxTime = moment(timeObject.time);

  const rxTimeHour = rxTime.hour();

   // we can print to Live Inspector for debugging.
   console.log(`Timestamp variable is:${rxTime}, hour is: ${rxTimeHour}`);
    //var rawTime = rxTime.toString('ascii');  
    //const myTime = Buffer.from(rawTime, 'base64');
   payload.push({"variable" : "myTime" , "value" : rxTime.toString('ascii') });

It’s a part of my decoder but I have an error in the live inspector due to a wrong payload.push output.

I want push “rxTime” in “myTime” variable in order to use it later in analysis but I’m little bit lost with the conversion of rxTime besides I’m not sure if I have to convert rxTime…

I’m sure that piece of code works until console.log

Live inspector console:
22:13:55: Log from [device] payload parser: "Timestamp variable is:Sat Oct 31 2020 22:13:55 GMT+0100, hour is: 22"

Thank you for your help.

So it’s works like that:

if (timeObject) {

  var rxTime = moment(timeObject.time);

  var rxSecondeTime = moment().format();

   // we can print to Live Inspector for debugging.

   console.log(`Timestamp variable is:${rxTime}, SecondeTime is: ${rxSecondeTime}`);


   payload.push({"variable" : "myTime" , "value" : rxTime });

it was because the return of moment(timeObject.time); with “const” keyword caused a problem.

1 Like