stefanbode / Sonoff-Tasmota

Provide ESP8266 based itead Sonoff with Web, MQTT and OTA firmware using Arduino IDE, enhanced with I2C options
GNU General Public License v3.0
128 stars 41 forks source link

A place for "Pre-DeepSleep" function calls #179

Closed thomas-lentz closed 4 years ago

thomas-lentz commented 4 years ago

ISSUE DESCRIPTION - TROUBLESHOOTING

I need to know the best place to put Pre-DeepSleep function calls. Concrete example: I want to switch off a sensor and a display just prior Tasmota goes to sleep - otherwise these devices consume senselessly power during the deepsleep phase.

REQUESTED INFORMATION

stefanbode commented 4 years ago

There is currently no functionality for this

thomas-lentz commented 4 years ago

Hi Stefan, I just need to know, which function is called to enter the deepsleep state, the rest I can program myself (of course I would publish it here). I would be something before or shortly after the

18:10:11 MQT: tele/skybeam/UPTIME_S = {"Time":"2019-08-27T18:10:11", "Uptime_s":0} message.

stefanbode commented 4 years ago

I made a small change and you can now place your function in FUNC_SAVE_BEFORE_RESTART. For Example you create you own driver e.g xdrv_50_mydriver.ino and in the bottom under.

bool Xdrv50(uint8_t function)
{
  bool result = false;

    switch (function) {
      case FUNC_SAVE_BEFORE_RESTART:
        mypoweroff();
        break;
     ....

Just take a look at the other drivers how they do it. The function will be called for drivers and sensors.

stefanbode commented 4 years ago

Cool addition with the change is, that you now can also use rules. "System#Save" is the rule event that is triggered just before deepsleep.

thomas-lentz commented 4 years ago

Great, thank you - that's what I needed.