handle missing MQTT addon

- we have to check if the supervisor API and a
MQTT broker add-on is installed. If not we assume
the user has an external MQTT broker
This commit is contained in:
Stefan Allius
2025-05-31 18:54:22 +02:00
parent 4fda544b19
commit ffaef139a2

View File

@@ -1,18 +1,28 @@
#!/usr/bin/with-contenv bashio #!/usr/bin/with-contenv bashio
echo "Add-on environment started" echo "run.sh: info: Add-on environment started"
bashio::cache.flush_all
echo "check for Home Assistant MQTT" echo "run.sh: info: check for Home Assistant supervisor API"
MQTT_HOST=$(bashio::services mqtt "host") MQTT_HOST=""
MQTT_PORT=$(bashio::services mqtt "port") if bashio::supervisor.ping; then
MQTT_USER=$(bashio::services mqtt "username") echo "run.sh: info: check for Home Assistant MQTT"
MQTT_PASSWORD=$(bashio::services mqtt "password") if bashio::services mqtt; then
MQTT_HOST=$(bashio::services mqtt "host")
MQTT_PORT=$(bashio::services mqtt "port")
MQTT_USER=$(bashio::services mqtt "username")
MQTT_PASSWORD=$(bashio::services mqtt "password")
else
echo "run.sh: error: Home Assistant service MQTT not available!"
fi
else
echo "run.sh: error: Home Assistant supervisor API not available!"
fi
# if a MQTT was/not found, drop a note # if a MQTT was/not found, drop a note
if [ -z "$MQTT_HOST" ]; then if [ -z "$MQTT_HOST" ]; then
echo "MQTT not found" echo "run.sh: info: MQTT configuration not found"
else else
echo "MQTT found" echo "run.sh: info: MQTT found"
export MQTT_HOST export MQTT_HOST
export MQTT_PORT export MQTT_PORT
export MQTT_USER export MQTT_USER