diff --git a/esphome/components/gpio/binary_sensor/gpio_binary_sensor.cpp b/esphome/components/gpio/binary_sensor/gpio_binary_sensor.cpp index 43e5a9d0e1..ef99863845 100644 --- a/esphome/components/gpio/binary_sensor/gpio_binary_sensor.cpp +++ b/esphome/components/gpio/binary_sensor/gpio_binary_sensor.cpp @@ -19,11 +19,12 @@ void GPIOBinarySensorStore::setup(InternalGPIOPin *pin, gpio::InterruptType type this->pin_ = pin; pin->setup(); this->isr_pin_ = pin->to_isr(); - { - InterruptLock lock; - this->last_state_ = pin->digital_read(); - this->state_ = this->last_state_; - } + + // Read initial state + this->last_state_ = pin->digital_read(); + this->state_ = this->last_state_; + + // Attach interrupt - from this point on, any changes will be caught by the interrupt pin->attach_interrupt(&GPIOBinarySensorStore::gpio_intr, this, type); }