-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deep Sleep WIP #11
base: platform/libretuya
Are you sure you want to change the base?
Deep Sleep WIP #11
Conversation
Let's keep the discussion in the main PR (the platform one). I'll reply there tomorrow with a little review. |
Just wanted to leave my 2c here of testing that I have done with the I'll keep playing around to see if there's anything I can see as to why it keeps waking
substitutions:
name: "door-sensor-laundry-02"
wifi_ssid: !secret wifi_ssid
wifi_password: !secret wifi_password
static_ip: 192.168.0.97
gateway: 192.168.0.1
subnet: 255.255.255.0
sensor_pin: P16
esphome:
name: $name
bk72xx:
board: generic-bk7231n-qfn32-tuya
framework:
version: dev
api:
encryption:
key: !secret api_password
ota:
password: !secret ota_password
wifi:
ssid: $wifi_ssid
password: $wifi_password
fast_connect: true
manual_ip:
static_ip: $static_ip
gateway: $gateway
subnet: $subnet
captive_portal:
mdns:
logger:
web_server:
local: true
text_sensor:
- platform: wifi_info
ip_address:
id: ip_address
name: IP Address
binary_sensor:
- platform: gpio
pin:
number: $sensor_pin
mode:
input: true
pullup: true
name: $name Sensor
device_class: door
id: door
deep_sleep:
wakeup_pin: $sensor_pin
id: deep_sleep_1
run_duration: 30s |
@samhunt In my case multiple pins were reacting to a magnet, and I had to find the proper one for wake source by trial and error. |
Thanks, I'll give that a try |
@samhunt, did you manage to make it works? I've tried several combination of the deep_sleep parameters, but I always encounter the same problem. Here is my current setup for deep_sleep and binary_sensor
What I noticed is that if I use the I tried also with both I don't know if there is something wrong with my configuration or with the |
No I wasn't able to get libretiny to work. OpenBreken worked fine with the same device, and the batteries were able to last over a month instead of a day or so with this code. |
I'm in the exact same situation... I tried with OpenBeken, same device and same pin settings, and deep sleep seems to be working fine. With libretiny the response seems to be faster, at least when it reboot immediately after going into deep sleep based on what I was able to test. I'm not an expert of C/C++, so it's a bit tricky for me to change the code and do some tests. Any help would me more than appreciated. 😃 |
I think I found where the problem is. The condition in
while in libretiny when the deep sleep GPIO is configured in
That's why as soon as the device went to sleep using the I didn't want to recompile all the platform code (and honestly I don't even know how to do it 😃), but I tried to apply a quick change in the esp-home deep_sleep component, and it seems to work!
In this way I can invert the condition in the platform code, even if it's not correct logically speaking. I will do some more test, but so far it seems to work as expected. Hope that helps! 🙂 |
@alessiocappa This what openbeken has to say about it:
Also in their code:
So it looks like the same implementation as mine. (On rising (high), zero out the pin, on falling, set it to 1). |
@Xmister are you using single or multiple wake up pins? I see in your code that the I flashed OpenBeken and deep sleep was working on the same device, so I don't think it's an hardware problem.
As far as I understand, if the pin is HIGH falling is 1, while if the pin is LOW falling is 0. |
@alessiocappa This is the code for handling the invertion, i.e. if it's currently high, wake up on low. |
I did test out changing the code in my cached FWIW my device only has one pin available to attach to deep_sleep |
I see, it was just to provide the full context. 🙂
And the following code in libretiny-esphome:
Let's assume P16 is LOW. The function
So the device is woken up immediately, considering that the pin is already in a LOW state. I double checked the OpenBeken code and indeed the logic seems to be the same, but I think the main difference is that OpenBeken was providing an inverted value by default to me, so I guess that why it was working with OB and it works with libretiny if I modify the definition of Also, it's not clear to me why
Thanks for your help! 👍 |
@alessiocappa I see, if the openbeken logic is based on an inverted value all the time, then yes, our logic is wrong. I indeed use the wakeup_pins definition which has the "bug" of wrongly initializing the level variable, and that's why it works for me. |
Created libretiny-eu/libretiny#159 |
I don't know what I am doing wrong, but I cannot get that change in
|
@samhunt Is it also happening when you leave out |
Sorry for the late reply. I haven't been able to give that a long test, but that seems to have done the trick |
Hi @Xmister, first of all, thanks a lot for having updated the deep sleep component in order to work with the official ESPHome release! I hope it will be implemented in the official firmware as well, but for now I can use it as an external component. However, I would like to check with you how does it work in your case from a performance point of view. What I noticed is that the response time on the one with ESPHome is way more slower; indeed, the one with the stock firmware seems to be pretty fast, with an average response time of about 3s, while the device with ESPHome installed can take up to 8/9, sometimes 10 seconds to report the state. What is the response time in your case? Do you know if there is a way to improve it? |
@alessiocappa Hi, In my use case (door sensor as gas meter) I can just update the internal state on wake within 1s, and only report back to HA every 10-100 wakes. |
How do you put deep_sleep on same pin because at me tell me always duplicate pin use |
how you use 2 PIN in yaml? bacuse always i have : And can't compile |
Is this your yaml that is not compiling? |
…#6715) Co-authored-by: Jesse Hills <[email protected]>
Co-authored-by: Jesse Hills <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jesse Hills <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jesse Hills <[email protected]>
…ne when microphon… (esphome#6391)
This is an initial try on Deep Sleep for the Beken platform.
Most of the code are tailored from OpenBeken.
Platform Changes
BDK Changes
NOTE: I'm still having linking issues, and can't figure out why it can't find a definition for
bk_enter_deep_sleep_mode
Maybe someone can help me figure out the last steps. @kuba2k2 maybe?