How to change the value of a binary sensor

I’m new to ESPHome after using ESP Easy and MQTT for the last year. My first project is to try and make a battery powered button with a D1 mini.

I have the code below which seems to work for putting the unit into deep sleep the I can press the rest button to wake it and right now it comes online for 5 seconds and then back to sleep.

What I can’t figure out is how to make a “fake” binary sensor that I can control in the YAML. As in it can wake, some yaml code changes the binary sensor value to 1, code waits a second or two, changes it back to 0 then goes back to sleep. Then I can use this sensor value in my automations. I have spent an hour going thru the docs and can’t find anything that relates to this.

  name: esphome-web-7ab100
    priority: -100.0
   # - something here to set binary sensor to on?
      - delay: 5s
   # - something here to set binary sensor to off?
      - deep_sleep.enter

  board: d1_mini

# Enable logging

# Enable Home Assistant API


  ssid: !secret wifi_ssid
  password: !secret wifi_password

  - platform: adc
    pin: VCC
    name: "VCC Voltage"

In this particular use-case, could you just use the status binary sensor? This turns on when the ESP connects, and turns off when it disconnects from HA.

1 Like

If you only use it as a fake binary sensor, you can use a bool global variable, see Automations and Templates — ESPHome

1 Like

Awesome these are two great solutions. Not sure how I missed the Status sensor but I kept thinking there must be something like that must exist.

Now I just need to see if I can live with the lag of connecting to WiFi. Not exactly a responsive button. Either way I’m excited to try from battery powered sensors.

1 Like