#!/bin/bash # Test script to diagnose TV physical response to CEC commands echo "════════════════════════════════════════════════════════════" echo " TV Physical Response Diagnostic Test" echo "════════════════════════════════════════════════════════════" echo "" # Load configuration if [ -f ../.env ]; then export $(grep -v '^#' ../.env | xargs) elif [ -f .env ]; then export $(grep -v '^#' .env | xargs) fi CEC_DEVICE=${CEC_DEVICE:-0} echo "Using CEC_DEVICE: $CEC_DEVICE" echo "" # Test 1: Check current power status echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "📊 Test 1: Current TV Power Status" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" echo "Command: echo \"pow $CEC_DEVICE\" | cec-client -s -d 1" echo "" INITIAL_STATE=$(echo "pow $CEC_DEVICE" | cec-client -s -d 1 2>&1) echo "$INITIAL_STATE" echo "" if echo "$INITIAL_STATE" | grep -q "on"; then echo "✅ TV reports: ON" INITIAL_ON=true elif echo "$INITIAL_STATE" | grep -q "standby"; then echo "✅ TV reports: STANDBY/OFF" INITIAL_ON=false else echo "⚠️ TV power state unclear" INITIAL_ON=unknown fi echo "" read -p "❓ Does this match the actual TV LED indicator? (y/n): " -n 1 -r echo "" if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo "⚠️ CEC status doesn't match physical state - possible CEC communication issue" fi echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "🔌 Test 2: Power ON Command" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" echo "👀 WATCH YOUR TV SCREEN AND LED NOW!" echo "" echo "Sending: echo \"on $CEC_DEVICE\" | cec-client -s -d 1" echo "" START_TIME=$(date +%s) TURN_ON_RESULT=$(echo "on $CEC_DEVICE" | cec-client -s -d 1 2>&1) END_TIME=$(date +%s) DURATION=$((END_TIME - START_TIME)) echo "$TURN_ON_RESULT" echo "" echo "⏱️ Command took: ${DURATION}s" echo "" if echo "$TURN_ON_RESULT" | grep -iq "success\|power on"; then echo "✅ CEC command reported success" else echo "❌ CEC command may have failed" fi echo "" echo "Waiting 5 seconds for TV to respond..." sleep 5 # Check power status after ON command AFTER_ON_STATE=$(echo "pow $CEC_DEVICE" | cec-client -s -d 1 2>&1) if echo "$AFTER_ON_STATE" | grep -q "on"; then echo "✅ TV now reports: ON" else echo "⚠️ TV still reports: STANDBY/OFF" fi echo "" read -p "❓ Did the TV screen actually turn on? (y/n): " -n 1 -r echo "" TV_TURNED_ON=$REPLY if [[ ! $TV_TURNED_ON =~ ^[Yy]$ ]]; then echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "🔄 Test 3: Try with Active Source Command" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" echo "Some TVs need explicit input switch. Trying 'active source'..." echo "" echo "Command: echo \"as\" | cec-client -s -d 1" AS_RESULT=$(echo "as" | cec-client -s -d 1 2>&1) echo "$AS_RESULT" echo "" echo "Waiting 3 seconds..." sleep 3 echo "" read -p "❓ Did the TV screen turn on now? (y/n): " -n 1 -r echo "" if [[ $REPLY =~ ^[Yy]$ ]]; then echo "✅ TV responds to 'active source' command!" echo "💡 Solution: Display Manager should send both 'on' and 'as' commands" fi fi echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "📺 Test 4: Check TV Vendor" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" echo "Command: echo \"ven $CEC_DEVICE\" | cec-client -s -d 1" VENDOR_INFO=$(echo "ven $CEC_DEVICE" | cec-client -s -d 1 2>&1) echo "$VENDOR_INFO" echo "" if echo "$VENDOR_INFO" | grep -iq "samsung"; then echo "📌 Samsung TV detected" echo " Known issue: Some Samsung TVs need 'as' (active source) after 'on'" elif echo "$VENDOR_INFO" | grep -iq "lg"; then echo "📌 LG TV detected" echo " Known issue: Some LG TVs have 'Simplink' mode that must be 'Full'" elif echo "$VENDOR_INFO" | grep -iq "sony"; then echo "📌 Sony TV detected" echo " Known issue: Check 'Bravia Sync' settings" fi echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "📊 Test Summary" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" if [[ $TV_TURNED_ON =~ ^[Yy]$ ]]; then echo "✅ SUCCESS: TV turns on with CEC commands" echo "" echo "Your configuration is working correctly." else echo "❌ ISSUE: TV doesn't respond physically" echo "" echo "💡 Troubleshooting steps:" echo "" echo "1. Check TV CEC Settings:" echo " • Settings → HDMI-CEC (or Anynet+/Simplink/Bravia Sync)" echo " • Must be 'Enabled' or 'Full' mode (not 'Limited')" echo "" echo "2. Try Different HDMI Port:" echo " • Some TVs only support CEC on HDMI 1" echo " • Move Raspberry Pi to a different port" echo "" echo "3. Check HDMI Cable:" echo " • Must be HDMI 1.4 or newer" echo " • Try a different cable" echo "" echo "4. Update Display Manager:" echo " • If 'active source' worked, add it to turn_on()" echo " • Some TVs need both 'on' and 'as' commands" echo "" echo "5. Increase Wait Time:" echo " • Set CEC_POWER_ON_WAIT=10 in .env" echo " • Some TVs are slow to respond" fi echo "" echo "════════════════════════════════════════════════════════════"