Skip to content

Add‐ons feature : add env variables

Alexandre edited this page Oct 11, 2023 · 6 revisions

Auto scripting feature

Most add-ons include a feature to add your custom environment variables execute when it is starting.

You just need to create a folder named /config/addons_autoscripts/${slug}.sh, slug corresponding to the "slug" value from the addon config.json in my repository.

In this folder, you need to create a file named config.yaml that will contain the environment variables that you wish to add to the addon. It must respect the yaml format - to be sure you can use the site https://www.yamllint.com/ to check its validity. Here is a customizable example : https://github.com/alexbelgium/hassio-addons/blob/master/.templates/config.template

Examples

Example 1 : add a TZ variable to your addon
#!/usr/bin/env bashio
echo "Starting script"
# Installing cron
apt-get update
apt-get install cron -yqq
# Setting cron
echo "echo \"hello\"" > /etc/cron.hourly/hello
chmod 777 /etc/cron.hourly/hello
# Starting cron
service cron start & true
```yaml
</details>
---
#============================#
# ALEXBELGIUM'S ENV INJECTOR #
#============================#
#
# All env variables set in this file will be enabled in the app
# This allows enabling more options that normally available in the addon options
# This file must be filled according to the yaml format.
# If the format is invalid, the addon will note an error.
# To validate your yaml, you can use the free online tool http://www.yamllint.com/

# EXAMPLE of the format (you need to remove the # for it to become active)
TZ: Europe/Paris
```yaml