Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A timezone could not be found #39

Closed
cybersea54 opened this issue Sep 21, 2023 · 6 comments · Fixed by #40
Closed

A timezone could not be found #39

cybersea54 opened this issue Sep 21, 2023 · 6 comments · Fixed by #40

Comments

@cybersea54
Copy link

cybersea54 commented Sep 21, 2023

I'm running Home Assistant 2023.9.2 Supervisor 2023.09.2 Operating System 10.5 Frontend 20230911.0 - latest, not a Docker version, but still getting this error when try to setup integration.

Logger: custom_components.petkit
Source: custom_components/petkit/util.py:34
Integration: PetKit ([documentation](https://github.com/RobertD502/home-assistant-petkit/blob/main/README.md), [issues](https://github.com/RobertD502/home-assistant-petkit/issues))
First occurred: 14:28:37 (2 occurrences)
Last logged: 14:36:08
A timezone could not be found. If you are running Home Assistant as a standalone Docker container, you must define the TZ environmental variable.

TZ environment variable presents in system:

изображение

@RobertD502
Copy link
Owner

RobertD502 commented Sep 21, 2023

Can you please run the command cat /etc/timezone. This will provide the timezone that Home Assistant OS has defined. You'll need to be within the Home Assistant OS shell terminal when running the command. The env command you ran returns what the TZ variable is set to within the docker container that resides inside of the OS.

Edit: Also, run the cat /etc/timezone command within the Home Assistant container - this will let us know if the time zone in the /etc/timezone file (within the docker container) conflicts with the TZ environment variable that is defined for the HA docker container within Home Assistant OS. Disregard: The Home Assistant container within Home Assistant OS doesn't use /etc/timezone.

Edit 2: Add tzlocal: debug to logger in your configuration.yaml file, save it, then restart Home Assistant. After Home Assistant restarts, look at your full Home Assistant logs to see what/if any debug logging is returned by the tzlocal library which this integration uses to get your system's timezone name.

Edit 3: To see if the tzlocal library is able to find the TZ env variable - In the terminal (as seen in your screenshot), run the command python -c "import os; print(os.environ.get(\"TZ\"))". This is the command that the tzlocal library is using under the hood to determine the timezone name.

@cybersea54
Copy link
Author

cybersea54 commented Sep 22, 2023

Here is output from Home Assistant OS, it seems time zone didn't set:
изображение
There is full logs:

2023-09-22 13:11:09.575 DEBUG (MainThread) [tzlocal] Found a TZ environment: Asia/Ho_Chi_Minh
2023-09-22 13:11:09.575 DEBUG (MainThread) [tzlocal] TZ does not contain a time zone name
2023-09-22 13:11:10.849 ERROR (MainThread) [custom_components.petkit] A timezone could not be found. If you are running Home Assistant as a standalone Docker container, you must define the TZ environmental variable.

There is python output:
изображение

@RobertD502
Copy link
Owner

Home Assistant OS does have a timezone set (Etc/UTC), so there is no issue there.

This seems to be a bug with the tzlocal library. Based on their code, the reason it is failing is because Asia/Ho_Chi_Minh is missing from their list. So, this isn't anything wrong on your end, rather, a missing timezone in their code.

@RobertD502
Copy link
Owner

I raised an issue with the maintainer of the library, but until that is fixed on their end and a new version of tzlocal is pushed out, the Asia/Ho_Chi_Minh timezone won't work. I do see that the Asia/Bangkok timezone has the same offset as Asia/Ho_Chi_Minh - In the meantime, if you set your timezone to Bangkok via the Home Assistant GUI, you should be able to use this integration.

@RobertD502
Copy link
Owner

Disregard the comment above. I am working on implementing a Timezone option in the configuration flow where you'll be able to select Asia/Ho_Chi_Minh as an option - this way you won't have to change your timezone in Home Assistant and we don't have to wait on the tzlocal library maintainer to update his code.

@RobertD502
Copy link
Owner

@cybersea54 Upgrade to version 0.1.10 and select Asia/Ho_Chi_Minh as your timezone during the integration setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants