Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add total sleep duration sensor #228

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Sedentary Time
Sleeping Time
Awake Duration
Sleep Duration
Total Sleep Duration
Floors Ascended
Floors Descended
Floors Ascended Goal
Expand Down
8 changes: 8 additions & 0 deletions custom_components/garmin_connect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ async def _async_update_data(self) -> dict:
activity_types = {}
sleep_data = {}
sleep_score = None
sleep_time_seconds = None
hrv_data = {}
hrvStatus = {"status": "UNKNOWN"}

Expand Down Expand Up @@ -190,6 +191,12 @@ async def _async_update_data(self) -> dict:
except KeyError:
_LOGGER.debug("Sleep score data is not available")

try:
sleep_time_seconds = sleep_data["dailySleepDTO"]["sleepTimeSeconds"]
_LOGGER.debug(f"Sleep time seconds data: {sleep_time_seconds}")
except KeyError:
_LOGGER.debug("Sleep time seconds data is not available")

try:
if hrv_data and "hrvSummary" in hrv_data:
hrvStatus = hrv_data["hrvSummary"]
Expand All @@ -206,6 +213,7 @@ async def _async_update_data(self) -> dict:
"activity_types": activity_types,
"gear_defaults": gear_defaults,
"sleepScore": sleep_score,
"sleepTimeSeconds": sleep_time_seconds,
"hrvStatus": hrvStatus,
}

Expand Down
1 change: 1 addition & 0 deletions custom_components/garmin_connect/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@
SensorStateClass.MEASUREMENT,
True,
],
"sleepTimeSeconds": ["Total Sleep Duration", UnitOfTime.MINUTES, "mdi:sleep", None, SensorStateClass.TOTAL, True],
"hrvStatus": [
"HRV Status",
None,
Expand Down