How to make ESP goes online once a day, sync time, then wifi disable.?

ESP8266 nodemcu, esphome[2023.12.5] controls dusk to dawn lights. I need it to sync time once a day then sleep (wifi.disable).

I tried this but if the esp happened to not be connected to wifi at dusk/dawn, it fails to execute sunrise/sunset actions. As if the esp doesnt retain the time clock when the sync fails because the WIFI is disabled?

interval:
 - interval: 24 hr
   then:
     - wifi.enable
     - delay: 10 min
     - wifi.disable
time:
  - platform: homeassistant
    id: homeassistant_time

sun:
  latitude: 42.588081
  longitude: -87.822899
  on_sunset:
    - then:
        - delay: 30 min
        - switch.turn_on:
            id: lights


  on_sunrise:
    - elevation: -18°
      then:
        - switch.turn_off:
            id: lights

maybe an option to trigger a sync when wifi is on? something like

interval:
 - interval: 24 hr
   then:
     - wifi.enable
     - time.sync #i know this is not an option but hoping to find something similar
     - delay: 10 min
     - wifi.disable

Could you use deep sleep for your application?

The deep sleep duration is templateable, so you could calculate the time until the next sunrise / sunset, sleep, wake up, change the lights, update the next events, and go back to sleep until next iteration?

Thank you for your reply. I suppose the deep sleep would work for my application. The thing that annoys me when not in deep sleep, whenever I lose my WAN connection, the esphome ‘forgets’ the time and wouldnt trigger sun actions.

1 Like