Playing around with an 8266 (have a 32 on the way) and have the deep sleep part running. I simply have a uptime sensor and an ADC as a sensor. Interestingly (not what this post is about) it updates the uptime without fail every time it comes out of sleep but not every time does it update the ADC.
It wakes for 180 seconds before going back to sleep. Is there a way I can either send a pin high 5 seconds after it wakes then say send it low 5 seconds before it sleeps. The idea being I can turn on and off the circuit its using to test thus reduce the battery usage even more. Currently the testing circuit runs all the time.
turning off 5 seconds before going to sleep …
there might be several ways to do it, I would first try removing run_duration from deep_sleep and continue adding code to on_boot:
Thanks for that. Will give it try when home form work. I guess I will try what I am about to ask but while its in the 170 second delay will the adc do its thing? The reason I had it on for 180 seconds was efectively to do three adc samples. I the sample pin will now tuen on and off that part of the ciruit hopefully to cut down sleep current a bit more
Ok have entered some test code. Runs prettu well but get a zero reading in the ADC every now and then. I am thinking it is taking a reading before the sample pin turns on and supplies the test circuit or after it turns off. Just going to shorten the delays to see if that stops it. Not sure and looking if there is a command to get the adc to read when called and thus I can turn on the pin, wait a few secods then get it to take a reading.
Ok its mostly working as expected except as mentioned above it seems to every now and then send though a reading of 0 (or that close) indicating its taking a reading just before the sample pin is turned on or just after its turned of. Hardware doing the sampling is controlled (powered up/dpwn) via the sample pin.
So reading the ESP home stuff it looks like I can maybe filter the readings out below a certain value or maybe some other filter but idealy would live to be able to end the data only when the sample pin has been on for a second or 2 and stop sending data a second or 2 before the sample pin is turned off. The pin itself is working as expected
Just looking also at using mqtt as it may be easier to fire off the values when needed
I’m curious to see how far you get on this. I read in a reddit somewhere that the esphome api might delay these methods of ‘waking to quickly send data’… something about the API taking up to 60sec to grab the new value(s). Seemed folks fixed this by just using mqtt, which allows you to spontaneously fire off a json message with all your sensor data without any wait.
Right now I have a few esp devices running standard arduino code, with mqtt for HA. That certainly offers all the flexibility needed for most applications, however I’ve always wondered if some of the more ‘complex tricks’ I’m doing in arduino could be replicated in esphome. One of them is similar to what you are after… I use a pin to power up/down some sensors so the sensors don’t burn battery while the esp is sleeping. In arduino, on top of that you can do other cool battery saving tricks, like ensuring the wifi radio is off at reboot so the sensors all get clean power while reading (also saves power since some sensors need some time to warm up for a good reading)… then turn the radio on for a quick upload to mqtt after all the sensors have been correctly read (rejecting dht nan’s, averaging several values, etc…), then of course radio down then deepsleep(x). If esphome can do this, I’d happily switch those devices over.
Posting this for anyone else who comes here looking for the answer. Below is a bit simpler solution that works with deep_sleep and not having to use the delay values
esphome:
name: My Sleepy ESP
on_boot:
then:
- output.turn_on: pwr_pin
- delay: 1s # I use this delay just to ensure the pin has power before reading
on_shutdown:
then:
- output.turn_off: pwr_pin
- logger.log: "Goodnight sweet prince"
# Deep sleep
deep_sleep:
run_duration: 10s
sleep_duration: 12h
# Rest of your ESP Code
# ...
output:
- platform: gpio
pin: GPIO35 # or whatever pin your use
id: pwr_pin