Variables not updating on ESP32 using IoT Cloud

I am trying to use IoT Cloud to be able to control some lights using Google Home. I have created 5 variables there (once using CloudLight, once using CloudSwitch) and have integrated my thing with Google Home. These variables update correctly when I turn them on or off on my phone, but my code doesn't seem to reflect that, as they always stay at "false".

I have this code, partially generated by AI (I was desperate).

#include "arduino_secrets.h"
#include "thingProperties.h"
#include <WiFi.h> // Include the WiFi library for ESP32
/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/3043cf77-3b19-4f99-b247-fcd202a2dd05 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  CloudSwitch luz_garagem;
  CloudSwitch luz_quarto_direita;
  CloudSwitch luz_quarto_esquerda;
  CloudSwitch luz_quarto_tras;
  CloudSwitch luz_sala;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#define LED_SALA 25
#define LED_QUARTO_ESQUERDA 32
#define LED_QUARTO_DIREITA 33
#define LED_QUARTO_TRAS 26
#define LED_GARAGEM 27

#define TEMP_PIN 16
#define TRIG_PIN 17
#define ECHO_PIN 18
#define POT_PIN 19

float duration, distance;

void startArduinoCloud() {
  initProperties();

  Serial.println("Connecting to Arduino IoT Cloud...");
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  setDebugMessageLevel(4); // Maximum debug level
  ArduinoCloud.printDebugInfo();

  unsigned long startTime = millis();
  while (ArduinoCloud.connected() == 0) {
    ArduinoCloud.update();
    if (millis() - startTime > 10000) { // Timeout after 10 seconds
      Serial.println("Failed to connect to Arduino IoT Cloud.");
      return;
    }
  }
  Serial.println("Connected to Arduino IoT Cloud!");

  
}

void syncTime() {
  configTime(0, 0, "pool.ntp.org", "time.nist.gov"); // You can add more servers if needed

  Serial.print("Waiting for NTP time sync");
  time_t now = time(nullptr);
  int retries = 0;
  while (now < 8 * 3600 * 2 && retries < 20) {
    delay(500);
    Serial.print(".");
    now = time(nullptr);
    retries++;
  }

  Serial.println();
  if (now < 8 * 3600 * 2) {
    Serial.println("Failed to sync time.");
  } else {
    Serial.println("Time synced!");
    struct tm timeinfo;
    gmtime_r(&now, &timeinfo);
    Serial.print("Current time: ");
    Serial.println(asctime(&timeinfo));
  }
}

void startSerial() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 
}

void initializePins(){
  pinMode(LED_SALA, OUTPUT);
  pinMode(LED_QUARTO_ESQUERDA, OUTPUT);
  pinMode(LED_QUARTO_DIREITA, OUTPUT);
  pinMode(LED_QUARTO_TRAS, OUTPUT);
  pinMode(LED_GARAGEM, OUTPUT);

  pinMode(POT_PIN, INPUT);  // Potentiometer PIN
  pinMode(TEMP_PIN, INPUT); // Temperature Pin

  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
}

void startWifi() {
  // Connect to WiFi
  Serial.print("Connecting to ");
  Serial.println(SSID);
  WiFi.begin(SSID, PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("Connected to WiFi");
  

  IPAddress serverIP;
  if (WiFi.hostByName("iot.arduino.cc", serverIP)) {
    Serial.print("Resolved IP: ");
    Serial.println(serverIP);
  } else {
    Serial.println("Failed to resolve iot.arduino.cc");
  }
  //timeSync("UTC0", "pool.ntp.org", "time.nis.gov");
}

void setup() {
  startSerial();
  startWifi();

  syncTime();

  startArduinoCloud();
  initializePins();


}

void loop() {
  // Check and restore WiFi connection if lost
  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("WiFi disconnected! Attempting to reconnect...");
    WiFi.begin(SSID, PASS);

    unsigned long wifiReconnectStart = millis();
    while (WiFi.status() != WL_CONNECTED && millis() - wifiReconnectStart < 10000) {
      delay(500);
      Serial.print(".");
    }

    if (WiFi.status() == WL_CONNECTED) {
      Serial.println("\nReconnected to WiFi!");
    } else {
      Serial.println("\nFailed to reconnect to WiFi.");
    }
  }

  // Update the cloud service
  ArduinoCloud.update();
  //ArduinoCloud.sync();
  delay(1000);
  // Check if Arduino Cloud is connected (for debug/logging only — do not call begin here)
  if (!ArduinoCloud.connected()) {
    ESP.restart(); // Restart the ESP32 if Arduino Cloud is not connected
    Serial.println("Arduino Cloud not connected. Restarting ESP32...");
    // Do not call begin() here. Let the cloud auto-recover if WiFi is stable.
  }

  // Debug prints — keep as-is or refactor into a function
  Serial.print("Arduino Cloud Connected: ");
  Serial.println(ArduinoCloud.connected());

  Serial.print("Luz Garagem: ");
  Serial.println(luz_garagem);

  Serial.print("Luz Quarto Direita: ");
  Serial.println(luz_quarto_direita ? "ON" : "OFF");

  Serial.print("Luz Quarto Esquerda: ");
  Serial.println(luz_quarto_esquerda ? "ON" : "OFF");

  Serial.print("Luz Quarto Tras: ");
  Serial.println(luz_quarto_tras ? "ON" : "OFF");

  Serial.print("Luz Sala: ");
  Serial.println(luz_sala ? "ON" : "OFF");
}



void onLuzQuartoEsquerdaChange()  {
  digitalWrite(LED_QUARTO_ESQUERDA, luz_quarto_esquerda ? HIGH : LOW);
  Serial.print("Luz do Quarto Esquerda: ");
  Serial.println(luz_quarto_esquerda ? "ON" : "OFF");
  // Optional: Add a delay to avoid rapid toggling
  // luz.addField("Luz do Quarto Esquerda", luz_quarto_esquerda);
}

void onLuzQuartoDireitaChange()  {
  digitalWrite(LED_QUARTO_DIREITA, luz_quarto_direita ? HIGH : LOW);
  Serial.print("Luz do Quarto Direita: ");
  Serial.println(luz_quarto_direita ? "ON" : "OFF");
  // luz.addField("Luz do Quarto Direita", luz_quarto_direita);
}

void onLuzQuartoTrasChange()  {
  digitalWrite(LED_QUARTO_TRAS, luz_quarto_tras ? HIGH : LOW);
  Serial.print("Luz do Quarto Tras: ");
  Serial.println(luz_quarto_tras ? "ON" : "OFF");
  // luz.addField("Luz do Quarto Tras", luz_quarto_tras);
}

void onLuzSalaChange()  {
  digitalWrite(LED_SALA, luz_sala ? HIGH : LOW);
  Serial.print("Luz do Sala: ");
  Serial.println(luz_sala ? "ON" : "OFF");
  // luz.addField("Luz do Sala", luz_sala);
}

void onLuzGaragemChange()  {
  digitalWrite(LED_GARAGEM, luz_garagem ? HIGH : LOW);
  Serial.print("Luz do Garagem: ");
  Serial.println(luz_garagem ? "ON" : "OFF");
  // luz.addField("Luz do Garagem", luz_garagem);
}

Any help would be gladly appreaciated

There is no "false" in your code.

Yeah, the false is on the IoT Cloud variables, that's what I check on the main function.

Can you track how the "false" gets from where it is to where you see it?