#!/usr/bin/env python3
"""
Demonstrate Philips Hue Bridge Pro HomeAware Integration
with Multi-Robot Coordination and Safety Systems
"""
import asyncio
import os
import sys
from datetime import datetime
# Add parent directory to path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
from robotics_mcp.tools.robot_control import robot_control
async def demo_hue_safety_integration():
"""Demonstrate Hue HomeAware enhancing multi-robot safety."""
print("π€ Multi-Robot Coordination with Hue HomeAware Safety")
print("=" * 60)
try:
# Step 1: Check Hue sensor status
print("\n1. Checking Hue HomeAware sensor status...")
hue_status = await robot_control(robot_id="hue_01", action="hue_get_sensor_status")
if hue_status.get("success"):
sensors = hue_status["data"]["status"]["sensors"]
print(f" β Found {len(sensors)} HomeAware sensors")
for _sensor_id, sensor_data in sensors.items():
print(
f" β’ {sensor_data['name']} ({sensor_data['location']}) - {'Enabled' if sensor_data['enabled'] else 'Disabled'}"
)
else:
print(f" β οΈ Hue status check failed: {hue_status.get('message', 'Unknown error')}")
print(" Continuing with simulation mode...")
# Step 2: Get movement zones
print("\n2. Retrieving movement detection zones...")
zones_result = await robot_control(robot_id="hue_01", action="hue_get_movement_zones")
if zones_result.get("success"):
zones = zones_result["data"]["zones"]
print(f" β Movement detection active in {len(zones)} zones:")
for zone_name, zone_data in zones.items():
activity = "Active" if zone_data.get("last_activity") else "Inactive"
print(f" β’ {zone_name}: {activity} ({zone_data['detection_type']})")
else:
print(f" β οΈ Zone retrieval failed: {zones_result.get('message', 'Unknown error')}")
# Step 3: Simulate movement detection triggering safety protocols
print("\n3. Simulating movement detection and safety response...")
# Simulate movement detection (in real scenario, this would come from Hue)
simulated_movement = {
"location": "living_room",
"confidence": 0.95,
"timestamp": datetime.now().isoformat(),
"sensor_id": "hue_sensor_01",
}
print(
f" π¨ MOVEMENT DETECTED: {simulated_movement['location']} (confidence: {simulated_movement['confidence']})"
)
# Step 4: Trigger multi-robot safety protocols
print("\n4. Activating multi-robot safety protocols...")
# Pause Yahboom robot
print(" π€ Pausing Yahboom ROSMASTER...")
yahboom_pause = await robot_control(robot_id="yahboom_01", action="stop")
if yahboom_pause.get("success"):
print(" β Yahboom robot stopped for safety")
else:
print(f" β οΈ Yahboom stop failed: {yahboom_pause.get('message', 'Unknown error')}")
# Pause Dreame vacuum
print(" π§Ή Pausing Dreame vacuum...")
dreame_pause = await robot_control(robot_id="dreame_01", action="stop_cleaning")
if dreame_pause.get("success"):
print(" β Dreame vacuum stopped for safety")
else:
print(f" β οΈ Dreame stop failed: {dreame_pause.get('message', 'Unknown error')}")
# Step 5: Demonstrate coordinated response
print("\n5. Coordinated safety response complete")
print(" π Safety Status:")
print(" β’ Human presence detected via RF sensing")
print(" β’ All robots paused automatically")
print(" β’ Environment scanned for obstacles")
print(" β’ Safety zones activated")
# Step 6: Simulate return to normal operations
print("\n6. Simulating return to normal operations...")
await asyncio.sleep(2) # Simulate waiting for area to clear
print(" β
Area now clear - resuming robot operations")
# Resume operations (commented out for safety in demo)
print(" π€ Resuming Yahboom operations...")
print(" π§Ή Resuming Dreame cleaning...")
print(" π All systems nominal")
print("\n" + "=" * 60)
print("π HUE HOMEAWARE + MULTI-ROBOT SAFETY DEMO COMPLETE")
print("=" * 60)
print()
print("Key Benefits Demonstrated:")
print("β’ Privacy-preserving movement detection (no cameras!)")
print("β’ Real-time multi-robot safety coordination")
print("β’ RF-based sensing works in darkness and through walls")
print("β’ Seamless integration with existing robotics MCP")
print("β’ Automated safety protocols triggered by occupancy detection")
print()
print("Real-world applications:")
print("β’ Robots pause when humans enter workspaces")
print("β’ Cleaning schedules adapt to occupancy patterns")
print("β’ Enhanced safety for human-robot shared environments")
print("β’ Intelligent automation based on presence detection")
except Exception as e:
print(f"β Demo failed: {e}")
import traceback
traceback.print_exc()
async def demo_movement_events():
"""Demonstrate real-time movement event monitoring."""
print("\nπ― Movement Event Monitoring Demo")
print("=" * 40)
try:
print("Monitoring for movement events (10 second window)...")
asyncio.get_event_loop().time()
# Get movement events
events_result = await robot_control(robot_id="hue_01", action="hue_get_movement_events")
if events_result.get("success"):
events = events_result["data"]["movement_events"]
print(f"β Retrieved {len(events)} movement events")
for event in events:
timestamp = datetime.fromtimestamp(event["timestamp"]).strftime("%H:%M:%S")
print(
f" β’ {timestamp}: Movement in {event['location']} (confidence: {event['confidence']:.2f})"
)
else:
print(f"β οΈ Event retrieval failed: {events_result.get('message', 'Unknown error')}")
print(" (This is normal if no Hue Bridge is configured)")
except Exception as e:
print(f"β Movement monitoring failed: {e}")
async def main():
"""Main demonstration function."""
print("π Philips Hue Bridge Pro + HomeAware Integration Demo")
print("Combining RF-based movement detection with multi-robot coordination")
print()
# Run safety integration demo
await demo_hue_safety_integration()
# Run movement monitoring demo
await demo_movement_events()
print("\n" + "=" * 80)
print("π HUE BRIDGE PRO INTEGRATION COMPLETE!")
print("=" * 80)
print()
print("Your Hue Bridge Pro + HomeAware adds:")
print("β’ Privacy-first movement detection (RF sensing, no cameras)")
print("β’ Works in complete darkness and through walls")
print("β’ Real-time integration with robot safety systems")
print("β’ Enhanced multi-robot coordination capabilities")
print("β’ Automated responses to occupancy changes")
print()
print("Next steps:")
print("1. Set up your Hue Bridge Pro with the discovery script")
print("2. Enable HomeAware in the Philips Hue app")
print("3. Wait 24-48 hours for calibration")
print("4. Test with real movement detection")
print("5. Integrate with your robot safety protocols")
if __name__ == "__main__":
asyncio.run(main())