ESP Home SET Pin High

How to simply set pin GPIO02 to HIGH ? I am lost

substitutions:
  name: esphome-web-5822df
  friendly_name: ESP-HUMIDITY

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  min_version: 2024.6.0
  name_add_mac_suffix: false
  project:
    name: esphome.web
    version: dev

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:

# Allow Over-The-Air updates
ota:
- platform: esphome

# Allow provisioning Wi-Fi via serial
improv_serial:

wifi:
  # Set up a wifi access point
  ap: {}

# In combination with the `ap` this allows the user
# to provision wifi credentials to the device via WiFi AP.
captive_portal:

dashboard_import:
  package_import_url: github://esphome/example-configs/esphome-web/esp8266.yaml@main
  import_full_config: true

sensor:
  - platform: dht
    pin: GPIO0 #Pin D3
    temperature:
      name: "Living Room Temperature"
    humidity:
      name: "Living Room Humidity"
    update_interval: 2s

switch:
  - platform: gpio
    name: "GPIO13 Switch"
    pin: GPIO02
    id: GPIO02_switch
    internal: true

web_server:
 port: 80

When do you want to turn the switch on (GPIO02 → High)?

You can control it from your dashboard in home assistant. Or in ESPHome you can use the switch.turn_on action. See: Actions, Triggers, Conditions — ESPHome

Is there any reason that you set it as internal? This way it’s not accessible from HA. Delete that line and it will appear.

Full time without condition

Why use a gpio then?
Why not use the 3.3 v pin?

That’s an excellent question I did not partially responded:
Because I am testing a lot of sensors that have Fix pin that are all in front of my ESP8266 PIN.
So, instead of prototyping a lot of hardware, I just want to set the right “voltage” on PINs. (And yes, the current consumed by the sensor is lower than the electrical capability of the output pin.)

Add the following to your switch

restore_mode: ALWAYS_ON
1 Like
  on_boot:
    priority: 1000
    then:
      - lambda: |-
          pinMode(02, OUTPUT);
          digitalWrite(02, HIGH);

Do it in lambda. This should set it high very early on the boot.

1 Like

Thank you !