# Homeyduino - Deepsleep

**URL:** <https://community.homey.app/t/homeyduino-deepsleep/23298>\
**Category:** Developers\
**Created:** [December 28, 2019, 7:34pm UTC](https://community.homey.app/t/homeyduino-deepsleep/23298 "2019-12-28T19:34:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andreas\_Osterdahl](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/andreas_osterdahl/32/18713_2.png) [@Andreas\_Osterdahl](https://community.homey.app/u/Andreas_Osterdahl)\
**Post date:** [December 28, 2019, 7:34pm UTC](https://community.homey.app/t/homeyduino-deepsleep/23298/1 "2019-12-28T19:34:13Z")

</div>

Hello!

I can´t get homeyduino to work with deepsleep on ESP32. I want to send temperature every 60s.  
In order to get values to homey I need to have power for 10s until i go to deepsleep. Another problem is when i reboot homey I then need to also reboot the homeyduino app afterward until values are reported to homey?

Part of code that work, but I want shorter up time since I want to minimize power.

```
void loop() {
  wifi();
  Homey.loop();
  unsigned long currentMillis = millis();
  if(millis()>10000){
    updateSensor(); 
    ESP.deepSleep(60 * 1000000);
  }
}
```

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 28, 2019, 8:31pm UTC](https://community.homey.app/t/homeyduino-deepsleep/23298/2 "2019-12-28T20:31:38Z")

</div>

I don’t think the original developers of Homeyduino every considered supporting deep sleep.

From what I understand from the code, Homeyduino works by the ESP device sending HTTP requests to a server running on Homey, passing data, so not sure why it’s taking 10 seconds to get value updates. Either the Homeyduino app (on Homey) or the library (on the ESP) might be getting confused by the sleep (if I were to guess, I think it might be the library).

---

<div class="post-metadata">

**Author:** ![Lars\_Machiels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/lars_machiels/32/10295_2.png) [@Lars\_Machiels](https://community.homey.app/u/Lars_Machiels)\
**Post date:** [December 29, 2019, 11:38am UTC](https://community.homey.app/t/homeyduino-deepsleep/23298/3 "2019-12-29T11:38:08Z")

</div>

Hi Andreas,

If I remember well deepsleep on an ESP32 doesn’t work with a common loop. I think everything should be in the setup function. You could google “deepsleep Andreas Spies” to see a video about this matter.

Gr.,  
Lars

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 29, 2019, 12:49pm UTC](https://community.homey.app/t/homeyduino-deepsleep/23298/4 "2019-12-29T12:49:01Z")

</div>

Starting a deep sleep from `loop` works just fine on an ESP32.

The video from Andreas is showing a deep sleep example from Espressif, which starts the deep sleep from `setup`, so it makes sense that _in that particular example_, `loop` is never called. But there are no inherent issues with starting a deep sleep from it (just that you have to be aware that it will not continue the `loop` once it wakes up, but it’ll call `setup` again).

---

<div class="post-metadata">

**Author:** ![Lars\_Machiels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/lars_machiels/32/10295_2.png) [@Lars\_Machiels](https://community.homey.app/u/Lars_Machiels)\
**Post date:** [December 29, 2019, 1:01pm UTC](https://community.homey.app/t/homeyduino-deepsleep/23298/5 "2019-12-29T13:01:06Z")

</div>

O, good to know. Thanks.

---

<div class="post-metadata">

**Author:** ![Lars\_Machiels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/lars_machiels/32/10295_2.png) [@Lars\_Machiels](https://community.homey.app/u/Lars_Machiels)\
**Post date:** [December 29, 2019, 1:05pm UTC](https://community.homey.app/t/homeyduino-deepsleep/23298/6 "2019-12-29T13:05:15Z")

</div>

Could it be that with deep sleep the ESP32 loses it’s memory settings?

---

<div class="post-metadata">

**Author:** ![Andreas\_Osterdahl](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/andreas_osterdahl/32/18713_2.png) [@Andreas\_Osterdahl](https://community.homey.app/u/Andreas_Osterdahl)\
**Post date:** [December 29, 2019, 1:27pm UTC](https://community.homey.app/t/homeyduino-deepsleep/23298/7 "2019-12-29T13:27:36Z")

</div>

Thanks for the answer.  
The ESP32 reads the temperature just fine every 60s but as stated before Homey won´t recieve the data. I have tried with and without loop but only succes with a loop of \>10s until deepsleep is activated.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 29, 2019, 1:40pm UTC](https://community.homey.app/t/homeyduino-deepsleep/23298/8 "2019-12-29T13:40:51Z")

</div>

It looks like you might be able to define `DEBUG_ENABLE` before including `Homey.h` to enable some debug logging from the Homeyduino library. Perhaps that will give a clue why you need to wait 10 seconds.
