I’m trying to set up an ESP32 with a DS1307 RTC module.
The ESP32 will not have any other time source as no network is available. I’ve configured the ESP32 to act as an access point and I’ve enabled the web server so I can set some configuration items.
I’ve configured a datetime template where I can specify the current date and time. I would like to sync this user-provided value to the system clock (and RTC) so I can update the time this way. Once it’s set, the system should read the time from the RTC on boot. I can’t seem to find how to set the current system time to an explicit value, so I can then write it to the ds1307.
The DS1307 seems to be halted now. I assume that’s because no initial time has been configured on it?
Currently when the esp32 boots, it shows the following relevant lines:
[11:48:59][C][ds1307:013]: Setting up DS1307...
[11:49:00][D][ds1307:092]: Read 00:00:00 2000-01-01 CH:ON RS:3 SQWE:OFF OUT:OFF
[11:49:00][W][ds1307:037]: RTC halted, not syncing to system clock.
I have the following lines in my config regarding time:
Same issue for me. ESP32 with limited internet availability needs to be set manually.
I let the user enter date and time (global variables as int) via pushbuttons.
And then the magic should happen and the DS1307 should get the new date time.
There seems to be a bug in pr#7621 related to setting of the hour.
Here is my lambda code:
int hour = id(dt_hour).state;
ESP_LOGD("main", "hour is: %d", hour);
id(rtc_time).set_time(year, month, day, hour, minute, 0);
auto time = id(rtc_time).now();
id(current_time).publish_state(time.strftime("%Y-%m-%d / %H:%M"));
The log show hour is “N” but the time is set to “N-1”. Entering hour = 0 is ignored.
I am using a DS3231 but should be the same as DS1307 from a programming point of view.
I too have a webserver application that requires date and time independent of the internet.
I could create a custom component to write to the DS3231 registers but that should not be necessary.
I could just add one to hour but that seems like a hack.
I hope you notice that the example Esphome code has no connection to Home Assistant. The ESPHOME board synchronizes to ds1307 time on_boot with ds1307.readtime. I added a Home Assistant Wifi connection just to debug my code as the Wifi update is faster and it saves reconnecting to the WiFi access point on each iteration. After debug, the code is set to just Wifi AP access. By the way, do not use an ds1307 with a 3.3V ESP32 as it not reliable. Instead use the ds3231 with is designed to operate at 3.3V.
Yes, I noticed that the board has no connection with the server and does not receive time from it. I myself added part of the code to receive time from the home assistant.Thus, I checked how time behaves in esp32.When setting the time manually, everything works fine. If a connection with a home assistant appears at that time, the time zone is not taken into account.