Obtaining the heart rate from an external sensor (chest strap)

I'm trying to get the heart rate value from an external sensor (chest strap) so that I can display an indicator on my watch face when the heart rate is coming from that source.  When I try to use the Sensor module in my watch face code, I get this error message:

Error: Permission Required

Details: Module 'Toybox.Sensor' not available to 'Watch Face'

I have the "Sensor" item selected in the permissions manifest, but that does not appear to help.  Any advice would be appreciated.

  • It seems that I can only access the Sensor module in a background process, but I think I can only access that every 5 minutes.  That can't be correct.  There has to be some easier way to get this simple data!  Anyone?

  • Watch faces can't access Sensor except in a background service, which can run at most every 5 minutes and for at most 30 seconds at a time,  No way to avoid that.  You can display the HR from the OHR sensor by using

    Activity.getActivityInfo().currentHeartRate;
    it can be null, so check that. 
    Staying connected to an external band would be a battery killer for both the external band as well as the Garmin and not something you want to do for extended times outside an Activity.
  • Thank you for the response!  Is there some simple way to determine if the watch is using the chest strap (if it is connected)?

  • In general, it won't be connected unless you are doing an activity and an external band is paired, awake, and within range

  • Really I just want to know which sensor is actively reporting the heart rate.  Thank you!

  • Sometimes it seems like the chest strap “drops out” and reverts to the wrist heart rate - even when the band is connected during and activity.  That is why I wanted my watch face to have an indicator that the chest strap is connected and working.

  • Sometimes it seems like the chest strap “drops out” and reverts to the wrist heart rate - even when the band is connected during and activity.  That is why I wanted my watch face to have an indicator that the chest strap is connected and working.

    Are you using a Garmin chest strap? What device are you using?

    Newer devices have a controversial feature called "dynamic source switching" (which is only supposed to work with supported Garmin straps), where the watch will temporarily revert to the wrist heart rate if it thinks that the chest strap HR data is bad. One problem that some have mentioned (and that I've confirmed) is that sometimes the watch will actually choose wrist heart rate data that is clearly worse than the chest strap data. This usually happens near the beginning of an activity.

    To turn this feature off:

    - wear the chest strap and ensure it's paired with your watch

    - Hold MENU and select Settings > Health & Wellness > Wrist Heart Rate

    - Disable Dynamic Source Switching

    You can actually see the effects of this feature after the fact.

    - Open the activity on the Connect website

    - Select the gear icon (in the upper right hand corner) and select Export File. This will export the original FIT file

    - Open the FIT file in fitfileviewer.com

    - Click on the graph icon

    - A graph will be displayed where you can select up to two metrics to graph. "Heart rate" is the heart rate that's displayed (and used) in the activity. If source switching was enabled, you will also see *both* of "external heart rate" and "wrist heart rate", graphed at the same time. You can view either of those along with "heart rate" to see at which points the device decided to switch between the external chest strap and the wrist hr.

  • But this makes no sense. Have you read what jim_m_58 wrote? Even if there's no drop you wouldn't be able to use the strap when you don't start an activity. So start an activity, and then you'll have many ways to test your strap. You can use: https://forums.garmin.com/developer/connect-iq/f/showcase/314512/ant-hrm-heart-rate-monitor-data-field or just look at the Respiratory Rate (either during activity or after you synced to Garmin Connect and look at the graphs). Where you see respiratory rate is a positive number, there you got the HR from the strap, where it's 0 or -- there you get it from the optical sensor of the watch,

  • If the reason for the "drop outs" is source switching (as described above), there will be no way to confirm this except after the fact, by looking at the FIT file in fitfileviewer.com:

    - When source switching is enabled, both "wrist heart rate" and "external heart rate" should be graphed at all times (unless the strap actually disconnects from the watch)

    - Either of the "wrist heart rate" or "external heart rate" metrics can be compared to the "heart rate" metric, to determine when source switching kicked in (to use the wrist HR instead of the external HR). It should be obvious, because "wrist heart rate" will likely have a different value from "external heart rate", and "heart rate" will be equal to "wrist heart rate". (Ofc, if source switching kicked in at a point where "external heart rate" is the same as "wrist heart rate", it will be impossible to tell, but also, it won't matter at all.)

    I agree that it wouldn't help to have a hypothetical indicator on a watchface. None of those other suggestions will help, either, if the cause of the "drop outs" is source switching.

    Where you see respiratory rate is a positive number, there you got the HR from the strap, where it's 0 or -- there you get it from the optical sensor of the watch,

    No, the presence of respiration rate during an activity will only confirm that a compatible Garmin chest strap is natively paired and connected.

    You are assuming that the only possible reason for getting HR from the wrist instead of a strap is that the strap is not connected.

    Again, another possible reason is that dynamic source switching has kicked in. As I alluded to above, many people on the forums have complained that their watch inappropriately uses data from the wrist HR when an external HR is connected, it's almost 100% certain that these observations are caused by dynamic source switching, and what OP is saying sounds pretty similar to what they're saying:

    "Sometimes it seems like the chest strap “drops out” and reverts to the wrist heart rate - even when the band is connected during and activity"

    Since we're talking workarounds to see if your chest strap is connected:

    - For any chest strap (Garmin or non-Garmin), you could simply look in the sensors menu (to be fair, this is a bit more time consuming than looking at a field)

    - For Garmin chest straps that support running dynamics, you could also check for a valid ground contact balance value during an activity

    My suggestion is to simply disable source switching (if in fact, it is enabled), to eliminate one possible cause of the observed behaviour. It's impossible to change the source switching setting without pairing a compatible Garmin strap, btw. and it's enabled by default.

    If drop outs are still observed, then it's most likely a problem with strap. Even if source switching is disabled, I would expect that drop outs due to the strap actually disconnecting from the watch should still be observable by checking the FIT file in fitfileviewer.com after the fact. In this case, I would expect "wrist heart rate" (and not "external heart rate") to be graphed during the periods of time that the drop outs occurred.

  • You are assuming that the only possible reason for getting HR from the wrist instead of a strap is that the strap is not connected.

    Again, another possible reason is that dynamic source switching has kicked in.

    Good point, it's worth to test it somehow. I only have Polar strap, so I can't test, but if you can somehow test this then I'd be interested. My guess is that when the switch happens and the HR of the optical sensor is used, then you won't see respiratory rate for those seconds. It wouldn't make sense to decide that the strap's HR reading is bad quality, so we switch to the optical sensor, while still using the strap's HR to calculate the respiratory rate.