hasensors: add step count sensor
parent
cf237621f3
commit
a02b5a6f56
|
|
@ -2,3 +2,4 @@
|
||||||
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
|
0.03: Add HRM sensor
|
||||||
|
Add step count sensor
|
||||||
|
|
|
||||||
|
|
@ -23,3 +23,4 @@ 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)
|
* `<sensor id>_hrm`: Heart rate (only if measured: this app doesn't enable/disable the sensor)
|
||||||
|
* `<sensor id>_steps`: Step Count
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
(function () {
|
(function () {
|
||||||
const sb = () => require("hasensors").sendBattery();
|
const su = () => require("hasensors").sendUpdate();
|
||||||
Bangle.on("charging", sb);
|
Bangle.on("charging", su);
|
||||||
NRF.on("connect", () => setTimeout(sb, 2000));
|
NRF.on("connect", () => setTimeout(su, 2000));
|
||||||
setInterval(sb, 10 * 60 * 1000);
|
su();
|
||||||
|
setInterval(su, 10 * 60 * 1000);
|
||||||
Bangle.on('HRM', h=>require("hasensors").sendHRM(h));
|
Bangle.on('HRM', h=>require("hasensors").sendHRM(h));
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,7 @@ function post(sensor, data) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.sendBattery = function () {
|
function sendBattery() {
|
||||||
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";
|
||||||
|
|
@ -40,7 +39,26 @@ exports.sendBattery = function () {
|
||||||
icon: i,
|
icon: i,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
|
function sendSteps() {
|
||||||
|
post("steps", {
|
||||||
|
state: Bangle.getStepCount(),
|
||||||
|
attributes: {
|
||||||
|
friendly_name: "{name} Step Count",
|
||||||
|
unit_of_measurement: "steps",
|
||||||
|
state_class: "total",
|
||||||
|
icon: "mdi:shoe-print",
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.sendUpdate = function() {
|
||||||
|
if (!NRF.getSecurityStatus().connected) return;
|
||||||
|
sendBattery();
|
||||||
|
sendSteps();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
let hrm_last = 0;
|
let hrm_last = 0;
|
||||||
const HRM_INTERVAL = 10*60*1000;
|
const HRM_INTERVAL = 10*60*1000;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue