Skip to content

Instantly share code, notes, and snippets.

Last active October 16, 2023 04:20
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
// Updated version of the very useful post:
// preferred key names
const fieldKeyLookup = {
qty: 'value',
Avg: 'avg',
Min: 'min',
Max: 'max',
msg.payload = => {
.map(measurement => {
const timestamp = Date.parse(;
var fields = {};
Object.keys(measurement).forEach(e => {
if (typeof(measurement[e]) !== 'object') fields[fieldKeyLookup[e] || e] = measurement[e];
if (fields.min && fields.max && fields.min == fields.max) {
delete fields.min;
delete fields.max;
return {
measurement:, //active_energy
fields: fields, // {value: 5} or {systolic:120, diastolic: 70}, etc
tags: {
unit: metric.units //kJ
timestamp: timestamp //2021-03-16 00:00:00 +0100
.flat() // we've created array for each metric consisting of array of measurements
.filter(e => Object.keys(e.fields).length) // just in case, only return entries with fields
return msg;
Copy link

wivaku commented May 17, 2021

note, this does not add measurements for notification metrics: irregular_heart_rate_notifications, high_heart_rate_notifications, low_heart_rate_notifications.
These consist of arrays of heartRate and/or heartRateVariation, which consist of:

  • hr: 70 (or hrv: 100)
  • units: bps (or: units: ms)
  • timestamp: {start, interval, end}

Copy link

This appears to be broken, unsure if just me but it was working fine until a few days ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment