Setting sample rate of HR sensor

Former Member
Former Member
Is there a way to have the HR sensor provide samples only every 3 minutes or so? For sleep monitoring, a lower sample rate would be fine and prevent the battery from draining too quickly.

If there is no such option, would it be feasible to periodically turn the HR sensor on/off with setEnabledSensors() ?
  • There's no way to set the sample rate. In an app, you could just ignore the readings except one every 3 minutes.
    But here's something you may find helpful:

    On many watches, you don't need to use setEnabledSensors to get frequent readings from the oHRM. This for example is how watchfaces can display a "real time" HR. WFs are not able to set the Sensor permission, and can't even call setEnabledSensors.

    A hidden gem:

    Activity.getActivityInfo().currentHeartRate

    It's the current 24/7 HR, even if you are not recording an activity, and has no additional impact on the battery. It only works with watches that have an oHRM, and due to differences in the f5x hardware, not on it. But on the f5x, you can also see the latest reading from history, and that's saved every couple minutes.

    SensorHistory.getHeartRateHistory(). You can also use getHeartRateHistory() by way of ActivityMonitor, so you can also get that info on CIQ 1.x devices with a oHRM, but don't support SensorHistory. (like the f3hr)

    You get access to up to the last 4 hours of readings.

    You can get the same history for elevation, pressure and temperature, BTW, on most devices with SensorHistory

    So, on an f5x, getting it with Activity (in a WF) will be null in most cases, but you can pull the newest reading from history.

    On watches with a baro Altimeter, there are a few other things in Activity.getActivityInfo() that can be useful to. Like altitude, ambientPressure, rawAmbientPressure,meanSeaLevelPressure.

    Unless you have GPS on, currentLocation won't change, and will be the last location from an activity that used GPS, but will go stale after a time and be null. This is very useful though, as it's the way a watchface can get a location for things like sunrise/sunset, to request weather data from the internet, etc. if it is valid, a WF can save it off in the ObjectStore/Application.Storage, for times that it isn'tl.

    I'm using a WF here as an example, as with the different app types, it's the most restricted in accessing things, like GPS and sensors.
  • Former Member
    Former Member
    Thanks a lot. That is very helpful information!

    My idea for a sleep monitor is to monitor HR every 1-3 minutes (default) until it crosses a threshold. Then HR is monitored continously (oHRM always on), until it drops again.

    For this I should probably just listen to the default HR events with Sensor.enableSensorEvents(method(:onSensor)) until the threshold is reached and then switch to setEnabledSensors() for continous monitoring, correct?

    In order to check if a HR event is stale, the timestamps of SensorHistory.getHeartRateHistory() will tell.
  • You might be able to do what you want with Activity.Info.currentHeartRate and not ever turn on the oHRM with setEnabledSensors. (except the f5x and watches without a oHRM)

    Oh, I should mention that of you want the HR saved to a .fit, you will need to use setEnabledSenors for HR. You can do some minimal (I'd say more a debug thing) with println() calls, but those log files must be precreated, and at about 8k, they save the current one as a .bak, and write to a new one, and the name of the log is based on the .prg generated by the app store, so the name of the file isn't easy for a user to determine.
  • Former Member
    Former Member
    Activity.getActivityInfo().currentHeartRate might not be responsive enough. I often find it is late and misses peaks. My 24/7 heart rate history doesn't show the peaks that were recorded during activities (a bug, IMO, because HR captured during activity recording should also go to the 24/7 history - why drop that information when it is readily available?).