sfortis / openai_tts

OpenAI TTS custom component for HA
GNU General Public License v3.0
60 stars 17 forks source link

Unable to use environment variable #3

Closed codysaylor closed 10 months ago

codysaylor commented 10 months ago

Hi, first I want to say great job on this and thank you for making it!

One small issue I found though that I was wondering if you could look into: the configuration.yaml file is not happy with me using environment variables for the API key.

Failed to restart Home Assistant The system cannot restart because the configuration is not valid: Error loading /config/configuration.yaml: OPENAIAPI

This seems to work with other items in the configuration.yaml file so I assume it's related to the integration, but might not be.

tts:
  - platform: openai_tts
    api_key: !env_var OPENAIAPI
sfortis commented 10 months ago

This error comes before integration is loaded, by HA itself when validating configuration.yaml (i'm not sure if env_var can be used on api_key, never used that!)

You can use secrets.yaml for storing the api keys which is straightforward.

tts:

If you have your reasons to use environment variables, try to specify this on your secrets.yaml like:

openai_api_key: !env_var OPENAIAPI

this may work for you ;)

codysaylor commented 10 months ago

Sorry, had a misconfiguration on my end. I forgot to pass the environment variable into the docker compose file, which is why it was not working. Thank you for the suggestion though!