Skip to content

Instantly share code, notes, and snippets.

@sstratoti
Created March 21, 2021 15:39
Show Gist options
  • Save sstratoti/d666414954a368f0823a3d2f04591f98 to your computer and use it in GitHub Desktop.
Save sstratoti/d666414954a368f0823a3d2f04591f98 to your computer and use it in GitHub Desktop.
Room Assistant API Data Parser
msg.notification = '';
msg.notification_in = '';
for (i=0; i < msg.payload.length; i++){
if (msg.payload[i].name == "Steves-iPhone-BLE Room Presence"){
if (msg.payload[i].distances['Living Room'].outOfRange) {
msg.notification += "<br> Living Room Out Of Range (" + msg.payload[i].distances['Living Room'].distance + ")";
} else {
msg.notification_in += " <br> Living Room (" + msg.payload[i].distances['Living Room'].distance + ")";
}
if (msg.payload[i].distances['Kitchen'].outOfRange) {
msg.notification += " <br> Kitchen Out Of Range (" + msg.payload[i].distances['Kitchen'].distance + ")";
} else {
msg.notification_in += " <br> Kitchen (" + msg.payload[i].distances['Kitchen'].distance + ")";
}
if (msg.payload[i].distances['Basement'].outOfRange) {
msg.notification += " <br> Basement Out Of Range (" + msg.payload[i].distances['Basement'].distance + ")";
} else {
msg.notification_in += " <br> Basement (" + msg.payload[i].distances['Basement'].distance + ")";
}
if (msg.payload[i].distances['Master Bedroom'].outOfRange) {
msg.notification += " <br> Master Bedroom Out Of Range (" + msg.payload[i].distances['Master Bedroom'].distance + ")";
} else {
msg.notification_in += " <br> Master Bedroom (" + msg.payload[i].distances['Master Bedroom'].distance + ")";
}
if (msg.payload[i].distances['Nursery'].outOfRange) {
msg.notification += "<br> Nursery Out Of Range (" + msg.payload[i].distances['Nursery'].distance + ")";
} else {
msg.notification_in += "<br> Nursery (" + msg.payload[i].distances['Nursery'].distance + ")";
}
if (msg.payload[i].distances['Office'].outOfRange) {
msg.notification += "<br> Office Out Of Range (" + msg.payload[i].distances['Office'].distance + ")";
} else {
msg.notification_in += "<br> Office (" + msg.payload[i].distances['Office'].distance + ")";
}
}
}
return msg;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment