Dynamic SleepMode

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Domosapiens
Normal user
Posts: 307
Joined: 06 Nov 2016, 13:45

Dynamic SleepMode

#1 Post by Domosapiens » 13 Mar 2018, 10:50

I like to measure the sun energy with a SI1145 on a regular interval.
It will be a solar powered battery set-up.
I prefer a 1 minute sleep cycle for the next measurement during day-time.
During night hours this 1 minute cycle is useless and a waste of battery energy.

The SleepMode has a static sleep time at this moment.
I understand the limitation of the sleep counter: maximum 4229 seconds.

2 Questions:
- Is it technically possible to adapt ESPEasy, to define/override the SleepTime in a rule?
- Are more people interested in such feature?
30+ ESP units for production and test. Ranging from control of heating equipment, flow sensing, floor temp sensing, energy calculation, floor thermostat, water usage, to an interactive "fun box" for my grandson. Mainly Wemos D1.

arion_p
Normal user
Posts: 24
Joined: 05 Mar 2018, 22:02

Re: Dynamic SleepMode

#2 Post by arion_p » 13 Mar 2018, 17:13

You can achieve the same result using rules and the deepSleep command. deepSleep puts the system to sleep immediately and takes one argument the duration of the sleep. So depending on the conditions you choose you can set different duration. You can use the System#Sleep event to take over control and start sleep yourself using the duration you want. E.g if you want to increase sleep time between 22:00 and 05:00

Code: Select all

on System#Sleep do
  if %systime% > 22:00:00 or %systime% < 05:00:00
    deepSleep,300 //5 minutes
  endif
  // otherwise let the system use the default sleep duration
endon
Of course night time changes throughout the year. So you may want to have some sensor to check if it is day or night. Then instead of using time, use the sensor measurement to determine which sleep duration to apply

Domosapiens
Normal user
Posts: 307
Joined: 06 Nov 2016, 13:45

Re: Dynamic SleepMode

#3 Post by Domosapiens » 13 Mar 2018, 17:56

Top!
I will give it a try.
Thanks
30+ ESP units for production and test. Ranging from control of heating equipment, flow sensing, floor temp sensing, energy calculation, floor thermostat, water usage, to an interactive "fun box" for my grandson. Mainly Wemos D1.

Elektrofreak
Normal user
Posts: 22
Joined: 03 Mar 2016, 09:06

Re: Dynamic SleepMode

#4 Post by Elektrofreak » 13 Mar 2018, 20:23

Hi there,

Is it also possible to execute the deep sleep command with the FHEM Plugin? Which modifications would be needed to be able to do so?

Domosapiens
Normal user
Posts: 307
Joined: 06 Nov 2016, 13:45

Re: Dynamic SleepMode

#5 Post by Domosapiens » 16 Mar 2018, 23:17

Thanks arion_p.
I finaly solved my NTP time problem: a local server was needed for a reliable NTP at start-up.

Now I use this Rule:

Code: Select all

On System#Boot do
OLEDCMD,on
endon

on System#Sleep do
OLEDCMD,off
  if %systime% > 19:00:00 or %systime% < 05:00:00
   deepSleep,3600 //60 minutes
  endif
  // otherwise let the system use the default sleep duration
endon

I used the portable syslog server mentioned here, and see this: it looks like the SystemSleep Rule is executed 3 times:

Code: Select all

<7>MUC16_LOAD EspEasy: EVENT: Clock#Time=Fri,20:55		192.168.1.86	16/03 20:55:55.477	
<7>MUC16_LOAD EspEasy: EVENT: System#Sleep			192.168.1.86	16/03 20:55:55.483	
<7>MUC16_LOAD EspEasy: ACT  : OLEDCMD,off			192.168.1.86	16/03 20:55:55.492	
<7>MUC16_LOAD EspEasy: ACT  : deepSleep,3600			192.168.1.86	16/03 20:55:55.503	
<7>MUC16_LOAD EspEasy: EVENT: System#Sleep			192.168.1.86	16/03 20:55:55.513	
<7>MUC16_LOAD EspEasy: ACT  : OLEDCMD,off			192.168.1.86	16/03 20:55:55.523	
<7>MUC16_LOAD EspEasy: ACT  : deepSleep,3600			192.168.1.86	16/03 20:55:55.541	
<7>MUC16_LOAD EspEasy: EVENT: System#Sleep			192.168.1.86	16/03 20:55:55.549	
<7>MUC16_LOAD EspEasy: ACT  : OLEDCMD,off			192.168.1.86	16/03 20:55:55.558	
<7>MUC16_LOAD EspEasy: ACT  : deepSleep,3600			192.168.1.86	16/03 20:55:55.569	
<7>MUC16_LOAD EspEasy: EVENT: Time#Initialized			192.168.1.86	16/03 21:53:29.498	
<7>MUC16_LOAD EspEasy: Current Time Zone: STD time start: 2018-10-28 03:00:00 offset: 60 min	192.168.1.86	16/03 21:53:29.507
I have also seen that it was executed 2 times (when the OR Rule is false).

Is there any explanation for this?

The second remark is that 3600 seconds is not executed as an hour, but as 57 minutes and 34 seconds.
So by using deepSleep 3810, it will wake just after an hour and just after 05:00 instead of close to 06:00.

Pre-compiled GIT version: v2.0-20180312 on Wemos D1
Last edited by Domosapiens on 17 Mar 2018, 09:32, edited 1 time in total.
30+ ESP units for production and test. Ranging from control of heating equipment, flow sensing, floor temp sensing, energy calculation, floor thermostat, water usage, to an interactive "fun box" for my grandson. Mainly Wemos D1.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Dynamic SleepMode

#6 Post by grovkillen » 16 Mar 2018, 23:27

I think it could be that the new AND/OR operators introduced a triple check/trigger since it will do up to three values. Not sure, only a hunch.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Domosapiens
Normal user
Posts: 307
Joined: 06 Nov 2016, 13:45

Re: Dynamic SleepMode

#7 Post by Domosapiens » 16 Mar 2018, 23:41

Yeh ..but ..
then you would expect that only in the IF .. OR section
but the OLEDCMD is executed also 3 times :o
30+ ESP units for production and test. Ranging from control of heating equipment, flow sensing, floor temp sensing, energy calculation, floor thermostat, water usage, to an interactive "fun box" for my grandson. Mainly Wemos D1.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Dynamic SleepMode

#8 Post by grovkillen » 16 Mar 2018, 23:44

It's part of that IF chunk. Because it's triggered and the action is then carried out. Thus them commands will be showing up three times.

EDIT: not part of the IF.... Sorry. But still I think it's the reason for the three times trigger.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Domosapiens
Normal user
Posts: 307
Joined: 06 Nov 2016, 13:45

Re: Dynamic SleepMode

#9 Post by Domosapiens » 16 Mar 2018, 23:50

Too much logging creates sleepless nights ;)
30+ ESP units for production and test. Ranging from control of heating equipment, flow sensing, floor temp sensing, energy calculation, floor thermostat, water usage, to an interactive "fun box" for my grandson. Mainly Wemos D1.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Dynamic SleepMode

#10 Post by grovkillen » 16 Mar 2018, 23:53

The more you know, the more you don't understand. And ignorance is a bliss.

Good quotes 8-)
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Dynamic SleepMode

#11 Post by budman1758 » 17 Mar 2018, 01:37

This is a perfect use case for external RTC support like the DS3231. :ugeek: :ugeek:
"The glass is twice as big as it needs to be".

arion_p
Normal user
Posts: 24
Joined: 05 Mar 2018, 22:02

Re: Dynamic SleepMode

#12 Post by arion_p » 17 Mar 2018, 19:23

Domosapiens wrote: 16 Mar 2018, 23:17 I used the portable syslog server mentioned here, and see this: it looks like the SystemSleep Rule is executed 3 times:
....

I have also seen that it was executed 2 times (when the OR Rule is false).

Is there any explanation for this?
I can see why it is executed twice (but I cannot imagine why it would be executed a third time).

In ESPEasy.ino, in the main loop when sleep is enabled it runs all tasks at once (instead of at scheduled times) then if rules are enabled, it triggers the System#sleep event. Later at bottom of the loop if it's time to sleep it calls deepSleep() which calls startDeepSleep() which triggers the event again.

The first event trigger is superfluous. However the second one is also problematic. If it's time to sleep and startDeepSleep is called, the event is triggered. Now if you have a rule that runs the deepSleep command, this ends up calling startDeepSleep again triggering the event recursively. This should end up in an endless loop and finally to stack overflow. But according to your logs it does not.

I need to investigate further, however the first event trigger should definately be removed.

Edit: is there an issue on github for this?

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests