hasensors: add HRM sensor

Posts updates at most every 10 minutes, doesn't toggle the sensor.
pull/3686/head
Richard de Boer 2024-12-03 21:14:59 +01:00
parent ab3944efda
commit cf237621f3
No known key found for this signature in database
5 changed files with 28 additions and 5 deletions

View File

@ -1,3 +1,4 @@
0.01: New app!
0.02: Add sensor icons
Customize code directly, remove config file
0.03: Add HRM sensor

View File

@ -22,3 +22,4 @@ You need to fill out these fields:
Currently creates these sensors:
* `<sensor id>_battery_level`: Your watch battery level as percentage
* `<sensor id>_battery_state`: `charging` or `discharging`
* `<sensor id>_hrm`: Heart rate (only if measured: this app doesn't enable/disable the sensor)

View File

@ -3,4 +3,5 @@
Bangle.on("charging", sb);
NRF.on("connect", () => setTimeout(sb, 2000));
setInterval(sb, 10 * 60 * 1000);
Bangle.on('HRM', h=>require("hasensors").sendHRM(h));
})();

View File

@ -40,4 +40,24 @@ exports.sendBattery = function () {
icon: i,
}
});
};
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;
};

View File

@ -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",