fix_govee_lights.sh
Recovers Govee lighting by running a repair routine inside the Home Assistant container.
Note
Live script from my home-lab server. Tokens, IDs, phone numbers and other secrets have been replaced with
placeholders like
<WHATSAPP_GROUP_ID> — everything else is the real, running code.
#!/bin/bash
echo "=== Home Assistant Govee2MQTT Lights Auto-Fix ==="
# HA container name
HA_CONTAINER=$(docker ps --format "{{.Names}}" | grep homeassistant)
if [ -z "$HA_CONTAINER" ]; then
echo "Home Assistant container not found!"
exit 1
fi
# Run Python inside HA container
docker exec -i $HA_CONTAINER /bin/bash -c "
python3 - <<'EOF'
import json
import os
import shutil
STORAGE_PATH = '/config/.storage/core.entity_registry'
BACKUP_PATH = '/config/.storage/core.entity_registry.bak'
# 1. Check file exists
if not os.path.exists(STORAGE_PATH):
print(f'Error: {STORAGE_PATH} not found!')
exit(1)
# 2. Backup original file
shutil.copy2(STORAGE_PATH, BACKUP_PATH)
print(f'Backup created at {BACKUP_PATH}')
# 3. Load entity_registry
with open(STORAGE_PATH, 'r') as f:
data = json.load(f)
updated_count = 0
# 4. Patch missing color_mode for lights
for entry in data.get('data', {}).get('entities', []):
if entry.get('entity_id', '').startswith('light.'):
capabilities = entry.get('capabilities', {})
if 'color_mode' not in capabilities or capabilities['color_mode'] is None:
capabilities['color_mode'] = 'rgb'
entry['capabilities'] = capabilities
updated_count += 1
print(f\"Patched {entry['entity_id']} with color_mode='rgb'\")
# 5. Save patched file
with open(STORAGE_PATH, 'w') as f:
json.dump(data, f, indent=4)
print(f'=== Patch Complete: {updated_count} lights updated ===')
EOF
"
echo "=== Auto-Fix Script Finished ==="
echo "⚠️ Remember to RESTART Home Assistant to apply changes"