I need help with ESPHome sensor

Hello, I have a battery powered multisensor with ESP32 (PIR, sound, temp, humidity, battery, CO2).
What I want to do in the sensor yaml file is something like this :

  • Esp32 is in deep sleep for let’s say 30sec.
  • When is waking up from deep sleep to turn on the pir sensor power(this is already done for 5 seconds) and if the PIR sensor feels movement to go further with other tests(battery, temp, humidity,etc) and also to connect to WIFI and to send the values and deep sleep … if PIR doesn’t feel any movement (in that 5 seconds of being awake) to go to deep sleep again instantly (without turning on WIFI, scanning wifi networks and stuff) to save the battery.
    Can you help me to implement this “if - that - else” ?

This is my yaml file:

esphome:

  name: officesense1

  friendly_name: officesense1

  includes:

    - "cm1106.h"

  on_boot:

      priority: 250    

      then:

        - switch.turn_on: PIR_power        

        - delay: 5s

        - switch.turn_off: PIR_power 

   

esp32:

  board: esp32dev

  framework:

    type: arduino

# Enable logging

logger:

  level: DEBUG

# Enable Home Assistant API

api:

  encryption:

    key: "oelCUfp7IcuXcD908fWWcqSFw="

ota:

  password: "65c81d63a6a545b8808"

wifi:

  ssid: !secret wifi_ssid

  password: !secret wifi_password

  fast_connect: true

  # power_save_mode: HIGH  

  manual_ip:

    static_ip: 192.168.178.32

    gateway: 192.168.178.1    

    subnet: 255.255.255.0

   

  # Enable fallback hotspot (captive portal) in case wifi connection fails

  ap:

    ssid: "Officesense1 Fallback Hotspot"

    password: !secret wifi_password

captive_portal:

# i2c:

#   sda: 21

#   scl: 22

#   scan: true

#   id: bus_a

# uart:

#   rx_pin: 16

#   tx_pin: 17

#   baud_rate: 9600

#   id: cm1106_uart

sensor:

  # - platform: hdc1080

  #   temperature:

  #     name: "temperature"

  #   humidity:

  #     name: "humidity"

  #   update_interval: 60s

  # - platform: custom

  #   lambda: |-

  #     auto cm1106Sensor = new CM1106Sensor(id(cm1106_uart), 10000);

  #     App.register_component(cm1106Sensor);

  #     return {cm1106Sensor};

  #   sensors:

  #   - name: "CO₂ Sensor"

  #     accuracy_decimals: 0

  #     unit_of_measurement: "ppm"

  #     icon: "mdi:molecule-co2"

  - platform: adc

    pin: A5

    name: "Battery"

    icon: "mdi:battery-alert"

    accuracy_decimals: 2

    update_interval: 1s

    attenuation: 11dB

    filters:

      - multiply: 2.0

binary_sensor:

  - platform: gpio

    pin: 18

    name: "movement"

    id: movement

    device_class: motion

switch:

# - platform: custom

#   lambda: |-

#     auto cm1106Calib = new CM1106CalibrateSwitch(id(cm1106_uart));

#     App.register_component(cm1106Calib);

#     return {cm1106Calib};

#   switches:

#   - name: "CM1106 Zero Calibration"

- platform: gpio

  name: "PIR power "

  pin: 13

  id: PIR_power 

  icon: "mdi:eye"  

- platform: restart

  name: "Living Room Restart"  

deep_sleep:

  id: deep_sleep_1

  run_duration: 10s
  sleep_duration: 30s

I’m not sure you can force those sensors to be manually update only.

If I was designing something like this I would use a 3.3V PIR to trigger the interrupt pin on an ESP32, to wake it out of long term deep sleep. Have a read about ESP32 Wakeup Pin Mode.

I have seen other suggestions for an ESP8266 where the PIR trips a transistor circuit to latch power on. A quick google found this discussion: PIR sensor only to be powered and it turns on another power supply and load.

I personally would go with the wakeup pin. That’s how my mailbox sensor works.

1 Like