seime / openhab-esphome

ESPHome native API implementation for openHAB binding
MIT License
24 stars 6 forks source link

Support for `deep_sleep` #25

Open magx2 opened 1 month ago

magx2 commented 1 month ago

Hey,

I'm using your library to connect with my ESP that has an eink screen. This device runs on a battery, so I need to use deep sleep to extend its battery life. My use case looks like this:

  1. Turn on for 1 min
  2. Get data from OH
  3. Turn off for 45 min
  4. Repeat

I see that this use case is not currently supported by your software. Are you able to add it?

seime commented 1 month ago

I have not dug into deep sleep yet, so please enligthen me; what needs to be added to the binding?

magx2 commented 1 month ago

I would imagine this:

  1. add bool config property called deepSleep - if it's enabled the the rest of the algorithm applies
  2. add int config property called deepSleepReconnect - this is value for scheduleReconnect (right now it's hardcoed 40 secs)
  3. add int config property called deepSleepMaxRetries - after how many reconnects the device should be considered offline
  4. do not make the thing offline until hits deepSleepMaxRetries. Also do not log in WARN "[{}] Error initial connection" (I had to turn off logs for this class, because it was killing me)

So my use case would look like this:

deepSleep=true
deepSleepReconnect=10 // try every 10 secs to connect to device
deepSleepMaxRetries=270 // 45 min / 10 secs = 270 - my device turns on every 45 mins so this should work just fine

OH would try to connect to ESP every 10 secs and after 270 attempts (not earlier) it would put my thing as offline

before reaching 270 attempts: obraz

after 270 attempts: obraz

magx2 commented 1 month ago

And of course if it will establish connection with ESP at least once it will be online all the time (unless 270 attempts threshold will be hit)

seime commented 1 month ago

Ok, then I understand what you mean. I'll take a look - or feel free to create a PR :)

magx2 commented 3 weeks ago

Any luck?

seime commented 3 weeks ago

Just a quick look so far, but regular life got in between.

If you'll create a PR I'll try to prioritize reviewing and merging it