-
Notifications
You must be signed in to change notification settings - Fork 66
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
tesla-history.py not pulling all data #455
Comments
Hi @lukemcguire - Does the host your are running have your timezone set correctly? There is code in the script to do the timezone calculation but it does use your localhost settings. It should be something like: $ timedatectl
Local time: Thu 2024-03-21 19:48:56 PDT
Universal time: Fri 2024-03-22 02:48:56 UTC
RTC time: Fri 2024-03-22 02:48:56
Time zone: America/Los_Angeles (PDT, -0700) |
Well, add $ date ; date -u
Fri Mar 22 09:26:35 AM PDT 2024
Fri Mar 22 04:26:35 PM UTC 20244 So that looks like the system time is ok. Is it possible that one of the containers isn't in the right time zone? I don't know if that's being handled in the script or not. Looking at the screenshot I provided, the data gap would be from 2023-06-26 17:00-23:59 PDT. However, based on the debug output that I provided, it says Is there something else I can check? |
I guess I should also note that I've run the weather-history tool and it is working just fine and is not returning gaps. |
These aren't running in containers, just scripts on your localhost. The weather history tool isn't using the Tesla Cloud API so it wouldn't be impacted by the timezone translation issues. One final thought, can you confirm your Tesla App shows the correct timezone selected? I'll flag this as a bug to look at. If you want to debug the code is here: https://github.com/jasonacox/Powerwall-Dashboard/blob/main/tools/tesla-history/tesla-history.py |
Yeah, it seems like it's the right time zone.
I'll probably take a look at the script, but my coding skills are pretty
rusty.
…On Fri, Mar 22, 2024, 20:57 Jason Cox ***@***.***> wrote:
These aren't running in containers, just scripts on your localhost. The
weather history tool isn't using the Tesla Cloud API so it wouldn't be
impacted by the timezone translation issues. One final thought, can you
confirm your Tesla App shows the correct timezone selected?
I'll flag this as a bug to look at. If you want to debug the code is here:
https://github.com/jasonacox/Powerwall-Dashboard/blob/main/tools/tesla-history/tesla-history.py
—
Reply to this email directly, view it on GitHub
<#455 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJ4OQKLNWUMAKKTDDYSGUDYZT4Q3AVCNFSM6AAAAABFB2HNSCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMJWGMZTIOJUGA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Hi @lukemcguire - there seems to be some issue detecting your local timezone correctly when interpreting the The giveaway is below - for the period of history data being retrieved, it should show correctly your timezone offset in the timestamps (i.e -07:00), but it does not.
It's possibly more of a system compatibility issue rather than a bug in the script. Synology NAS (and NAS systems in general) seem to be a problem. There's an easy workaround. You can actually specify full formed timestamps including the offset with the i.e. try this instead (add your timezone offset after the times): python3 tesla-history.py --start "2023-06-26 00:00:00-07:00" --end "2023-06-27 23:59:59-07:00" Hopefully that would work for you. Let us know how it goes. |
Interesting idea, but unfortunately still no joy.
|
What is your TZ value set to in your tesla-history.conf file? Can you post a copy of the config file. |
Here you go. Renamed so that Github allows posting. |
This is so odd. I have a test system that has a lot of gaps. I found a good 5 day gap:
It filled in the full days... here is where it filled in the gap to the recorded data (the weather data shows the gap): @lukemcguire do you have another system that could be used to run the script? You would just edit the conf file to point to the IP address of your Dashboard host (for Influxdb). |
Agreed - really odd. There has to be in issue getting timezones correctly on this system. The start/end period shown makes no sense to me. The times should be shown in the configured InfluxDB timezone, with an offset - like "2023-06-26 00:00:00-07:00" - not +00 as below.
Also, it was mentioned the weather-history tool was fine, but that script must show the same problem. It uses the same python modules to get timezones etc. @lukemcguire - can you run the weather-history script and show the output from the first few lines? Does it output exactly like below when using command
Not sure how else to work out where the issue is.... could the host system be missing tzdata? Perhaps try this please. Run python and paste all of the below commands in the python shell. from dateutil.parser import isoparse
from dateutil import tz
start = isoparse("2023-06-26 00:00:00")
start
print(start)
type(start)
type(start.utcoffset())
influxtz = tz.gettz("America/Los_Angeles")
influxtz
print(influxtz)
type(influxtz)
start = start.replace(tzinfo=influxtz)
start
print(start)
type(start)
type(start.utcoffset())
utctz = tz.tzutc()
utctz
print(utctz)
type(utctz)
startutc = start.astimezone(utctz)
startutc
print(startutc)
type(startutc)
type(startutc.utcoffset())
startlocal = start.astimezone(influxtz)
startlocal
print(startlocal)
type(startlocal)
type(startlocal.utcoffset()) Then, what does the output show? Something must be off with one of these. i.e. I get below:
|
Huh... good catch @mcbirse. I didn't notice that the timezone call was basically giving +07 instead of -07. Something's clearly cracker jacks. Weather History ToolFirst, let's take a look at the weather-history tool.
It doesn't appear to be getting the timezone data correctly either so I'm not sure why that's working when the tesla-history tool isn't. I can see that the Python ShellHere's the output from the python shell
It's clearly doing something different from your installation and it looks like it's breaking around the Solution?However, I was able to get some progress here thanks to the suggestion from @jasonacox .
Yes, I was able to run the script from a laptop and sure enough, it found the data gaps and was able to import the data.
So, while I can get my data imported, the script still isn't working when run on the NAS. 🤷 |
Thanks for testing and sorry for late reply! So to me this does not appear to be an bug with the script, but more of an issue with either the host system (Synology NAS) and/or the python dateutil module. What's the deal with the timezone files on Synology NAS? python dateutil is interpreting the below as UTC, and not the timezone specified.
Above should show the offset as -07:00 if it was working correctly. Can you run the below test on your Synology NAS system and see what is returned? This is using the built-in zoneinfo module (available since python 3.9), instead of dateutil. from dateutil.parser import isoparse
from zoneinfo import ZoneInfo
start = isoparse("2023-06-26 00:00:00")
start
print(start)
influxtz = ZoneInfo("America/Los_Angeles")
influxtz
print(influxtz)
type(influxtz)
start = start.replace(tzinfo=influxtz)
start
print(start) |
It looks like this might resolve the issue. $ python3
Python 3.9.14 (main, Mar 24 2023, 10:04:27)
[GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from dateutil.parser import isoparse
>>> from zoneinfo import ZoneInfo
>>>
>>> start = isoparse("2023-06-26 00:00:00")
>>> start
datetime.datetime(2023, 6, 26, 0, 0)
>>> print(start)
2023-06-26 00:00:00
>>>
>>> influxtz = ZoneInfo("America/Los_Angeles")
>>> influxtz
zoneinfo.ZoneInfo(key='America/Los_Angeles')
>>> print(influxtz)
America/Los_Angeles
>>> type(influxtz)
<class 'zoneinfo.ZoneInfo'>
>>>
>>> start = start.replace(tzinfo=influxtz)
>>> start
datetime.datetime(2023, 6, 26, 0, 0, tzinfo=zoneinfo.ZoneInfo(key='America/Los_Angeles'))
>>> print(start)
2023-06-26 00:00:00-07:00 |
@lukemcguire I gave up trying to get the history tools working on my DS1621+ and just fired up an Ubuntu Server VM instead. Aside from Ubuntu breaking some of the PIP install instructions, it's been smooth sailing to get everything running. |
Problem
When running the tesla-history import tool not all of the data is being imported to the database. Specifically, the end of each day is missing data. When running the tool it'll find the data gap but it won't
To Reproduce
Please paste a screenshot or steps to reproduce the behavior:
Here's the output of the same command with --debug flag - debug.txt
Screenshots
Host System
Additional context
I think it may be something to do with time zones since it appears to not pull the last 7 hours of each day and I'm in tz America/Los_Angeles. Looking through the debug output it seems that it finds the gap but when it tries to pull the data it's pulling from the wrong time window.
The text was updated successfully, but these errors were encountered: