My wife never remembers to charge her Oura ring that she also depends on the metrics of for a variety of reasons, so I wanted to set up a very basic automation to detect when it stops syncing data, either because it’s dead, dying, or otherwise misbehaving.
Fortunately the Oura API is super simple, so I skimmed the docs and set up a super basic REST sensor to check the Oura API every couple hours for heart rate data (which the ring collects every 5 minutes), and record the most recently recorded HR timestamp as a sensor, so I can trigger an automation if the ring hasn’t synced in 48 hours for some reason and add it to my Todoist todo list to make her charge her ring.
Just sharing in case anyone finds the approach useful or could use the example:
The timestamp sensor for the rest sensor:
sensor:
- platform: rest
name: Last Oura Sync Date
headers:
# This string is "Bearer {oura_personal_access_token}" which is found in the docs
Authorization: !secret oura_access_token_header
resource: "https://api.ouraring.com/v2/usercollection/heartrate"
# Grab the last available timestamp, approximately the time of the last sync to the cloud
value_template: "{{ as_timestamp(value_json.data[-1].timestamp) | timestamp_local }}"
# Every couple hours
scan_interval: 7200
device_class: timestamp
unique_id: {UUID}
The automation config:
alias:
description: 2 days from the last recorded wake up time, add sync oura ring to todoist
triggers:
- trigger: time
at:
entity_id: sensor.last_oura_sync_date
offset: '48:00:00'
conditions: []
actions:
- action: todoist.new_task
metadata: {}
data:
project: Inbox
content: Force the Oura ring to Sync
description: It's been 2 days since the last heartrate was recorded
due_date_string: today
mode: single
It’s basically nailed the problem of me trying to keep track of whether she’s remembering to wear or charge the ring, or the ring occasionally just stopping syncing for some reason.