hasensors: add HRM sensor
Posts updates at most every 10 minutes, doesn't toggle the sensor.master
parent
ab3944efda
commit
cf237621f3
|
|
@ -1,3 +1,4 @@
|
||||||
0.01: New app!
|
0.01: New app!
|
||||||
0.02: Add sensor icons
|
0.02: Add sensor icons
|
||||||
Customize code directly, remove config file
|
Customize code directly, remove config file
|
||||||
|
0.03: Add HRM sensor
|
||||||
|
|
|
||||||
|
|
@ -21,4 +21,5 @@ You need to fill out these fields:
|
||||||
|
|
||||||
Currently creates these sensors:
|
Currently creates these sensors:
|
||||||
* `<sensor id>_battery_level`: Your watch battery level as percentage
|
* `<sensor id>_battery_level`: Your watch battery level as percentage
|
||||||
* `<sensor id>_battery_state`: `charging` or `discharging`
|
* `<sensor id>_battery_state`: `charging` or `discharging`
|
||||||
|
* `<sensor id>_hrm`: Heart rate (only if measured: this app doesn't enable/disable the sensor)
|
||||||
|
|
|
||||||
|
|
@ -3,4 +3,5 @@
|
||||||
Bangle.on("charging", sb);
|
Bangle.on("charging", sb);
|
||||||
NRF.on("connect", () => setTimeout(sb, 2000));
|
NRF.on("connect", () => setTimeout(sb, 2000));
|
||||||
setInterval(sb, 10 * 60 * 1000);
|
setInterval(sb, 10 * 60 * 1000);
|
||||||
})();
|
Bangle.on('HRM', h=>require("hasensors").sendHRM(h));
|
||||||
|
})();
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ function post(sensor, data) {
|
||||||
|
|
||||||
exports.sendBattery = function () {
|
exports.sendBattery = function () {
|
||||||
if (!NRF.getSecurityStatus().connected) return;
|
if (!NRF.getSecurityStatus().connected) return;
|
||||||
const b = E.getBattery(),
|
const b = E.getBattery(),
|
||||||
c = Bangle.isCharging();
|
c = Bangle.isCharging();
|
||||||
let i = "mdi:battery";
|
let i = "mdi:battery";
|
||||||
if (c) i += "-charging";
|
if (c) i += "-charging";
|
||||||
|
|
@ -40,4 +40,24 @@ exports.sendBattery = function () {
|
||||||
icon: i,
|
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;
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
"id": "hasensors",
|
"id": "hasensors",
|
||||||
"name": "Home Assistant Sensors",
|
"name": "Home Assistant Sensors",
|
||||||
"shortName": "HA sensors",
|
"shortName": "HA sensors",
|
||||||
"version": "0.02",
|
"version": "0.03",
|
||||||
"description": "Send sensor values to Home Assistant using Android Integration/Gadgetbridge",
|
"description": "Send sensor values to Home Assistant using Android Integration/Gadgetbridge",
|
||||||
"icon": "ha.png",
|
"icon": "ha.png",
|
||||||
"type": "bootloader",
|
"type": "bootloader",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue