Skip to content

Instantly share code, notes, and snippets.

@ftes
Created January 12, 2020 22:11
Show Gist options
  • Save ftes/6a08f097f3d75ea173a258d59db8cb32 to your computer and use it in GitHub Desktop.
Save ftes/6a08f097f3d75ea173a258d59db8cb32 to your computer and use it in GitHub Desktop.
zigbee2mqtt dynamic configuration.yaml with env variable substitution (e.g. for dynamic configuration via balena.io cloud)
# Environment variables are escaped by the envsubst entrypoint
homeassistant: false
permit_join: $ZIGBEE2MQTT_PERMIT_JOIN
mqtt:
base_topic: zigbee2mqtt
server: 'mqtt://mqtt'
serial:
port: $ZIGBEE2MQTT_SERIAL_PORT
# Write auto-generated data to other files
devices: devices.yaml
groups: groups.yaml
version: '2'
services:
mqtt:
image: eclipse-mosquitto
volumes:
- mosquitto_data:/mosquitto/data
- mosquitto_log:/mosquitto/log
zigbee2mqtt:
image: koenkk/zigbee2mqtt
volumes:
# Overwrite configuration.yaml with env-var-substituted version of configuration.yaml.env on every startup
- ./:/custom
- zigbee2mqtt_data:/app/data
entrypoint: /custom/envsubst.sh
depends_on:
- mqtt
privileged: true
environment:
TZ: Europe/Berlin
# Uncomment for local development.
# Comment when deploying to balena.io - it does not support env var substitution in compose file
# ZIGBEE2MQTT_PERMIT_JOIN: "${ZIGBEE2MQTT_PERMIT_JOIN}"
# ZIGBEE2MQTT_SERIAL_PORT: "${ZIGBEE2MQTT_SERIAL_PORT}"
volumes:
db:
zigbee2mqtt_data:
mosquitto_data:
mosquitto_log:
#!/bin/sh
# Interpolate (substitute) environment variables in configuration.yaml.env.
# Write the result to /app/data/configuration.yaml
INPUT=/custom/configuration.yaml.env
OUTPUT=/app/data/configuration.yaml
( echo "cat <<EOF" ; cat "$INPUT" ; echo EOF ) | sh > "$OUTPUT"
./run.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment