klali / ha-plejd

Plejd component for Home Assistant
Apache License 2.0
69 stars 16 forks source link

Time zone setting needed #45

Closed bnordli closed 3 years ago

bnordli commented 3 years ago

After connecting this component to my Plejd system, I noticed that the time functions started to behave strangely. I added debug logging and saw this:

2021-06-09 08:09:18 DEBUG (MainThread) [custom_components.plejd.light] Plejd network reports time as '2021-06-09 09:09:20'
2021-06-09 08:09:18 INFO (MainThread) [custom_components.plejd.light] Plejd time delta is 3601 seconds, setting time to '2021-06-09 08:09:18.441121'.

After reconnecting with the app, it resynchronizes the devices and the component logs the following. (I have removed the message details.)

2021-06-09 08:22:04 DEBUG (MainThread) [custom_components.plejd.light] No match for command 'b'001b'' (b'**')
2021-06-09 08:22:04 DEBUG (MainThread) [custom_components.plejd.light] No match for command 'b'001b'' (b'**')
2021-06-09 08:22:04 DEBUG (MainThread) [custom_components.plejd.light] No match for command 'b'0038'' (b'**')
2021-06-09 08:22:04 DEBUG (MainThread) [custom_components.plejd.light] No match for device '00' (b'**')
2021-06-09 08:22:04 DEBUG (MainThread) [custom_components.plejd.light] No match for command 'b'001b'' (b'**')
2021-06-09 08:22:05 DEBUG (MainThread) [custom_components.plejd.light] No match for device '00' (b'**')

..and then of course the component reports again:

2021-06-09 08:25:43 DEBUG (MainThread) [custom_components.plejd.light] Plejd network reports time as '2021-06-09 09:25:46'
2021-06-09 08:25:43 INFO (MainThread) [custom_components.plejd.light] Plejd time delta is 3602 seconds, setting time to '2021-06-09 08:25:43.909139'.

I am at UTC+2, but it looks like Plejd is reporting time in UTC +3 (!). The timers from my app worked correctly before I attached Home Assistant, so at least it is internally consistent.

Suggested solution: If possible, read the time zone information from Plejd, otherwise add a time zone (or offset) setting to the component to avoid setting the wrong clock.

klali commented 3 years ago

Interesting, mine just did the same thing. I guess it might be a conflict with winter/summer time or such.

bnordli commented 3 years ago

It's a little strange, because Swedish/Norwegian summer time is UTC+2 while winter time is UTC+1, so UTC+3 seems like a bug in the Plejd software.

This line fixes the problem for me, at least during summer hours:

n = n + timedelta(minutes=60)

I guess we have to wait some months to see what the Plejd system does during winter time, but I think a config setting (minutes_offset) would be handy for those not wanting to change the code.

klali commented 3 years ago

So for me the current code worked during winter, and now it logs:

2021-06-09 08:06:34 DEBUG (MainThread) [custom_components.plejd.light] Plejd network reports time as '2021-06-09 09:06:33'
2021-06-09 08:06:34 INFO (MainThread) [custom_components.plejd.light] Plejd time delta is 3601 seconds, setting time to '2021-06-09 10:06:34.199084'.

An interesting difference is that my system time runs on UTC, but the offset from plejd time is what's interesting I guess. For me plejd ran on local time during winter, and now 1h after apparently. I'll look into this a bit and try to think of something that doesn't require more settings.. :)

bnordli commented 2 years ago

FYI: After the time zone switch, I didn't need to to anything (!). My Plejd system is still reporting time to be 60 minutes off.

klali commented 2 years ago

Interesting (annoying?).

My system changes to now not be offset at all from swedish winter time. I wonder if it's worth keeping the time code around at all if it's this inconsistent, it's not really needed for anything when you connect it with home assistant anyways.

bnordli commented 2 years ago

(It's not annoying to me, as I can keep the offset at +60 mins throughout the year.) I would like to keep the time syncing feature, possibly making it optional.

Rationale: I use Plejd's time feature to trigger scenarios, and it is very handy that HA makes sure its time is correct. Yes, with #54, I can also trigger Plejd scenarios from HA, but I guess some people still want to use Plejd to setup astro/time triggers.

klali commented 2 years ago

Fair enough.. it doesn't disturb me at all that it gets my time wrong half the year since I don't use the app or time at all.