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

Sync time sets the time one hour ahead #307

Open
AndreiArdelean1 opened this issue Apr 8, 2023 · 18 comments
Open

Sync time sets the time one hour ahead #307

AndreiArdelean1 opened this issue Apr 8, 2023 · 18 comments
Labels
Bug Something isn't working

Comments

@AndreiArdelean1
Copy link

AndreiArdelean1 commented Apr 8, 2023

Description

When enabling automatic time sync or tapping the sync time button, the time on the camera is set to one hour ahead. This is most likely caused by "Hour": now.hour if time.localtime().tm_isdst == 0 else now.hour + 1. When looking around the calls, I've noticed that the camera already has DST parameters.

Calling:
{"method":"multipleRequest","params":{"requests":[{"method":"getClockStatus","params":{"system":{"name":"clock_status"}}},{"method":"getDstRule","params":{"system":{"name":"dst"}}},{"method":"getTimezone","params":{"system":{"name":["basic"]}}}]}}

Returns:
{'result': {'responses': [{'method': 'getClockStatus', 'result': {'system': {'clock_status': {'seconds_from_1970': 1682072995, 'local_time': '2023-04-21 13:29:55'}}}, 'error_code': 0}, {'method': 'getDstRule', 'result': {'system': {'dst': {'enabled': '1', 'synced': '1', 'has_rule': '1', 'dst_rule': 'DST-03:00,M3.5.0/03:00:00,M10.5.0/04:00:00'}}}, 'error_code': 0}, {'method': 'getTimezone', 'result': {'system': {'basic': {'timing_mode': 'ntp', 'zone_id': 'Europe/Athens', 'timezone': 'UTC+02:00'}}}, 'error_code': 0}]}, 'error_code': 0}

Reproduction Steps

Tap Sync Time button

Expected behavior

Sync to the current time

If applicable, add error logs.

No response

Device Firmware

C225 v1 1.0.17 Build 230222 Rel.34031n

Using stream component

Yes

Does camera work via official integrations?

Yes

Camera has all attributes filled out in developer tools

Yes

HASS Environment

Docker

Search for similar issues

Yes

Additional information

The one hour adjustment may still be needed on some cameras, but on c225 it seems to introduce an extra hour.

@thomasramm
Copy link

i run into the same problem on C320WS.
Also, after HA set the wrong time, there is no longer a motion detection in the app.
After disable time setting from HA and set the correct time on Cam, i get the motion detection back in the app.
On cam i have enabled diagonstic, this is the log (Power off the cam at 11:38 to copy log file):

<4>2023-04-21 11:28:14[MD_ALARM]MD end
<4>2023-04-21 12:28:33[SYSTEM]System time is calibrated by user from App/web/NVR.
<4>2023-04-21 12:28:33[SNTPC]Set timing mode to MANUAL
<4>2023-04-21 12:28:33[STM]record_plan new rec type:(null)
<4>2023-04-21 12:29:15[HSR]HSR start
<4>2023-04-21 12:29:15[AMS] PD start
<4>2023-04-21 12:29:15[MD_ALARM]MD start

In HA everything looks correct, i can't see the wrong cam time in the frontend, only in the cam diagnostics.

@JurajNyiri JurajNyiri added the Bug Something isn't working label Aug 20, 2023
@JurajNyiri
Copy link
Owner

Is this still an issue?

@FeikoJoosten
Copy link

I'm having the same issue with my C225 camera. Syncing through the tapo app results in the correct time, but syncing through home assistant results in an 1 hour offset where the camera is 1 hour ahead

@fortellerq
Copy link

fortellerq commented May 29, 2024

@JurajNyiri Yes, the issue is still there. I tried to play with it a little and I don't seem to be able to set correct time on my camera using built-in time-sync option:

Current time: 22:00
Current TZ: TZ=Europe/Warsaw

Application TZ: Europe/Brussels (or any other UTC+01:00 TZ)
Sync via app: 22:00
Sync via Home Assistant: 23:00

Application TZ: UTC
Sync via app: 20:00
Sync via Home Assistant: 21:00

Application TZ: UTC (or any other UTC-00:00 TZ)
Sync via app: 20:00
Sync via Home Assistant: 21:00

Camera: Tapo C220
Revision: v1
FW: 1.1.9 240223

@ReTaec
Copy link

ReTaec commented Jun 5, 2024

Tapo C320WS has the same issue. When it is connected to Home Assistant, the time is 1h ahead of the actual time
Current time: 12:00
Current TZ: TZ=Europe/Brussels

Change timezone in Tapo Application to: Europe/Amsterdam (or any other UTC+01:00 TZ)
Sync via app: 12:00
Sync via Home Assistant: 13:00

Maybe an issue with daylight saving time?

Camera: Tapo C320WS
Hardware-Version: 2.0
Firmware: 1.1.8 231211

@CaptInsano
Copy link

Came here to report a similar issue, but my Tapo C210 gets set 1 hour behind rather then ahead:

Tapo C210,
TZ: Europe/Dublin

Internet access blocked due to current issues on newest firmware documented here:
Due to internet blockage, no access to NTP server, need to syn via HomeAssistant.

Home Assistant Time (correct):
HA Time

TapoCam after clicking "Sync Time" (1 hour behind):
CamTime

Any help would be much appreciated!

Thanks so much for your continued hard work on this brilliant integration

@xmikos
Copy link

xmikos commented Sep 6, 2024

@JurajNyiri I can also confirm this is still an issue. It is caused by this line:

"Hour": now.hour if time.localtime().tm_isdst == 0 else now.hour + 1,

Clearly that DST logic is wrong. If I remove if time.localtime().tm_isdst == 0 else now.hour + 1 condition (just leave it at now.hour), it works as expected, time is synchronized right (I am in CET timezone).

Could you please fix it?

@CaptInsano
Copy link

@xmikos thanks for pointing me in the right direction:

I had to edit it differently than you for it to work for me:

image

It looks like the logic has an issue in this area of the code?

TZ: Europe/Dublin:
image

With the above edit to HomeAssistant-Tapo-Control/custom_components/tapo_control/utils.py the time now syncs correctly from home assistant to tapo cams.

image

@CaptInsano
Copy link

@JurajNyiri
Any ideas of implementing a fix for this if we are to keep the devices isolated from WAN?
WAN isolation recommended due to: #551

Thanks so much for your work on this integration.

@JurajNyiri
Copy link
Owner

I hope I will get to it soon, but I've been very busy in work lately so I have very little time left. For now I would suggest changing the hour in the source code by adding an hour, or substracting it.

Any PRs are welcomed as well, but we need to make sure it works well for all the timezones (and time savings) as there was a similar ticket in the past where it was one hour less.

@chatziko
Copy link

Just a quick note that the recent addition of a select.*_timezone entity in 5.6.3 seems to fix this issue for me. After setting a timezone, sync now works fine (it previously was setting the time 1 hour ahead).

Note that in my C320WS, after upgrading to 5.6.3, sync initially did not work although the timezone in select.*_timezone was the correct one. I had to change the timezone to something else, and then back to the correct one, and after that it worked. I cannot reproduce this behaviour any more so I'm not sure what happened, now sync always works, even after a reboot, without touching the timezone anymore.

@yoali11
Copy link

yoali11 commented Oct 18, 2024

I have three C320WS cameras all with same firmware:
Firmware: 1.1.15 Build 240605 Rel.49436n
Hardware: 2.0

Two of them shows the wrong time (one hour ahead) and one of them the correct one. Unfortunately the timezone select doesn't help fixing the timezone. I followed the suggestion from above by changing the timezone back and forth without luck.

@JurajNyiri
Copy link
Owner

JurajNyiri commented Oct 28, 2024

To move this issue forwards please post following template, below would be an example.

My Timezone: GMT+1
Is it currently summer time?: No
Sync time works: Yes
Camera Timezone: UTC+01:00 (Europe/Belgrade)
Home Assistant timezone (Find at /config/general): (GMT+01:00) Berlin
Real time when button clicked: 13:29
Camera was set to: 13:29

*** this is just an example and not an exact data set, it should be ignored from evaluation as my setup actually does not support time sync at all due to https.

@fortellerq
Copy link

Dwo days ago summer time has ended, and that problem seems to be related to DST.

@CaptInsano
Copy link

@JurajNyiri as requested:

My Timezone: UTC+0 (Dublin, Ireland)
Is it currently summer time?: No (ended 2 days ago)
Sync time works: No
Camera Timezone:  UTC-00:00 (in Tapo integration settings)
Home Assistant timezone (Find at /config/general): (GMT+00:00) Dublin
Real time when button clicked: 08:46
Camera was set to: 09:46

@JurajNyiri
Copy link
Owner

JurajNyiri commented Nov 12, 2024

Thank you @CaptInsano that was helpful.

Here is what I tried.

  1. Set my HA instance to (GMT+00:00) Dublin
  2. Set my camera to UTC-00:00
  3. Pushed button

This was the request to camera:

2024-11-12 12:05:36.978 WARNING (MainThread) [custom_components.tapo_control] {
    'DateTimeType': 'Manual',
    'DaylightSavings': True,
    'TimeZone': None,
    'UTCDateTime': {
        'Date': {
            'Year': 2024,
            'Month': 11,
            'Day': 12
        },
        'Time': {
            'Hour': 12,
            'Minute': 5,
            'Second': 36
        }
    }
}

I checked the time, and it is set correctly - it was 12:05.36 in Dublin.

I tried playing with DaylightSavings setting it to True, or False and it has no effect on my camera. This is very strange.

As a next step, please download https://github.com/JurajNyiri/HomeAssistant-Tapo-Control/tree/time_sync_debug manually. You should see a bunch of warning logs like this.

2024-11-12 12:13:51.023 WARNING (MainThread) [custom_components.tapo_control] async_update_data - entry
2024-11-12 12:13:51.025 WARNING (MainThread) [custom_components.tapo_control] Motion sensor or time sync is enabled.
2024-11-12 12:13:51.026 WARNING (MainThread) [custom_components.tapo_control] Setting up subscription to motion sensor...
2024-11-12 12:13:51.498 WARNING (MainThread) [custom_components.tapo_control] {'device': <onvif.client.ONVIFCamera object at 0xffff631c8f80>, 'device_mgmt': <onvif.client.ONVIFService object at 0xffff631377d0>}
2024-11-12 12:13:51.498 WARNING (MainThread) [custom_components.tapo_control] setupOnvif - entry
2024-11-12 12:13:51.498 WARNING (MainThread) [custom_components.tapo_control] Setting up onvif...
2024-11-12 12:13:51.498 WARNING (MainThread) [custom_components.tapo_control] setupEvents - entry
2024-11-12 12:13:51.499 WARNING (MainThread) [custom_components.tapo_control] Using HTTPS: False
2024-11-12 12:13:51.499 WARNING (MainThread) [custom_components.tapo_control] Webhook enabled: False
2024-11-12 12:13:51.499 WARNING (MainThread) [custom_components.tapo_control] Using Webhooks: False
2024-11-12 12:13:51.499 WARNING (MainThread) [custom_components.tapo_control] Setting up events...
2024-11-12 12:13:51.499 WARNING (MainThread) [custom_components.tapo_control] WSPullPointSupport: True
2024-11-12 12:13:51.612 WARNING (MainThread) [custom_components.tapo_control] Events started.
2024-11-12 12:13:56.219 WARNING (MainThread) [custom_components.tapo_control] TEST
2024-11-12 12:13:56.219 WARNING (MainThread) [custom_components.tapo_control] OK
2024-11-12 12:13:56.219 WARNING (MainThread) [custom_components.tapo_control] Syncing time for 01J382AJT3XRYGYPDCE6TPNWR9...
2024-11-12 12:13:56.219 WARNING (MainThread) [custom_components.tapo_control] Is DST: 0
2024-11-12 12:13:56.220 WARNING (MainThread) [custom_components.tapo_control] {
    'DateTimeType': 'Manual',
    'DaylightSavings': True,
    'TimeZone': None,
    'UTCDateTime': {
        'Date': {
            'Year': 2024,
            'Month': 11,
            'Day': 12
        },
        'Time': {
            'Hour': 12,
            'Minute': 13,
            'Second': 56
        }
    }
}

Please post them here.

@JurajNyiri
Copy link
Owner

I have added additional properties to button.guest_room_sync_time entity.

Screenshot 2024-11-12 at 13 56 40

Please post those as well on the latest code at https://github.com/JurajNyiri/HomeAssistant-Tapo-Control/tree/time_sync_debug (install manually).

@JurajNyiri
Copy link
Owner

JurajNyiri commented Nov 12, 2024

And finally I also added another warning log,
Screenshot 2024-11-12 at 14 02 50
Please post that as well.

So in the end, your report should look something like this:

2024-11-12 13:02:33.135 WARNING (MainThread) [custom_components.tapo_control] Timezone offset is -2.135672092437744.
2024-11-12 13:03:03.168 WARNING (MainThread) [custom_components.tapo_control] async_update_data - entry
2024-11-12 13:03:03.169 WARNING (MainThread) [custom_components.tapo_control] Motion sensor or time sync is enabled.
2024-11-12 13:03:03.170 WARNING (MainThread) [custom_components.tapo_control] Setting up subscription to motion sensor...
2024-11-12 13:03:03.306 WARNING (MainThread) [custom_components.tapo_control] {'device': <onvif.client.ONVIFCamera object at 0xffff89f63f80>, 'device_mgmt': <onvif.client.ONVIFService object at 0xffff8a2dc9b0>}
2024-11-12 13:03:03.306 WARNING (MainThread) [custom_components.tapo_control] setupOnvif - entry
2024-11-12 13:03:03.306 WARNING (MainThread) [custom_components.tapo_control] Setting up onvif...
2024-11-12 13:03:03.306 WARNING (MainThread) [custom_components.tapo_control] setupEvents - entry
2024-11-12 13:03:03.307 WARNING (MainThread) [custom_components.tapo_control] Using HTTPS: False
2024-11-12 13:03:03.307 WARNING (MainThread) [custom_components.tapo_control] Webhook enabled: False
2024-11-12 13:03:03.307 WARNING (MainThread) [custom_components.tapo_control] Using Webhooks: False
2024-11-12 13:03:03.307 WARNING (MainThread) [custom_components.tapo_control] Setting up events...
2024-11-12 13:03:03.307 WARNING (MainThread) [custom_components.tapo_control] WSPullPointSupport: True
2024-11-12 13:03:03.400 WARNING (MainThread) [custom_components.tapo_control] Events started.
2024-11-12 13:03:03.400 WARNING (MainThread) [custom_components.tapo_control] TEST
2024-11-12 13:03:03.400 WARNING (MainThread) [custom_components.tapo_control] OK
2024-11-12 13:03:03.400 WARNING (MainThread) [custom_components.tapo_control] Syncing time for 01J37Y1GR2PQ236CDJ6X7C6E60...
2024-11-12 13:03:03.400 WARNING (MainThread) [custom_components.tapo_control] Is DST: 0
2024-11-12 13:03:03.400 WARNING (MainThread) [custom_components.tapo_control] {
    'DateTimeType': 'Manual',
    'DaylightSavings': False,
    'TimeZone': None,
    'UTCDateTime': {
        'Date': {
            'Year': 2024,
            'Month': 11,
            'Day': 12
        },
        'Time': {
            'Hour': 13,
            'Minute': 3,
            'Second': 3
        }
    }
}
Screenshot 2024-11-12 at 14 05 09

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

10 participants