RobertD502 / home-assistant-petkit

Home Assistant integration for PetKit devices
MIT License
156 stars 24 forks source link

Virtual Machine without TZ variable #37

Closed Anian-igor closed 9 months ago

Anian-igor commented 10 months ago

Hello. I've trying to setup PetKit but got well known issue regarding timezone TZ variable I've setup HassOS on virtual machine on Proxmox and don't have any TZ variable on it. Just a regula Home assistant operation system. How I can fix an issue? I already tried to create manual file with timezone (like on a pure debian) and TZ variable but without luck.

RobertD502 commented 9 months ago

If you are using Home Assistant OS then ensure you have a timezone setup within the Home Assistant settings: found under Settings --> System --> General.

Anian-igor commented 9 months ago

Yes. Timezone installed at start but I still have an issue.

RobertD502 commented 9 months ago

Please post any logs associated with PETKIT. I'm not sure if I'll be able to help much, but if you have any backups I'd recommend reverting back to before you started to tinker with manually trying to set up a timezone on the operating system.

Anian-igor commented 9 months ago

2023-09-12 17:37:24.720 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. I started with installation and trying to add something manually on a test instance.

RobertD502 commented 9 months ago

2023-09-12 17:37:24.720 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.

I started with installation and trying to add something manually on a test instance.

How did you install Home assistant on Proxmox? Was the Home Assistant OS image used to create a VM or was another operating system installed with Home Assistant on top of it as a supervised method or docker method or even pyenv? The timezone error doesn't happen with Home Assistant OS installs.

Anian-igor commented 9 months ago

Home assistant OS VM on proxmox. Not docker or supervised method

RobertD502 commented 9 months ago

In that case, this is the first I've heard of it happening. I don't have a solution on hand. If this is a test environment, I'd recreate the VM and start from scratch.

Anian-igor commented 9 months ago

This is a production environment. I don't want to recreate. I think I need to forget about Petkit service at least for some time.

RobertD502 commented 9 months ago

If you can get into the command line of the OS (not the Home Assistant CLI) and execute the command cat /etc/timezone, a valid timezone should be in that file.

The Home Assistant CLI has ha in the terminal - if you see this then you are not in the OS's terminal: image

Example of output from Home Assistant OS's terminal output for the command above:

image

Anian-igor commented 9 months ago

зображення

RobertD502 commented 9 months ago

What happens when you run ls -l /etc/localtime

RobertD502 commented 9 months ago

Also, run the command ha info and let me know the output of that (there should be a timezone listed).

Another useful command is to run docker container inspect homeassistant. Under the Config section a TZ environment variable should be defined, if the home assistant OS's home assistant container has a timezone environment variable defined.

In addition, your /etc/timezone file is showing a timezone of Europe/Kiev....For Home Assistant OS users the timezone of the OS itself should be Etc/UTC. The timezone that you set within the Home Assistant UI is set within the Home Assistant docker container that is running in the Home Assistant OS and not for the OS itself - given that your output of cat /etc/timezone is not returning Etc/UTC, this needs to be changed (I'm assuming whatever you did previously caused this change to happen).

Anian-igor commented 9 months ago

ha info зображення docker container inspect homeassistant "Env": [ "SUPERVISOR=172.30.32.2", "HASSIO=172.30.32.2", "TZ=Europe/Kyiv", cat /etc/timezone - absent after reboot

RobertD502 commented 9 months ago

cat /etc/timezone absent after a reboot? That should not be the case. The cat /etc/timezone command is looking at the OS's timezone configuration which should always be there.

Anian-igor commented 9 months ago

It's to complicated to me to resolve an issue.

RobertD502 commented 9 months ago

Hi, I think I tracked down the problem. It looks like the tzlocal library doesn't recognize the Europe/Kyiv timezone, only Europe/Kiev. I don't see the latter as an option in Home Assistant. In order to fix that, the tzlocal library maintainer will need to push out an update to include your timezone. I've created a bug report on that project and hopefully it will be fixed.

In the meantime, if you can switch your Home Assistant to another timezone that is identical to Europe/Kyiv and valid with the tzlocal library, that should get you going.

RobertD502 commented 9 months ago

@Anian-igor I see that both Europe/Kyiv and Europe/Riga observe the same time offset and Daylight savings time schedule. If you want to use this integration without waiting on the maintainer to fix the tzlocal library, you can change your timezone to Riga via the Home Assistant GUI and that should get the integration running.

Anian-igor commented 9 months ago

@Anian-igor I see that both Europe/Kyiv and Europe/Riga observe the same time offset and Daylight savings time schedule. If you want to use this integration without waiting on the maintainer to fix the tzlocal library, you can change your timezone to Riga via the Home Assistant GUI and that should get the integration running.

I tried Europe\Riga and reboot home assistant host but without luck. 2023-09-22 19:03:25.830 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.

RobertD502 commented 9 months ago

In your configuration.yaml file add tzlocal: debug to the logger. Save the file and then restart Home Assistant. Open the full Home Assistant log and there should be logging done by tzlocal in there. Share that here.

Anian-igor commented 9 months ago

It's a strange. I changed timezone in configuration but docker inspect still show Kyiv timezone. Also in logs 2023-09-22 19:25:55.149 DEBUG (MainThread) [tzlocal] Found a TZ environment: Europe/Kyiv 2023-09-22 19:25:55.149 DEBUG (MainThread) [tzlocal] TZ does not contain a time zone name

RobertD502 commented 9 months ago

Did you press update on the bottom of the page after changing the timezone in the HA GUI?

Anian-igor commented 9 months ago

Yeap. I also stopped HAOS and start after that зображення

RobertD502 commented 9 months ago

You wouldn't happen to have time_zone set in your configuration.yaml file? If so, then setting it in the GUI won't work.

Anian-igor commented 9 months ago

I tried to setup via configuration.yaml but this still didn't help

RobertD502 commented 9 months ago

Did you remove time_zone from configuration.yaml, save the file, and restart Home Assistant before attempting to set the time zone via the GUI?

Anian-igor commented 9 months ago

Yes. Remove from configuration. Reboot and shutdown host to be sure. Still didn't help. Europe/Kyiv via inspector.

RobertD502 commented 9 months ago

I'd raise an issue on the Home Assistant Core repo, since this seems to be a bug of its own. Perhaps they will be able to help get to the bottom of your time zone not changing when set via the GUI.

RobertD502 commented 9 months ago

@Anian-igor

I am currently putting together a Timezone option for the configuration flow where you'll be able to select Europe/Kyiv as the timezone instead of relying on the tzlocal library to fetch the timezone from Home Assistant (which fails since tzlocal doesn't have Europe/Kyiv in its list of timezones). This way you won't have to change your timezone in Home Assistant and we don't have to wait on the tzlocal library maintaner to update his code.

Once the new version of this integration is released, update to it and you should see the option to select a timezone during setup.

Anian-igor commented 9 months ago

Ready to start testing ASAP. Thanks a lot

RobertD502 commented 9 months ago

@Anian-igor Upgrade to version 0.1.10 and select Europe/Kyiv as your timezone during the integration setup.