44if bashio::supervisor.ping 2> /dev/null; then
55 STANDALONE=false
66 bashio::log.info " Running as HA Add-on (Supervisor detected)"
7+ # Wait for Supervisor API to be fully ready (avoids "forbidden" on fresh install)
8+ for i in 1 2 3; do
9+ if bashio::config ' log_level' & > /dev/null; then break ; fi
10+ bashio::log.info " Waiting for Supervisor API... ($i /3)"
11+ sleep 2
12+ done
713else
814 STANDALONE=true
915 bashio::log.info " Running standalone (no Supervisor)"
@@ -25,20 +31,29 @@ if [ "$STANDALONE" = "false" ]; then
2531 export SANDBOX_AI_PROVIDER=" $AI_PROVIDER "
2632
2733 # MQTT — use HA Supervisor MQTT service if available
28- if bashio::services.available " mqtt" ; then
29- export SANDBOX_MQTT_HOST=" $( bashio::services mqtt ' host' ) "
30- export SANDBOX_MQTT_PORT=" $( bashio::services mqtt ' port' ) "
31- export SANDBOX_MQTT_USER=" $( bashio::services mqtt ' username' ) "
32- export SANDBOX_MQTT_PASS=" $( bashio::services mqtt ' password' ) "
34+ if bashio::services.available " mqtt" 2> /dev/null ; then
35+ export SANDBOX_MQTT_HOST=" $( bashio::services mqtt ' host' 2> /dev/null || echo ' ' ) "
36+ export SANDBOX_MQTT_PORT=" $( bashio::services mqtt ' port' 2> /dev/null || echo ' 1883 ' ) "
37+ export SANDBOX_MQTT_USER=" $( bashio::services mqtt ' username' 2> /dev/null || echo ' ' ) "
38+ export SANDBOX_MQTT_PASS=" $( bashio::services mqtt ' password' 2> /dev/null || echo ' ' ) "
3339 export SANDBOX_MQTT_USE_TLS=" false"
34- bashio::log.info " Using Supervisor MQTT service at ${SANDBOX_MQTT_HOST} :${SANDBOX_MQTT_PORT} "
40+ if [ -n " ${SANDBOX_MQTT_HOST} " ]; then
41+ bashio::log.info " Using Supervisor MQTT service at ${SANDBOX_MQTT_HOST} :${SANDBOX_MQTT_PORT} "
42+ else
43+ bashio::log.warning " MQTT service available but could not read config"
44+ fi
45+ else
46+ bashio::log.info " No MQTT service found in Supervisor"
3547 fi
3648 export SANDBOX_MQTT_ENABLED=" $( bashio::config ' mqtt_enabled' ) "
3749 export SANDBOX_MQTT_TLS=" $( bashio::config ' mqtt_tls' ) "
3850
3951 # HA API via Supervisor
4052 export SANDBOX_HA_URL=" http://supervisor/core"
41- export SANDBOX_HA_TOKEN=" ${SUPERVISOR_TOKEN} "
53+ export SANDBOX_HA_TOKEN=" ${SUPERVISOR_TOKEN:- } "
54+ if [ -z " ${SANDBOX_HA_TOKEN} " ]; then
55+ bashio::log.warning " SUPERVISOR_TOKEN not set — HA API access disabled"
56+ fi
4257
4358 LOG_LEVEL=" $( bashio::config ' log_level' ) "
4459else
0 commit comments