Skip to content

Athozs/hass-environment-variable

Repository files navigation

hacs_badge

Environment variable for Home Assistant

Environment Variable integration for Home Assistant allows to add environment variable automatically each time Home Assistant is started, even after Home Assistant is updated/upgraded.

This integration is useful for Home Assistant OS (HAOS).

This integration is useless for Home Assistant Docker image and Core installations.

Variables that are set with this integration won't be available for automations.

1. INSTALL WITH HACS

Environment Variable integration may not be available yet from HACS interface, install Environment Variable by adding this Github repository to HACS custom repositories:

hacs-custom-repo hacs-repo-box

2. INSTALL WITHOUT HACS

2.1. HAOS - Home Assistant Operating System

  • Go to the Add-on store
  • Install one of the SSH add-ons (you need to enable advanced mode in your user profile to see them)
  • Configure the SSH add-on you chose by following the documentation for it
  • Start the SSH add-on
  • Connect to the SSH add-on
  • Download the latest release of Environment Variable from Github (.zip):
wget https://github.com/Athozs/hass-environment-variable/releases/latest/download/environment_variable.zip
  • Unzip archive:
unzip environment_variable.zip
  • Move or copy folder environment_variable into config/custom_components/ directory:
cp -r environment_variable config/custom_components/

2.2. Docker and Core

If you're running Home Assistant core (Python package) directly on host, or running Home Assistant Docker image, you don't need Environment Variable integration. You should set your environment variables from your host OS or Docker Compose file.

3. CONFIGURATION

  1. Enable Environment Variable integration in configuration.yaml and set custom environment variables:

Model:

# configuration.yaml
---
default_config:
environment_variable:
  <string>: <string>
  <string>: <string>
  # ...: ...

Example:

# configuration.yaml
---
default_config:
environment_variable:
  REQUESTS_CA_BUNDLE: /etc/ssl/certs/ca-certificates.crt
  FOOBAR: baz
# ...
  1. Restart Home Assistant.

  2. You may need to reload your integrations after Home Assistant has started to take environment variables into account.

  3. Check the logs, look for pattern environment_variable in traces (there is not UI for Environment Variable).

4. HOW DOES Environment Variable WORK ?

When enabled, Environment Variable integration sets environment variables at Home Assistant application level using standard Python lib, meaning environment variables are available only inside Home Assistant Python application/integrations.

Environment variables that are set with this integration won't be available at operating system level.

It loads environment variables only at Home Assistant startup.

There is no control on integrations startup order, you may need to reload your integration after Home Assistant has completely started to take environment variables into account.

For now, Environment Variable won't be visible in Home Assistant integrations dashboard, there is not UI component for Environment Variable integration. This may be possible in future release.

5. UNINSTALL

  1. Delete Environment Variable from custom components:
rm -r config/custom_components/environment_variable
  1. Remove environment_variable: config key from configuration.yaml:
# configuration.yaml
---
default_config:
# environment_variable:
#   FOOBAR: baz
# ...
  1. Restart Home Assistant.

6. TROUBLESHOOTING

You can't check your environment variables using the Shell prompt, because environment variables that are set with this integration are only available at Home Assistant Python application level.

The only way to check environment variable is to access it through Python code inside an integration.

7. KNOWN ISSUES

n/a