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

uptime doesn't take TZ into account #183

Open
dikt1338 opened this issue Dec 30, 2024 · 0 comments
Open

uptime doesn't take TZ into account #183

dikt1338 opened this issue Dec 30, 2024 · 0 comments

Comments

@dikt1338
Copy link

dikt1338 commented Dec 30, 2024

I figured, that the "uptime sensor" uses uptime -s but later adds "Z" (=Zulu =CET) to the timestamp value before sending via mqtt.
According to my testing this leads to wrong values as uptime -s is always local (sorry can't find a man entry to prove that. This is according to some blog posts I found and is confirmed by my own tests)

I changed the script like that - maybe this could be considered for further releases?

def check_uptime(format):
    if format == 'timestamp':
        full_cmd = "uptime -s"
        tz_cmd = "date +%z"
        tz_str = subprocess.Popen(tz_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0].decode('utf-8').strip()**
        timestamp_str = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0].decode('utf-8').strip()
        timestamp = datetime.strptime(timestamp_str, '%Y-%m-%d %H:%M:%S')
        iso_timestamp = timestamp.isoformat() + tz_str  # Append correct offset to indicate `local` time

Basically, I use
data +%z
to get the time zone offset of the current installation to send the correct timestamp

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

No branches or pull requests

1 participant