Output pin and Deep Sleep

Hi all.

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.

Share the ,… code.

You can use on_boot then delay

For the other part you can do delay before sleep

Ok here we go. Thia is what running at the moment.

esphome:
  name: esp1
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: "ssid"
  password: "1234"

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

sensor:
  - platform: uptime
    name: Uptime Sensor

  
  - platform: adc
    pin: A0
    name: "soil"
    update_interval: 20s    
    filters:
      - multiply: 3.3
deep_sleep:
  run_duration: 180s
  sleep_duration: 20min      

I think I have to add

output:
  - platform: gpio
    pin: 5
    id: sample_pin

and then as suggested a turn on in the on wake and turn off in the before sleep.

esphome:
  name: esp1
  platform: ESP8266
  board: esp01_1m
  on_boot:
     then:
       - delay: 5s
       - output.turn_on: sample_pin

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:


  on_boot:
     then:
       - delay: 5s
       - output.turn_on: sample_pin
       - delay: 170s # 180 - 10
       - output.turn_off: sample_pin
       - delay: 5s
       - deep_sleep.enter: deep_sleep_1 # add id to deep_sleep

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

I really cannot anticípate what will happen exactly. Experiment that and report your findings!

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.

esphome:
  name: esp1
  platform: ESP8266
  board: esp01_1m
  on_boot:
     then:
       - delay: 5s
       - output.turn_on: sample_pin
       - delay: 165s
       - output.turn_off: sample_pin
       - delay: 5s
       - deep_sleep.enter: Deepsleep1
output:
  - platform: gpio
    pin: 5
    id: sample_pin 
  

wifi:
  ssid: "ssid"
  password: "1234"

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

sensor:
  - platform: uptime
    name: Uptime Sensor

  
  - platform: adc
    pin: A0
    name: "soil"
    update_interval: 30s    
    filters:
      - multiply: 3.3
deep_sleep:
  id: Deepsleep1 
  run_duration: 200s
  sleep_duration: 5min    

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