cyprien
(cyprien)
March 7, 2023, 9:41am
1
Hello !
I use Time component with platform homeassistant to synchronize my esp clock like that
time:
- platform: homeassistant
id: homeassistant_time
I would like to use it with a precision of 0.1s or 0.05s. Can i do that ? How can i retrieve something like millis() arduino function ?
Here is the code i use in lambda
lambda: |-
ESP_LOGD("main", "Time %d", millis());
ESP_LOGD("main", "Time %d", id(homeassistant_time).now());
Thank you very much for your help.
cyprien
(cyprien)
March 7, 2023, 1:33pm
2
I reply the solution i’ve found.
Normaly, you can get a precision of few millisecond, that’s a lot enough for me
To retrive millis, i’ve used gettimeofday() function. I’ve test with two nodemcu and they are synchronised, i’m happy !
Here is my lambda code…
lambda: |-
ESP_LOGD("main", "Millis() %d", millis());
ESP_LOGD("main", "now() %d", id(homeassistant_time).now());
struct timeval tv;
gettimeofday(&tv, NULL);
ESP_LOGD("main", "tv_sec %ld", tv.tv_sec);
ESP_LOGD("main", "tv_usec %d", tv.tv_usec);