Skip to content

feat: Enhance Nanit integration with WebSocket resilience and improved controls - #33

Open
tanvach wants to merge 1 commit into
indiefan:mainfrom
tanvach:main
Open

feat: Enhance Nanit integration with WebSocket resilience and improved controls#33
tanvach wants to merge 1 commit into
indiefan:mainfrom
tanvach:main

Conversation

@tanvach

@tanvach tanvach commented Jul 10, 2025

Copy link
Copy Markdown

This comprehensive update combines multiple enhancements to the Nanit Home Assistant integration:

WebSocket Connection Reset Mechanism

  • Implements automatic WebSocket reconnection when commands fail to receive responses
  • Configurable timeout system to detect and recover from 'half-dead' connections
  • Automatic command retry after successful reconnection
  • Resolves MQTT switch unresponsiveness issues that required manual container restarts

Enhanced Camera Controls

  • Added standby mode toggle support for compatible Nanit cameras
  • Improved light switch functionality with initial state support
  • Refactored MQTT light hooks for better reliability
  • Fixed crashes when MQTT is not enabled

Configuration Options

  • NANIT_MQTT_RESET_WHEN_FAILED: Enable automatic WebSocket reset (default: false)
  • NANIT_WEBSOCKET_TIMEOUT: Command response timeout (default: 1s)
  • Backward compatible - features are opt-in

Reliability Improvements

  • Enhanced WebSocket connection lifecycle management
  • Improved error handling and logging for debugging
  • Cooldown bypass for immediate reconnection on failures
  • Robust command tracking and retry mechanisms

Documentation

  • Comprehensive setup and troubleshooting guide in docs/switches.md
  • Configuration examples and best practices
  • Detailed explanation of the reset mechanism

This update ensures the Nanit integration remains stable and responsive over long periods while adding valuable new control capabilities.

Full transparency - this PR generation was created with assistance of AI (Claud 4 Sonnet). Please let me know if you have any questions or issues. I've tested on a set up with 2 cameras and it's been working fine for a week now.

…d controls

This comprehensive update combines multiple enhancements to the Nanit Home Assistant integration:

## WebSocket Connection Reset Mechanism
- Implements automatic WebSocket reconnection when commands fail to receive responses
- Configurable timeout system to detect and recover from 'half-dead' connections
- Automatic command retry after successful reconnection
- Resolves MQTT switch unresponsiveness issues that required manual container restarts

## Enhanced Camera Controls
- Added standby mode toggle support for compatible Nanit cameras
- Improved light switch functionality with initial state support
- Refactored MQTT light hooks for better reliability
- Fixed crashes when MQTT is not enabled

## Configuration Options
- NANIT_MQTT_RESET_WHEN_FAILED: Enable automatic WebSocket reset (default: false)
- NANIT_WEBSOCKET_TIMEOUT: Command response timeout (default: 1s)
- Backward compatible - features are opt-in

## Reliability Improvements
- Enhanced WebSocket connection lifecycle management
- Improved error handling and logging for debugging
- Cooldown bypass for immediate reconnection on failures
- Robust command tracking and retry mechanisms

## Documentation
- Comprehensive setup and troubleshooting guide in docs/switches.md
- Configuration examples and best practices
- Detailed explanation of the reset mechanism

This update ensures the Nanit integration remains stable and responsive over long periods while adding valuable new control capabilities.
@tanvach

tanvach commented Dec 12, 2025

Copy link
Copy Markdown
Author

Update: I’ve been running with these changes with two camera and a light switch for many months now without any issues.

stuart22 added a commit to stuart22/home_assistant_nanit that referenced this pull request Apr 12, 2026
…diefan#33)

- Connection registry routes MQTT commands to correct camera by baby UID
- Manager registry tracks websocket connection managers per baby
- Global MQTT handler registration (moved from per-connection to app-level)
- Handler signatures now include babyUID for proper multi-camera routing
- ForceReconnect() with cooldown skip for failed command recovery
- Pending retry queue replays failed commands after reconnection
- New env vars: NANIT_MQTT_RESET_WHEN_FAILED, NANIT_WEBSOCKET_TIMEOUT
stuart22 added a commit to stuart22/home_assistant_nanit that referenced this pull request Apr 12, 2026
…diefan#33)

- Connection registry routes MQTT commands to correct camera by baby UID
- Manager registry tracks websocket connection managers per baby
- Global MQTT handler registration (moved from per-connection to app-level)
- Handler signatures now include babyUID for proper multi-camera routing
- ForceReconnect() with cooldown skip for failed command recovery
- Pending retry queue replays failed commands after reconnection
- New env vars: NANIT_MQTT_RESET_WHEN_FAILED, NANIT_WEBSOCKET_TIMEOUT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants