Looping
Loop through elements in a array
for (let element of msg.payload){
node.warn(element);
}
Loop through keys in an object
for (let key of Object.keys(msg.payload)){
node.warn(key);
}
Loop through array 
for (let i in msg.payload){
node.warn(msg.payload[i]);
}
Loop through elements of an array
for (score of scores) { node.warn(score);}
   
Mscl
Sort object by key
let sorted = Object.keys(msg.payload).sort().reduce((acc, currValue) => {
    acc[currValue] = msg.payload[currValue];
    return acc;
}, {});
node.warn(sorted);
Recursive Traversal of Object
function traverse(x) { if (isArray(x)) { traverseArray(x) } else if ((typeof x === 'object') && (x !== null)) { traverseObject(x) } } function traverseArray(arr) { arr.forEach(function (x) { traverse(x) }) } function traverseObject(obj) { for (var key in obj) { if (obj.hasOwnProperty(key)) { traverse(obj[key]); node.warn(obj); } } } function isArray(o) { return Object.prototype.toString.call(o) === '[object Array]' } traverse(msg.payload); return msg;
 
Stripe
const stripeF = stripe(global.get('vars.stripe_key'));
stripeF.subscriptions.list(
{
    customer: msg.payload,
    limit: 100
},
function(err, subscriptions) {
    msg.customerdata.subscriptions = subscriptions.data;
    node.send(msg);
}
);
const stripeF = stripe(msg.query.stripe_key);
var start = async function(customer) {
    var params = {
        limit : 100        
    };
    paymentIntent = await stripeF.paymentIntents.list(
        params
    );
    node.send(msg);
}
 
ESP Rules

on balls do
  publish debug/%sysname%,releasestart
  event gateup
  delay 6000
  event gatedown
  publish debug/%sysname%,releasefinish
endon

Topic: ESP_Easy/cmd, Payload: event,beep

Ringtones

On armtone do  
rtttl,12,:d=2,o=5,b=355:32p,1a-,d-,a-,a-,4a-,4a-,g-,f,1c-,32p,4c-,d-,a-,a-,a-,1g-
Endon

On disarmtone do  
rtttl,12,:d=4,o=6,b=56:16c-5,16e5,32c,8b5,32e5,32g.5,g-5,32e.5,32f-5,32e5,8d-5,32g-4,32c-.5,a-4,
Event disarmled
//james bond
Endon

On nowarmedtone do  
rtttl,12,:d=4,o=5,b=56:16g,16g,16g,16d-,16g-,16g-,16g-,16g,16d-6,16d-6,16d-6,c6,
Event armled
Endon

On intruder do  
rtttl,12,:d=4,o=5,b=140:c,d-,16d-6,8f6,8d-6,8d-6,16d-6,8f6,8d-6,8c6,16a-,c6,16p,c,d-,16d-6,8f6,8d-6,8d-6,16d-6,8f6,8d-6,8d-6,16d-6,g6,16p,c,d-,16d-6,8f6,8d-6,8d-6,16d-6,8f6,8d-6,8c6,16a-,c6,16p,c,d-,8d-6,8f6,8d-6,8g6,8f6,16d-6,8c6
Event intruderled
Endon

On disarmled do
GPIO,13,0
GPIO,5,1
Endon

On armled do
GPIO,13,1
GPIO,5,0
Endon

On intruderled do
GPIO,13,1
GPIO,5,1
Endon

//Microwave Stuff
On System#Boot do    
Let,1,0      //%v1% Presence
Let,2,0      //%v2% MovEnergy
Let,3,0      //%v3% Motion
endon

On MW#Presence=1 do
  If %v1% = 0
      Let,1,1
      Publish test/presence,"Presence Detected"
  Endif

  TimerSet,1,10 // reset timer
Endon

On MW#Presence=0 do
  Let,1,1
  TimerSet,1,1
Endon

On MW#MovEnergy>=50 do
  If %v2% = 0
      Let,2,1
      Publish test/MovEnergy,"Energy Detected"
  Endif
  
  TimerSet,2,10 // reset timer
Endon

On Rules#Timer=1 do  
  Let,1,0 // Presence Stopped
  publish test/presence,"Presence Stopped"
endon

On Rules#Timer=2 do  
  Let,2,0 // Moving Energy Stopped
  publish test/MovEnergy,"Energy Stopped"
endon

 

/////////////////////////////////

 

On PIR#State=1 do
  If %v3% = 0
      Let,3,1
      Publish test/PIR,"PIR Detected"
  Endif

  TimerSet,3,10 // reset timer
Endon

On Rules#Timer=3 do  
  Let,3,0 // Presence Stopped
  publish test/PIR,"PIR Stopped"
endon

 

 

Flash LED on reading RFID

On pn532#Tag Do
  Event open
Endon

On open do
GPIO,12,1
delay 2000
GPIO,12,0

GPIO,13,1
delay 2000
GPIO,13,0

Endon

 

 
 
Copyright © 2024 IoTLink.org
Edit       FileManager     Duplicate /themes.../layouts/partials/footer.html