A comprehensive Home Assistant integration for Microsoft 365 OneDrive for Business. This component allows you to seamlessly use your OneDrive account as a native backup location and monitor your cloud storage.
- Native Backup Target: "Microsoft 365 OneDrive" appears directly in the Home Assistant backup UI, allowing you to create backups and send them to the cloud in one click.
- Full Backup Management: Complete backup lifecycle support including upload, download, list, and delete operations.
- Protected Backup Support: Backups are properly marked as encrypted/protected, maintaining security standards.
- Automatic Cleanup: Configurable automatic deletion of old backups to manage storage space.
- Automation-Friendly Service: Includes a service (
hass-onedrive-m365.upload_latest_backup) to upload your most recent local backup, perfect for use in advanced automations. - Large File Support: Automatically uses resumable, chunked uploads for large backup files (>4MB).
- Storage Monitoring: Includes a sensor entity to monitor your OneDrive storage usage.
- Metadata Preservation: Maintains complete backup metadata including addons, folders, and Home Assistant version information.
- Robust Error Handling: Comprehensive error handling and logging for troubleshooting.
- Home Assistant 2024.1.0 or newer (for backup agent support)
- A Microsoft 365 account with OneDrive for Business
- An Azure AD application with appropriate permissions
- Open HACS in your Home Assistant instance
- Click on "Integrations"
- Click the three dots menu in the top right and select "Custom repositories"
- Add this repository URL:
https://github.com/ghostinator/hass-onedrive-m365 - Select "Integration" as the category
- Click "Add"
- Search for "Microsoft 365 OneDrive" and install it
- Restart Home Assistant
- Download the latest release from GitHub
- Extract the
hass-onedrive-m365folder to yourcustom_componentsdirectory - Restart Home Assistant
- Go to Azure Portal
- Navigate to "Azure Active Directory" → "App registrations"
- Click "New registration"
- Name your application (e.g., "Home Assistant OneDrive Backup")
- Select "Accounts in this organizational directory only"
- Set redirect URI to:
https://login.microsoftonline.com/common/oauth2/nativeclient - After creation, note down:
- Application (client) ID
- Directory (tenant) ID
- Go to "Certificates & secrets" → "New client secret"
- Create a secret and note down the value
- Go to "API permissions" → "Add a permission"
- Select "Microsoft Graph" → "Delegated permissions"
- Add these permissions:
Files.ReadWrite.AllUser.Read.All
- Click "Grant admin consent" (may require admin privileges)
- Go to Settings → Devices & Services
- Click "Add Integration"
- Search for "Microsoft 365 OneDrive"
- Enter the required information:
- Client ID (from Azure AD app)
- Client Secret (from Azure AD app)
- Tenant ID (from Azure AD)
- User Principal Name (your Microsoft 365 email)
- Click Submit
- Go to Settings → System → Backups
- Click "Create backup"
- Select "Microsoft 365 OneDrive" as the location
- Configure your backup options
- Click "Create"
The integration will:
- Stream the backup directly to OneDrive
- Preserve all metadata (addons, folders, Home Assistant version)
- Mark the backup as protected/encrypted
- Automatically clean up old backups if configured
- Go to Settings → System → Backups
- Your OneDrive backups will appear in the list marked as "Protected"
- Click on a backup to view details including:
- Backup size and date
- Included addons and folders
- Home Assistant version
- Click "Restore" to restore from that backup
Use the hass-onedrive-m365.upload_latest_backup service in your automations:
automation:
- alias: "Daily Backup to OneDrive"
trigger:
- platform: time
at: "03:00:00"
action:
- service: hass-onedrive-m365.upload_latest_backupThe integration includes several debug services for troubleshooting:
hass-onedrive-m365.debug_backup_agents: Test backup agent discoveryhass-onedrive-m365.debug_list_backups: Test backup listing functionalityhass-onedrive-m365.debug_test_backup_roundtrip: Test complete backup upload/download cycle
After setup, you can configure these options:
- Backup Folder: The OneDrive folder where backups are stored (default: "Home Assistant Backups")
- Max Backups: Maximum number of backups to keep (default: 10, range: 1-100)
- Auto Cleanup: Automatically delete old backups when the limit is reached (default: enabled)
sensor.microsoft_365_onedrive_storage: Shows OneDrive storage usage- State: Used storage in GB
- Attributes:
total_storage_gb: Total available storageused_storage_gb: Used storagefree_storage_gb: Free storageusage_percentage: Percentage of storage usedowner_name: Account owner's display name
- Small Files (<4MB): Direct upload to OneDrive
- Large Files (≥4MB): Resumable upload sessions with chunked transfer
- Download: Streaming download with 8KB chunks for memory efficiency
- Validation: File size verification and integrity checks
The integration maintains a local metadata cache to improve performance:
- Stores backup metadata locally for faster listing
- Syncs with remote backups to remove orphaned entries
- Preserves complete Home Assistant backup structure
- Backups are marked as protected/encrypted by default
- Uses Microsoft Graph API with proper OAuth2 authentication
- Supports token refresh and error recovery
- No sensitive data stored in plain text
This error occurs when the backup metadata is missing required information. The integration now automatically ensures all backups include the necessary metadata for restoration. If you encounter this with older backups:
- Create a new backup using the updated integration
- Use the new backup for restoration
- Older backups may need to be deleted and recreated
If you encounter authentication errors:
- Verify your Azure AD app permissions are correctly configured
- Ensure admin consent has been granted for the permissions
- Check that your client secret hasn't expired
- Try removing and re-adding the integration
For upload issues:
- Check your OneDrive storage quota
- Verify network connectivity
- Check Home Assistant logs for detailed error messages
- Ensure the backup file isn't corrupted
- For large files, ensure stable internet connection for resumable uploads
If backups fail to download or appear corrupted:
- Check the backup file size in OneDrive matches the expected size
- Verify network stability during download
- Check Home Assistant logs for streaming errors
- Try downloading again - the integration supports resumable downloads
Enable debug logging for more detailed information:
logger:
default: info
logs:
custom_components.hass-onedrive-m365: debugThis will provide detailed information about:
- Authentication and token management
- File upload/download progress
- Metadata extraction and processing
- Error conditions and recovery attempts
- Requires Home Assistant 2024.1.0+ for full backup agent functionality
- OneDrive for Business accounts only (personal OneDrive not supported)
- Maximum backup size limited to 2GB (configurable safety limit)
- Requires stable internet connection for large file transfers
- Report issues on GitHub Issues
- Join the discussion on Home Assistant Community
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
If you find this integration helpful and would like to support further development or simply show your appreciation, you can use the following donation addresses:
PayPal: [email protected]
SOL: AUyf3DxRL9uKWf7ePEjY5GhSL3XJtAqQZ2w7kUMLi1xS
ETH, Monad, Base, Polygon: 0x521E4D25212180B5f8A9f0261D00835EA3bd7fa6
Sui: 0x89844c9e0c509115e8d2747b02d230ceb2bf96a1246707416177457d0e1bb593e
Bitcoin: bc1qkljmuw3mexksnk0wg06p35xvhpkakgnhyp63la