Set DS1307 time to specific value

Hi,

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:

esphome:
  name: moemoe
  platform: ESP32
  board: esp32doit-devkit-v1

logger:
  level: DEBUG

wifi:
  ap:
    ssid: 'My ESP32'
    password: 'secret'
    ap_timeout: 10s

i2c:
  sda: GPIO21
  scl: GPIO22
  scan: true
  id: i2c_bus

time:
  - platform: ds1307
    id: ds1307_time
    timezone: Europe/Brussels
    on_time_sync:
      then:
        - logger.log: "DS1307 time synchronised"