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

TZ environment variable name confusion #3678

Closed
JakobLichterfeld opened this issue Feb 15, 2024 · 25 comments
Closed

TZ environment variable name confusion #3678

JakobLichterfeld opened this issue Feb 15, 2024 · 25 comments
Labels
Stale undetermined Not sure if this is considered a real bug

Comments

@JakobLichterfeld
Copy link
Collaborator

JakobLichterfeld commented Feb 15, 2024

I don't know why or how your reply explains my confusion. The fact is using "TZ=" was not enough but instead a line with "TM_TZ=" works yet is not in the documentation written as "TM_TZ=". Am I just missing something that should be "obvious"?

Originally posted by @TSJasonH in #3651 (comment)

@JakobLichterfeld
Copy link
Collaborator Author

@TSJasonH please share your docker-compose file (without your secrets). The name of the environment variable is TZwithout any TM_

@TSJasonH
Copy link

sure...

version: "3"

services:
  teslamate:
    image: teslamate/teslamate:latest
    restart: always
    environment:
      - ENCRYPTION_KEY=*redacted*
      - DATABASE_USER=teslamate
      - DATABASE_PASS=*redacted*
      - DATABASE_NAME=teslamate
      - DATABASE_HOST=database
      - MQTT_HOST=mosquitto
      - TZ="America/Indiana/Indianapolis"      
      - TM_TZ="America/Indiana/Indianapolis"   
    ports:
      - 4000:4000
    volumes:
      - ./import:/opt/app/import
    cap_drop:
      - all

  database:
    image: postgres:13
    restart: always
    environment:
      - POSTGRES_USER=teslamate
      - POSTGRES_PASSWORD=*redacted*
      - POSTGRES_DB=teslamate
    volumes:
      - teslamate-db:/var/lib/postgresql/data  

  grafana:
    image: teslamate/grafana:latest
    restart: always
    environment:
      - DATABASE_USER=teslamate
      - DATABASE_PASS=*redacted*
      - DATABASE_NAME=teslamate
      - DATABASE_HOST=database
    ports:
      - 3000:3000
    volumes:
      - teslamate-grafana-data:/var/lib/grafana

  mosquitto:
    image: eclipse-mosquitto:2
    restart: always
    command: mosquitto -c /mosquitto-no-auth.conf
    # ports:
    #   - 1883:1883
    volumes:
      - mosquitto-conf:/mosquitto/config
      - mosquitto-data:/mosquitto/data

volumes:
  teslamate-db:
  teslamate-grafana-data:
  mosquitto-conf:
  mosquitto-data:

@brianmay
Copy link
Collaborator

brianmay commented Feb 15, 2024

Random thought: I would like to be able to see the current timezone that is in use when the car is not charging. Maybe something to print the last refresh date/time in the live view or something like that would be a good idea. This probably would help debug this issue as well.

@maxhac03
Copy link

Been using TM_TZ in the .env file since 2019. Both TeslaMate and Grafana reported the correct time since.

Here the instruction for the .env file does mention TM_TZ:
https://docs.teslamate.org/docs/guides/traefik

All i did was change the zone and kept the same variable to fix the issue.

Screenshot_20240215-180146
screenshot 21
screenshot 22

@brianmay
Copy link
Collaborator

Note the referenced instructions set TZ=${TM_TZ} in the docker-compose file.

So doing in this way makes sense. TeslaMate is reading the TZ value, which is set from the TM_TZ value.

But there is nothing in TeslaMate - that I am aware of - that reads the TM_TZ environment variable directly.

The docker-compose file quoted above does not have the TZ=${TM_TZ} line.

@touchton
Copy link

Just to add another data point, my .yml file has the following:
TZ=America/Chicago

Nothing about TM_TZ in the file at all. I'm not having a problem; time is being displayed correctly in both the Teslamate page and Grafana pages.

I don't know if this information helps or hurts... I'm running the container locally in a Photon VM on an ESX host.

@cwanja
Copy link
Collaborator

cwanja commented Feb 16, 2024

For what it is worth, a user on TMC changed the variable from TZ to TM_TZ and their internal server error on TeslaMate webpage during charging went away.
https://teslamotorsclub.com/tmc/threads/teslamate-megathread.191537/page-164#post-8088719

@brianmay
Copy link
Collaborator

That does make sense. If TZ is wrong, then TeslaMate will see it and this will create the error. If TM_TZ is wrong, it doesn't matter, TeslaMate won't look at that and continue working using whatever the system default timezone is.

@JakobLichterfeld
Copy link
Collaborator Author

JakobLichterfeld commented Feb 16, 2024

database:
image: postgres:13
restart: always
environment:
- POSTGRES_USER=teslamate
- POSTGRES_PASSWORD=redacted
- POSTGRES_DB=teslamate
volumes:
- teslamate-db:/var/lib/postgresql/data

Even if it is not related to the issue here, you need to update your postgres database container, please do a backup and follow https://docs.teslamate.org/docs/maintenance/upgrading_postgres

@JakobLichterfeld
Copy link
Collaborator Author

JakobLichterfeld commented Feb 16, 2024

  • TZ="America/Indiana/Indianapolis"

The issue are the ". Please remove the unneeded TM_TZ and replace with - TZ=America/Indiana/Indianapolis in your case

@TSJasonH
Copy link

Looks good. Quotes...who knew :-/

Also thanks for the db upgrade tip. Completed the upgrade to pg 15 smoothly with the provided instructions.

@JakobLichterfeld
Copy link
Collaborator Author

JakobLichterfeld commented Feb 16, 2024

Looks good. Quotes...who knew :-/

So issue is resolved with only TZ=... correct?

@JakobLichterfeld JakobLichterfeld added the undetermined Not sure if this is considered a real bug label Feb 16, 2024
@Olyts
Copy link

Olyts commented Feb 16, 2024

The issue was fixed when I replaced to TZ by TM_TZ. As mentioned by @cwanja Now the web page is coming up while charging (no more 500 server error), but the time is 5.5 hours off. Although my TZ is set to America/Toronto? Grafana info is spot on about drive time and charge time, it is not just not showing up right on the Teslamate homepage.(+5,5 hours), As an example, at an expected local 8h15 finish time, it was showing 13h45. I’m not worried much, just want to report here.

@brianmay
Copy link
Collaborator

I think it might help if the time displayed the timezone offset, that would help verify that the timezone is correct.

@ampersandru
Copy link

was getting internal server errors, tried TM_TZ and it still didnt fix it.

Rolled back to teslamate/teslamate:1.28.2 and its working fine again with just the TZ env

@JakobLichterfeld
Copy link
Collaborator Author

was getting internal server errors,

If you ask for help, please share your docker-compose (without credentials)

@brianmay
Copy link
Collaborator

I kind of think we need to be able display configuration errors - such as invalid TZ - somewhere on the website. Which in turn means the website shouldn't crash if it is invalid, but maybe resort to some sort of fallback behaviour.

The idea of looking at the logs - is a sensible one - but I think our users who are not programmers can struggle with this. So maybe we need to try to simplify the errors as much as possible and make them accessible by putting them on the website, where everyone can see them without needing to learn about logs.

It doesn't help when the invalid TZ only error only happens when the car is charging either. Perhaps we should be trying to load the timezone at startup.

@JakobLichterfeld
Copy link
Collaborator Author

Total agree. Not only valid for TZ

@ampersandru
Copy link

was getting internal server errors,

If you ask for help, please share your docker-compose (without credentials)

This is the docker-compose i used a couple years ago initially, but have been using watchtower to update the stack

version: "3"

services:
  teslamate:
    image: teslamate/teslamate:latest
    restart: always
    environment:
      - PUID=1000
      - PGID=100
      - TZ=America/Los_angeles
      - ENCRYPTION_KEY=ABCDefg
      - DATABASE_USER=teslamate
      - DATABASE_PASS=secret
      - DATABASE_NAME=teslamate
      - DATABASE_HOST=database
      - MQTT_HOST=192.168.29.234
      - MQTT_PORT=1883
    ports:
      - 4000:4000
    volumes:
      - /volume2/docker/teslamate/import:/opt/app/import
    cap_drop:
      - all

  database:
    image: postgres:14
    restart: always
    environment:
      - PUID=1028
      - PGID=100
      - TZ=America/Los_angeles    
      - POSTGRES_USER=teslamate
      - POSTGRES_PASSWORD=secret
      - POSTGRES_DB=teslamate
    volumes:
      - teslamate-db:/volume2/docker/teslamate/postgresql

  grafana:
    image: teslamate/grafana:latest
    restart: always
    environment:
      - PUID=1028
      - PGID=100
      - TZ=America/Los_angeles    
      - DATABASE_USER=teslamate
      - DATABASE_PASS=secret
      - DATABASE_NAME=teslamate
      - DATABASE_HOST=database
    ports:
      - 3000:3000
    volumes:
      - teslamate-grafana-data:/volume2/docker/grafana

volumes:
  teslamate-db:
  teslamate-grafana-data:


@Olyts
Copy link

Olyts commented Mar 1, 2024

Just pulled a pulled some "updated" version of 1.2.8.3 (Teslamate and Database have been downloaded) and now the time to finish is accordingly to my TZ ! All is good now!

@JakobLichterfeld
Copy link
Collaborator Author

TZ=America/Los_angeles

This needs to be America/Los_Angeles in your case (So Angeles)
TZ Environment Variable is only needed in teslamate section, not in database nor in grafana

database:
image: postgres:14
restart: always
environment:
- PUID=1028
- PGID=100
- TZ=America/Los_angeles
- POSTGRES_USER=teslamate
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=teslamate
volumes:
- teslamate-db:/volume2/docker/teslamate/postgresql

Even if it is not related to the issue here, you need to update your postgres database container, please do a backup and follow https://docs.teslamate.org/docs/maintenance/upgrading_postgres

@ampersandru
Copy link

This needs to be America/Los_Angeles in your case (So Angeles)

Thanks, I did spot that and had updated my container, but it did still get the internal server error. I'll try updating again and trying again -also will try updating postgres

@towster
Copy link

towster commented Mar 28, 2024

I installed teslamate for the first time last week and followed the docker installation guide and using the example docker-compose.yml. I was having issues with the timestamps for my drives being hours off so I added the TZ variable into the compose and updated. Now my drives are the correct time. The TZ setting should be added to the installation docs.

@JakobLichterfeld
Copy link
Collaborator Author

I was having issues with the timestamps for my drives being hours off so I added the TZ variable into the compose and updated. Now my drives are the correct time. The TZ setting should be added to the installation docs.

Where were your timestaps off? Grafana use your local browser settings for displaying.

Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale label Apr 28, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale undetermined Not sure if this is considered a real bug
Projects
None yet
Development

No branches or pull requests

9 participants