Time Difference in ESPHome

The pcb of thumble dryer is gone, so i decided to create a new one using esphome.
Everything is working fine, except my delay script…
If the compressor of the dryer is turned off, i have to wait for 3 minutes to turn on again.
The template switch can be turned on, the gpio must be delayed, even if the microcontroller reboots.
so i decided to use sntp server so make sure.

Sadly something went wrong in the lambda, esp32 reboots, and the difftime isnt working at all.

Here is my code:

globals:
  - id: CurrentTIME
    type: long int
    restore_value: yes
  - id: CompressorTimeOFF
    type: long int
    restore_value: yes
  - id: CompressorOFFTime
    type: long int 
    restore_value: no

  - platform: template
    name: "Compressor Control"
    optimistic: true
    restore_state: false
    turn_on_action:
      - lambda: |-
          id(CurrentTIME) = id(sntp_time).now().timestamp;
          ESP_LOGI("custom", "Difference in seconds: %l", difftime(id(CurrentTIME), id(CompressorTimeOFF)) ) ;
          id(CompressorOFFTime) = difftime(id(CurrentTIME), id(CompressorTimeOFF));
          if (id (CompressorOFFTime) > 180) {
            ESP_LOGI("custom", "More than 180s elapsed, turning on" );
            id(Compressor).turn_on();
          } else {
            unsigned long TimeDifference = 180-(difftime(id(CurrentTIME), id(CompressorTimeOFF)));
            ESP_LOGI("custom", "Waiting for : %l seconds to turn on compressor", TimeDifference ) ;
            id(CompressorDelayedTurnOn).execute();
          }
    turn_off_action:
      - lambda: |-
         id(CompressorTimeOFF) = id(sntp_time).now().timestamp;
      - switch.turn_off: Compressor
      - script.stop: CompressorDelayedTurnOn 
    icon: mdi:heat-pump

script: 
  - id: CompressorDelayedTurnOn
    mode: single
    then: 
    - delay: !lambda return (180 - difftime(id(CurrentTIME), id(CompressorTimeOFF))) * 1000;
    - switch.turn_on: Compressor



I know its old, but have you find the solution?
I dont see the time component declaration

time:
  - platform: sntp
    id: sntp_time

and maybe you have to check if time is valid before use:
if (id(sntp_time).now().is_valid())