I have sonoff RF receiver which I have take payload and put it to separate switch nodes.
Then, there was too many switch nodes, and I try to replace them with only one function node, containting all 'translations' of incoming messages from RF to single mqtt publish node., with following code:
var a = msg.payload.RfReceived.Data;
//var a=msg.payload;
var b=null;
// motion sensor MS01 @ ENTRY DOOR
if (a=='EC2D8E') {msg.topic='stat/terasa/MS01'; msg.payload='ON';}
// motion sensor MS03 @ RADIONA
if (a=='EBC35E') {msg.topic='stat/terasa/MS03'; msg.payload='ON';}
// door senzor TERASA
if (a=='2BB30A') {msg.topic='stat/DS01'; msg.payload='ON';}
if (a=='2BB30E') {msg.topic='stat/DS01'; msg.payload='OFF';}
if (a=='2BB306') {msg.topic='stat/DS01'; msg.payload='BATT';}
// door senzor TEST SENZOR NA STOLU
if (a=='93B60A') {msg.topic='stat/DESK'; msg.payload='ON';}
if (a=='93B60E') {msg.topic='stat/DESK'; msg.payload='OFF';}
if (a=='93B606') {msg.topic='stat/DESK'; msg.payload='BATT';}
// door senzor STUBIĹ TE DONJA VRATA
if (a=='D8FE0A') {msg.topic='stat/DS07'; msg.payload='ON';}
if (a=='D8FE0E') {msg.topic='stat/DS07'; msg.payload='OFF';}
if (a=='D8FE06') {msg.topic='stat/DS07'; msg.payload='BATT';}
// door senzor ULAZNA VRATA
if (a=='32760A') {msg.topic='stat/DS02'; msg.payload='ON';}
if (a=='32760E') {msg.topic='stat/DS02'; msg.payload='OFF';}
if (a=='327606') {msg.topic='stat/DS02'; msg.payload='BATT';}
// door senzor GARAŽA POLO
if (a=='31A40A') {msg.topic='stat/DS03'; msg.payload='ON';}
if (a=='31A40E') {msg.topic='stat/DS03'; msg.payload='OFF';}
if (a=='31A406') {msg.topic='stat/DS03'; msg.payload='BATT';}
// door senzor GARAŽA AUDI
if (a=='347A0A') {msg.topic='stat/DS04'; msg.payload='ON';}
if (a=='347A0E') {msg.topic='stat/DS04'; msg.payload='OFF';}
if (a=='347A06') {msg.topic='stat/DS04'; msg.payload='BATT';}
// door senzor GARAŽA RADIONA
if (a=='32020A') {msg.topic='stat/DS05'; msg.payload='ON';}
if (a=='32020E') {msg.topic='stat/DS05'; msg.payload='OFF';}
if (a=='320206') {msg.topic='stat/DS05'; msg.payload='BATT';}
// door senzor POŠTANSKI SANDUČIĆ
if (a=='33900A') {msg.topic='stat/DS06'; msg.payload='ON';}
if (a=='33900E') {msg.topic='stat/DS06'; msg.payload='OFF';}
if (a=='339006') {msg.topic='stat/DS06'; msg.payload='BATT';}
// door senzor KAPIJA DOOBR BELL
if (a=='C5FD05') {msg.topic='stat/GATE/db01'; msg.payload='ON';}
// RF TIPKALA
// TIPKALO 1
if (a=='013C94') {msg.topic='cmnd/RS_LED1/POWER'; msg.payload='TOGGLE';}
if (a=='013C92') {msg.topic='cmnd/SOF001/POWER'; msg.payload='TOGGLE';}
if (a=='013C91') {msg.topic='cmnd/DOF003/POWER'; msg.payload='TOGGLE';}
// TIPKALO 2
if (a=='0A1B91') {msg.topic='cmnd/RS_LED1/POWER'; msg.payload='TOGGLE';}
if (a=='0A1B98') {msg.topic='cmnd/SOF001/POWER'; msg.payload='TOGGLE';}
if (a=='0A1B92') {msg.topic='cmnd/SOF003/POWER'; msg.payload='TOGGLE';}
return msg;
Works fine, but slower ?
It seams that sometimes I loose some of the input messages.
Is this approach worse then send payload to separate switch nodes ??