diff --git a/apps/hasensors/ChangeLog b/apps/hasensors/ChangeLog index 7b3a63039..e8b1934fc 100644 --- a/apps/hasensors/ChangeLog +++ b/apps/hasensors/ChangeLog @@ -1,3 +1,4 @@ 0.01: New app! 0.02: Add sensor icons Customize code directly, remove config file +0.03: Add HRM sensor diff --git a/apps/hasensors/README.md b/apps/hasensors/README.md index e7f6ca98d..c083a50dc 100644 --- a/apps/hasensors/README.md +++ b/apps/hasensors/README.md @@ -21,4 +21,5 @@ You need to fill out these fields: Currently creates these sensors: * `_battery_level`: Your watch battery level as percentage -* `_battery_state`: `charging` or `discharging` \ No newline at end of file +* `_battery_state`: `charging` or `discharging` +* `_hrm`: Heart rate (only if measured: this app doesn't enable/disable the sensor) diff --git a/apps/hasensors/boot.js b/apps/hasensors/boot.js index efafbc8a3..f031d7d7e 100644 --- a/apps/hasensors/boot.js +++ b/apps/hasensors/boot.js @@ -3,4 +3,5 @@ Bangle.on("charging", sb); NRF.on("connect", () => setTimeout(sb, 2000)); setInterval(sb, 10 * 60 * 1000); -})(); \ No newline at end of file + Bangle.on('HRM', h=>require("hasensors").sendHRM(h)); +})(); diff --git a/apps/hasensors/lib.js b/apps/hasensors/lib.js index 83072262c..56c609cee 100644 --- a/apps/hasensors/lib.js +++ b/apps/hasensors/lib.js @@ -14,7 +14,7 @@ function post(sensor, data) { exports.sendBattery = function () { if (!NRF.getSecurityStatus().connected) return; - const b = E.getBattery(), + const b = E.getBattery(), c = Bangle.isCharging(); let i = "mdi:battery"; if (c) i += "-charging"; @@ -40,4 +40,24 @@ exports.sendBattery = function () { icon: i, } }); -} \ No newline at end of file +}; + +let hrm_last = 0; +const HRM_INTERVAL = 10*60*1000; +exports.sendHRM = function (hrm) { + if (!NRF.getSecurityStatus().connected) return; + const now = (new Date).getTime(); + if (hrm_last > now-HRM_INTERVAL) return; + post("hrm", { + state: hrm.bpm, + attributes: { + confidence: hrm.confidence, + raw: hrm.raw, + friendly_name: "{name} Heart Rate", + icon: "mdi:heart", + unit_of_measurement: "bpm", + state_class: "measurement", + } + }); + hrm_last = now; +}; diff --git a/apps/hasensors/metadata.json b/apps/hasensors/metadata.json index 5764c6100..550095c76 100644 --- a/apps/hasensors/metadata.json +++ b/apps/hasensors/metadata.json @@ -2,7 +2,7 @@ "id": "hasensors", "name": "Home Assistant Sensors", "shortName": "HA sensors", - "version": "0.02", + "version": "0.03", "description": "Send sensor values to Home Assistant using Android Integration/Gadgetbridge", "icon": "ha.png", "type": "bootloader",