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

last_changed_seconds wrong due to timezone #1571

Closed
sander1988 opened this issue Sep 17, 2022 · 3 comments
Closed

last_changed_seconds wrong due to timezone #1571

sander1988 opened this issue Sep 17, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@sander1988
Copy link

I noticed that the last_changed_seconds property of an entity always is 7200 wrong. My timezone is +02:00 so this has to be a timezone issue.

It looks like 'now' isn't in UTC: https://github.com/AppDaemon/appdaemon/blob/4.2.1/appdaemon/entity.py#L575

I debugged the values during a state change trigger:

  • last_changed property of entity: 2022-09-17T12:39:58.203138+00:00
  • 'now' value at that time: 2022-09-17 12:39:58.219077+02:00 - There is no 'T' here, that's not a typo from my side.
  • last_changed_seconds value: -7199.982804
@sander1988
Copy link
Author

I use this a current workaround, it might help someone fixing it:

    def _convert_to_seconds_ago(self, last_changed) -> float:
        utc = iso8601.parse_date(last_changed)
        now = datetime.datetime.now(datetime.timezone.utc)
        return (now - utc).total_seconds()

@Odianosen25
Copy link
Collaborator

Thanks for reporting this @sander1988, we will look into it.

kind regards

@acockburn acockburn added the bug Something isn't working label Mar 3, 2023
@acockburn
Copy link
Member

This is fixed in 4.0.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants